# rok-orm-factory
Model factories for generating test data. Define factories for your rok models
and use them in tests or seeders with realistic fake data.
## Installation
```toml
[dev-dependencies]
rok-orm-factory = { version = "0.1" }
```
## Quick Start
```rust
use rok_orm_factory::{Factory, Faker};
pub struct UserFactory;
impl Factory for UserFactory {
type Model = User;
fn build(&self) -> User {
User {
id: 0, // auto-assigned by DB
email: Faker::email(),
name: Faker::name(),
password: "$argon2...".into(), // pre-hashed test password
created_at: chrono::Utc::now(),
}
}
}
// In tests
#[tokio::test]
async fn test_something() {
let user = UserFactory.create(&pool).await?;
let users = UserFactory.count(10).create_many(&pool).await?;
}
```
## Faker Helpers
```rust
Faker::email() // "user_142@example.com"
Faker::name() // "Alice Johnson"
Faker::uuid() // UUID v4 string
Faker::word() // random word
Faker::sentence() // random sentence
Faker::paragraph() // random paragraph
Faker::number(1..=100) // random number in range
Faker::bool() // true or false
Faker::url() // "https://example.com/path"
Faker::phone() // "+1-555-0142"
```
## With Overrides
```rust
u.email = "admin@example.com".into();
}).create(&pool).await?;
```
## Relationships
```rust
let post = PostFactory.for_user(&user).create(&pool).await?;
// sets post.user_id = user.id
```