Sqlx Models ORM
ActiveRecord pattern for Rust based on SQLx. Write idiomatic DB code (Postgres only).
[]
= "0.1"
Installation
Read the in-depth tutorial that doubles as a "kitchen sink" test in the examples
These are just some of the time-saving, boilerplate-killing features:
Model
model!
Create
let alice = app.human
.insert
.save.await?;
assert_eq!;
Query
let some_humans = app.human
.select
.limit
.offset
.likes_dogs_too_eq
.order_by
.desc
.all.await?;
assert_eq!;
Update
let updated_alice = alice.update.use_struct.save.await?;
assert_eq!;
Delete
alice.delete.await?;
Design principles:
- Stateful: You're not supposed to be passing a connection pool around explicitly.
- Your structs, your abstractions: This crate has a proc macro that creates a number of structs for different operations on a single database table. You can add any methods you want to any of these structs. Structs for the same operation in different tables implement a common trait to allow some degree of generalization across operations in these tables.
- Idiomatic rather than performant: This should be easy to learn and use, even if there were performance tradeoffs.
- Fallaback to SQLx: Always make it possible to fall back for custom queries and performance enhancements.
- One table per query. Reinventing SQL for joining tables in the ORM is hard to debug and understand. Favour multiple single-table queries over a single multi-table one. (see previous item).
- Only compile time checked queries. No chance of sql injection, no need for silly tests, at the cost of longer queries.
- Only Postgres for now. Sorry about that :(