Expand description
§Rusticx ORM
Blazingly fast, async-first, multi-database ORM for Rust.
§Quick start
[dependencies]
rusticx = { version = "0.1", features = ["postgres"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }ⓘ
use rusticx::prelude::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize, Deserialize, Model)]
#[rusticx(table = "users")]
pub struct User {
#[rusticx(primary_key)]
pub id: Uuid,
pub name: String,
pub email: String,
pub age: i32,
}
#[tokio::main]
async fn main() -> rusticx::Result<()> {
// Connect
let adapter = PostgresAdapter::connect_url("postgres://localhost/mydb").await?;
let repo: Repository<User, _> = Repository::new(Arc::new(adapter));
// Auto-create table
repo.migrate().await?;
// Insert
let user = User { id: Uuid::new_v4(), name: "Alice".into(), email: "alice@example.com".into(), age: 30 };
let inserted = repo.insert(&user).await?;
// Find by ID
let found = repo.find_by_id(inserted.id).await?;
// Query builder
let adults = repo.find(
repo.query().r#where("age", CondOp::Gte, 18).order_by("name", Direction::Asc)
).await?;
// Delete
repo.delete_by_id(inserted.id).await?;
Ok(())
}Modules§
Structs§
- Column
Def - Describes one column in a table schema.
- Query
Builder - Composable, database-agnostic query builder.
- Repository
- Typed, high-level repository for a single model type
M. - Sync
Adapter - Blocking wrapper around any
DatabaseAdapter. - Table
Schema - Schema descriptor built from
Model::columns().
Enums§
- Column
Type - Database-agnostic column type.
- CondOp
- Comparison operator for a WHERE condition.
- Direction
- Operation
- The DML operation this
QueryBuilderrepresents. - Rusticx
Error - All errors that Rusticx operations can produce.
- Value
- Universal value type that maps across SQL and NoSQL backends.
Traits§
- Database
Adapter - Async database adapter — the interface every backend must implement.
- Model
- Core trait that every ORM model must implement.
Type Aliases§
Derive Macros§
- Model
- Derive the [
rusticx_core::model::Model] trait for a named struct.