Oxidizer
A Rust ORM based on tokio-postgres and refinery
Dead simple, but powerful
Oxidizer is a Rust ORM based on tokio-postgres and refinery. Two powerful libraries that give performance and reliability to perform database interactions.
Asynchronous from the ground up
By using tokio and tokio-postgres, all the database operations are efficiently handled by tokio at runtime.
Relations
Oxidizer macros generate code to access forward and reverse relations between entities with ease.
Productive and Extensible
Write reusable code and think in terms of your problem domain, not SQL.
Comparison
How does Oxidizer compare to other popular options?
Diesel and RustORM are other great ORM options for Rust. Here are the three crates compared.
Oxidizer | Diesel | RustORM | |
---|---|---|---|
Asynchronous | |||
Raw SQL | |||
PostgreSQL | |||
MySQL | |||
SQLite |
Examples
Quick snippets to get started with Oxidizer
- Entity
- Insert/Update
- Select
- Delete
#[derive(Entity, Default)]#[entity(table_name = "my_table_name")] // optional#[index(name = "myindex", columns = "name, datetime", unique)] // optionalpub struct MyEntity {#[primary_key]id: i32,name: String,#[indexed] // optionalinteger: i32,integer64: i64,float: f32,double: f64,boolean: bool,datetime: Option<DateTime<Utc>>}
#[derive(Entity, Default)]pub struct MyEntity {#[primary_key]id: i32,name: String,}#[tokio::main]async fn main() {let mut entity = MyEntity::default();entity.name = "Hello world"let uri = "postgres://postgres:postgres@localhost/postgres";let db = Db::connect(&uri, 50, None).await.unwrap();let creating = entity.save(&db).await.unwrap();}
#[derive(Entity, Default)]pub struct MyEntity {#[primary_key]id: i32,name: String,}#[tokio::main]async fn main() {let uri = "postgres://postgres:postgres@localhost/postgres";let db = Db::connect(&uri, 50, None).await.unwrap();let id = 1;let results = MyEntity::find(&db, "id = $1", &[&id]).await.unwrap();}
#[derive(Entity, Default)]pub struct MyEntity {#[primary_key]id: i32,name: String,}#[tokio::main]async fn main() {let uri = "postgres://postgres:postgres@localhost/postgres";let db = Db::connect(&uri, 50, None).await.unwrap();let id = 1;let mut result = MyEntity::first(&db, "id = $1", &[&id]).await.unwrap();let deleted: bool = result.delete(&db).await.unwrap();}