Skip to main content

Factory

Trait Factory 

Source
pub trait Factory<M>:
    Sized
    + Send
    + Sync
where M: Model + Send + Sync + 'static,
{ // Required method fn definition(&self) -> M; // Provided methods fn make_one(&self) -> M { ... } fn count(self, count: usize) -> FactoryBuilder<M, Self> { ... } fn state<F>(self, modifier: F) -> FactoryBuilder<M, Self> where F: Fn(&mut M) + Send + Sync + 'static { ... } fn create_one<'life0, 'life1, 'async_trait>( &'life0 self, db: &'life1 DatabasePool, ) -> Pin<Box<dyn Future<Output = Result<M, AppError>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait { ... } fn create_many<'life0, 'life1, 'async_trait>( &'life0 self, db: &'life1 DatabasePool, count: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<M>, AppError>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait { ... } }
Expand description

Trait Factory — Pondasi pembuatan data mock/dummy untuk pengujian dan seeding ala Laravel.

Required Methods§

Source

fn definition(&self) -> M

Definisikan nilai atribut default untuk sebuah instance model

Provided Methods§

Source

fn make_one(&self) -> M

Buat 1 instance model in-memory tanpa menyimpannya ke database

Source

fn count(self, count: usize) -> FactoryBuilder<M, Self>

Menentukan jumlah record yang akan dibuat (fluent method chaining)

Source

fn state<F>(self, modifier: F) -> FactoryBuilder<M, Self>
where F: Fn(&mut M) + Send + Sync + 'static,

Menambahkan state modifier untuk mengubah nilai field tertentu

Source

fn create_one<'life0, 'life1, 'async_trait>( &'life0 self, db: &'life1 DatabasePool, ) -> Pin<Box<dyn Future<Output = Result<M, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Menyimpan 1 instance model langsung ke database dan memuat ulang record dari DB

Source

fn create_many<'life0, 'life1, 'async_trait>( &'life0 self, db: &'life1 DatabasePool, count: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<M>, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Menyimpan sejumlah record langsung ke database

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§