SQL-first, type-safe, ergonomic database toolkit for Rust.
- SQL-first — Builds on SQL semantics rather than hiding them; the query builder maps directly to the SQL you'd write
- Type-safe — Column constants, typed where clauses, and compile-time join validation catch errors before they run
- Ergonomic — Convention-driven models, fluent query builder, and factories for test data generation
Add fabrique to your Cargo.toml with the feature matching your database backend:
[dependencies]
fabrique = { version = "0.2", features = ["postgres"] }use fabrique::prelude::*;
#[derive(Model, Factory)]
pub struct Product {
#[fabrique(primary_key)]
pub id: Uuid,
pub name: String,
pub price_cents: i32,
}
// Query
let products = Product::query()
.r#where(Product::PRICE_CENTS, ">=", 1000)
.get(&pool)
.await?;
// Create test data
let product = Product::factory()
.name("Anvil 3000")
.create(&pool)
.await?;For tutorials and detailed documentation, see the User Guide.
- User Guide — Tutorials, concepts, and how-to guides
- API Reference — Technical documentation on docs.rs
SQLite (no external dependency):
cargo test --features sqlite,testingPostgreSQL and MySQL require a running database. Start them with Docker, then run the tests:
docker compose up -d
DATABASE_URL="postgres://postgres:postgres@localhost:5432/postgres" \
cargo test --features postgres,testing
DATABASE_URL="mysql://root:mysql@localhost:3306/fabrique" \
cargo test --features mysql,testing