GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - NyxCode/ormx: bringing orm-like features to sqlx

BranchesTags
Open more actions menu

Latest commit

 

History

68 Commits
68 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
example-mariadb
example-mariadb
 
 
example-mysql
example-mysql
 
 
example-postgres
example-postgres
 
 
ormx-macros
ormx-macros
 
 
ormx
ormx
 
 
scripts
scripts
 
 
.gitignore
.gitignore
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
rustfmt.toml
rustfmt.toml
 
 

Repository files navigation

ormx

lightweight macros for sqlx

Crates.io version chat docs.rs docs Download

getting started

Add ormx and sqlx to your Cargo.toml

[dependencies.ormx]
version = "0.11"
features = ["postgres"]

[dependencies.sqlx]
version = "0.8"
features = ["postgres", "runtime-tokio-rustls"]

what does it do?

ormx provides macros for generating commonly used sql queries at compile time.
ormx is meant to be used together with sqlx. Everything it generates uses sqlx::query! under the hood, so every generated query will be checked against your database at compile time.

what doesn't it do?

ormx is not a full-fledged ORM nor a query builder. For everything except simple CRUD, you can always just use sqlx.

it is required that every table contains an id column, which uniquely identifies a row. probably, you would want to use an auto-incrementing integer for this. this is a central requirement of ormx, and if your table does not fulfill this requirement, ormx is not what you are looking for.

databases

database cargo feature
PostgreSQL postgres1
MariaDB mariadb
MySQL mysql2
SQLite currently not supported

example

first, start a postgres database.
if you have docker installed, you can do so using ./scripts/postgres.sh.
next, set the DATABASE_URL environment variable: export DATABASE_URL=postgres://postgres:admin@localhost/ormx.
now, inside example-postgres, use the sqlx cli to setup the database schema: cargo sqlx db setup.
finally, run cargo run.

help

if you encounter an issue or have questions, feel free to ask in #ormx on the sqlx discord.
The documentation currently is not what it should be, so don't be afraid to ask for help.

migrate

to 0.11

v0.11 updated the sqlx dependency to v0.8.
most notably, the semantics of the sqlx::Executor trait have somewhat changed. in most cases, this is fixed by adding a * here or there.

to 0.7

Since 0.7, id columns are not special anymore - if they are generated by the database, you must annotate them with #[ormx(default)].

a note on reborrowing

if you run into the issue that the compiler tells you that you can't re-use a &mut Connection because

  • use of moved value and
  • move occurs because 'con' has type '&mut Connection', which does not implement the 'Copy' trait

you'll have to manually reborrow the connection with &mut *con.

Footnotes

  1. out of these three, the postgres backend is the most mature. ↩

  2. the mysql backend does work with both MariaDB and MySQL, though the mariadb backend emits cleaner and probably faster queries. ↩

About

bringing orm-like features to sqlx

Topics

macrosmariadbmysqlormpostgresrustsqlx

Resources

Readme
MIT license
Activity

Stars

297 stars

Watchers

5 watching

Forks

31 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.