Expand description
§Fabrique
Fluent ORM for Rust with type-safe queries and integrated testing tools.
Fabrique is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. It provides a fluent, type-safe API for defining models, querying data, and generating test fixtures.
§Core Features
§Models
Define database models using the #[derive(Model)] macro. Models
automatically map to database tables and provide methods for CRUD
operations, soft deletes, and more. See the model module for detailed
documentation.
§Query Builder
Build type-safe database queries with a fluent API. The query builder
provides methods for filtering, ordering, limiting results, and more. See
the [query_builder] module for details.
§Factories
Generate test data easily with the #[derive(Factory)] macro. Factories
help you create model instances for testing without manually specifying
every field. See the factory module for more information.
§Quick Example
use fabrique::prelude::*;
use sqlx::PgPool;
// Define a model
#[derive(Model, Factory)]
pub struct Product {
id: uuid::Uuid,
name: String,
price_cents: i32,
}
// Query the database
let expensive_products: Vec<Product> = Product::query()
.select()
.r#where(Product::PRICE_CENTS, ">=", 1000)
.get(db)
.await?;
// Create a new record
let product = Product {
id: uuid::Uuid::new_v4(),
name: "Anvil 3000".to_string(),
price_cents: 9999,
};
product.create(db).await?;
// Generate test data with factories
let test_product = Product::factory().create(db).await?;§Getting Started
To use Fabrique in your project, add it to your Cargo.toml:
[dependencies]
fabrique = "0.1"
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres"] }Then define your models and start querying. See the model module for a
comprehensive guide on model conventions and usage
Re-exports§
pub use fake;pub use database::*;pub use error::*;pub use factory::*;pub use model::*;pub use relation::*;
Modules§
- database
- Database configuration and types.
- error
- Error types for Fabrique database operations.
- factory
- Factories
- model
- Model traits for database operations.
- prelude
- relation
- Relationship types for model associations.
- sql
- Database: Query Builder
Functions§
- seeded_
value - Generates a seeded value for factory fields.