Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/NyxCode/ormx
bringing orm-like features to sqlx
https://github.com/NyxCode/ormx
macros mariadb mysql orm postgres rust sqlx
Last synced: 3 months ago
JSON representation
bringing orm-like features to sqlx
- Host: GitHub
- URL: https://github.com/NyxCode/ormx
- Owner: NyxCode
- License: mit
- Created: 2020-07-13T02:39:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-04T10:32:28.000Z (over 1 year ago)
- Last Synced: 2024-08-05T17:58:50.185Z (3 months ago)
- Topics: macros, mariadb, mysql, orm, postgres, rust, sqlx
- Language: Rust
- Homepage:
- Size: 72.3 KB
- Stars: 283
- Watchers: 7
- Forks: 35
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ormx
## getting started
Add ormx and sqlx to your `Cargo.toml`
```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.
## 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.## help
if you encounter an issue or have questions, feel free to ask in [`#ormx` on the sqlx discord](https://discord.gg/mrZz4Wv8r2).
The documentation currently is not what it should be, so don't be afraid to ask for help.## [mysql example](https://github.com/NyxCode/ormx/tree/master/example-mysql/src/main.rs)
## [postgres example](https://github.com/NyxCode/ormx/tree/master/example-postgres/src/main.rs)
## features
- `mysql` - enable support for mysql/mariadb
- `postgres` - enable support for postgres
## migration guide for 0.7
Since 0.7, id columns are not special anymore - if they are generated by the database, you must annotete 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`.