rquery-orm
Lightweight ORM for Rust providing a SQL style query builder over SQL Server and PostgreSQL. It exposes a small set of traits and a derive macro so your structs become database entities, while all SQL is generated through a typed DSL.
Connecting to the database
use connect_postgres;
async
For SQL Server use connect_mssql instead.
Declaring an entity
Annotate your struct with #[derive(Entity)] and mark each column:
use NaiveDateTime;
use Entity;
Building queries
All queries start from a GenericRepository tied to an entity. Chaining methods configures the SQL without executing it until an async terminal call:
use ;
let repo = new;
let rows = repo
.Select
.Join
.Where
.OrderBy
.Top
.to_list_async
.await?;
Join
- Typed (recommended): uses compile-time entity and field names.
use ;
let rows = repo
.Select
.Join
.to_list_async
.await?;
- String-based (aliasing): handy for complex/manual joins or aliases.
use ;
let rows = repo
.Select
.Join
.to_list_async
.await?;
Where
- Column = value (typed):
use condition;
let rows = repo
.Select
.Where
.to_list_async
.await?;
- Column = column (typed):
use ;
let rows = repo
.Select
.Join
.Where
.to_list_async
.await?;
- With aliases or ad-hoc paths (string literal):
use condition;
let rows = repo
.Select
.Where
.to_list_async
.await?;
Insert
let employee = Employees ;
repo.insert_async.await?;
Update
let mut e = rows.clone;
e.last_name = "Updated".into;
repo.update_async.await?;
Delete
repo.delete_by_key_async.await?;
Validations
Columns can declare validation rules so validate() and CRUD operations fail fast before reaching the database:
use Entity;
let user = User ;
if let Err = user.validate
When using repository methods like insert_async or update_async, validation runs automatically; failed validation aborts the operation.
Dual repository + typed join
use ;
let pairs: = new
.Select
.Join
.Top
.to_list_async
.await?;
See examples/usage.rs and the tests folder for additional scenarios.