rok-orm-factory
Model factories for generating realistic test data in rok-orm applications.
Part of the Rok Framework — a full-stack Rust web framework built on Axum 0.8 and SQLx 0.8.
Features
Factorytrait withbuild()for in-memory construction andcreate()for DB insertion#[derive(Factory)]proc-macro for zero-boilerplate factory generationFakerhelpers for realistic data: names, emails, UUIDs, URLs, sentences, numbers- Sequences for auto-incrementing unique values across test cases
- Named states via
.state("admin")for variant factory configurations - Relationship factories:
.for_user(&user)sets foreign keys automatically count(n).create_many()for bulk data seeding- Works alongside
sqlx::testandtokio::testfor isolated test databases
Installation
[]
= "0.2"
Quick Start
use ;
;
async
Core API
Overrides and states
// Override specific fields at call site
let admin = UserFactory
.with
.create
.await?;
// Named states defined on the factory
;
let inactive = UserFactory.as_state.create.await?;
Sequences
use Sequence;
static EMAIL_SEQ: Sequence = new;
Relationship factories
;
let user = UserFactory.create.await?;
let posts = PostFactory.for_user.count.create_many.await?;
Faker helpers
name // "Eleanor Vance"
first_name // "Eleanor"
email // "eleanor42@example.com"
unique_email // guaranteed unique within test run
uuid // "550e8400-e29b-41d4-a716-446655440000"
word // "luminous"
sentence // "The quick brown fox jumps."
paragraph // multi-sentence paragraph
number // 347
bool // true
url // "https://example.com/path/to/page"
phone // "+1-555-0247"
ip // "192.168.1.42"
Integration
rok-orm-factory works with any rok-orm model by requiring Model + sqlx::FromRow + Default. It pairs with rok-orm-migrate to set up a clean test schema via MigrationRunner before seeding, and with Axum's TestClient for full integration tests.
async
License
MIT