Add ormx and sqlx to your Cargo.toml
[dependencies.ormx]
version = "0.7"
features = ["mysql"]
[dependencies.sqlx]
version = "0.5"
default-features = false
features = ["macros", "mysql", "runtime-tokio-rustls"]
Right now, ormx supports mysql/mariadb and postgres.
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.
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.
if you encounter an issue or have questions, feel free to ask in #ormx
on the sqlx discord.
mysql
- enable support for mysql/mariadbpostgres
- enable support for postgres
Since 0.7, id columns are not special anymore - if they are generated by the database, you must annotete 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
.