8000 GitHub - NyxCode/ormx: bringing orm-like features to sqlx
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

NyxCode/ormx

Repository files navigation

ormx

lightweight macros for sqlx

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

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