Expand description
rok-orm-factory — model factories for tests and seeding.
§Quick start
Define a factory by implementing Factory on your model:
ⓘ
use rok_orm_factory::{Factory, Faker};
impl Factory for User {
fn definition() -> Self {
User {
id: 0,
name: Faker::name(),
email: Faker::email(),
active: true,
}
}
}
// Make models in-memory (no DB)
let user = User::factory().make();
let users = User::factory().count(5).make_many();
// Override specific fields
let admin = User::factory()
.with(|u| u.name = "Admin".to_string())
.make();
// Persist to DB (requires `features = ["postgres"]` and a pool in scope)
let user = User::factory().create().await?;
let users = User::factory().count(3).create_many().await?;Re-exports§
pub use faker::Faker;
Modules§
Structs§
- Factory
Builder - Fluent builder for creating model instances.
Traits§
- Factory
- Implement this on a model to enable the factory DSL.