Skip to content

robinstraub/fabrique

Repository files navigation

Fabrique

CI codecov Crates.io Downloads docs.rs

SQL-first, type-safe, ergonomic database toolkit for Rust.

Features

  • 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

Quick Example

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.

Documentation

Running Tests

SQLite (no external dependency):

cargo test --features sqlite,testing

PostgreSQL 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

Contributors

Contributors

License

MIT License

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors