#[derive(Factory)]Available on crate feature
macros and (crate features model-mysql or model-postgres or model-sqlite) only.Expand description
Derive rust_web_server::test_client::factory::Factory for a
#[derive(Model)] struct, and an inherent T::factory() returning a
ModelFactory<T> for tests (17.30.0).
Each field gets its type’s FactoryValue default (numbers 0, bool
false, Option None, a String the field’s name plus a sequence
number), or Default::default() for a type without one and for
#[ignore] fields. The #[primary_key] is 0 when it’s
auto_increment, else the sequence number. It reads the same attributes
as #[derive(Model)] and declares none of its own.
ⓘ
#[derive(rust_web_server::Model, rust_web_server::Factory, Debug, Clone)]
#[table(name = "users")]
pub struct User {
#[primary_key(auto_increment)]
pub id: i64,
pub name: String,
}
let user = User::factory().with(|u| u.name = "Ann".into()).create(&pool).await?;