- Notifications
You must be signed in to change notification settings - Fork33
bringing orm-like features to sqlx
License
NyxCode/ormx
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Add ormx and sqlx to yourCargo.toml
[dependencies.ormx]version ="0.11"features = ["postgres"][dependencies.sqlx]version ="0.8"features = ["postgres","runtime-tokio-rustls"]
ormx provides macros for generating commonly used sql queries at compile time.
ormx is meant to be used together with sqlx. Everything it generates usessqlx::query!
under the hood, so every generated query will be checked against your database at compile time.
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 uniquelyidentifies 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, ormxis not what you are looking for.
database | cargo feature |
---|---|
PostgreSQL | postgres1 |
MariaDB | mariadb |
MySQL | mysql2 |
SQLite | currently not supported |
first, start a postgres database.
if you have docker installed, you can do so using./scripts/postgres.sh
.
next, set theDATABASE_URL
environment variable:export DATABASE_URL=postgres://postgres:admin@localhost/ormx
.
now, insideexample-postgres
, use the sqlx cli to setup the database schema:cargo sqlx db setup
.
finally, runcargo run
.
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.
v0.11 updated the sqlx dependency to v0.8.
most notably, the semantics of thesqlx::Executor
trait have somewhat changed. in most cases, this is fixed by adding a*
here or there.
Since 0.7, id columns are not special anymore - if they are generated by the database, you must annotate them with#[ormx(default)]
.
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
andmove 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
About
bringing orm-like features to sqlx