Skip to main content

SeedConfig

Struct SeedConfig 

Source
pub struct SeedConfig<'a, D, S> { /* private fields */ }
Expand description

Builder that generates seed INSERT statements for a schema.

Create one with SeedConfig::sqlite, SeedConfig::postgres, or SeedConfig::mysql (each behind its feature), chain the settings, then call generate / try_generate. Tables and columns passed to the builder must belong to the schema; anything else is a compile error.

Defaults: seed 0, 10 rows per table, no skipped tables. See the crate docs for how values and row counts are chosen.

Implementations§

Source§

impl<'a, D, S> SeedConfig<'a, D, S>

Source

pub const fn seed(self, seed: u64) -> Self

Sets the RNG seed (default 0). The same seed gives the same rows.

Source

pub const fn default_count(self, count: usize) -> Self

Sets the row count for tables with no explicit count and no seeded parent (default 10).

Source

pub fn max_params(self, limit: usize) -> Self

Caps the bind parameters per INSERT; rows are split across more statements to stay under it.

Without this, a dialect-specific default is used.

§Panics

Panics if limit is zero.

Source§

impl<D, S> SeedConfig<'_, D, S>
where S: SQLSchemaImpl,

Source

pub fn count<T>(self, table: &T, count: usize) -> Self
where T: SQLTableInfo, S: SchemaHasTable<T>,

Sets the row count for table.

This wins over relation and default_count.

Source

pub fn relation<P, C>(self, parent: &P, child: &C, count: usize) -> Self

Generates count rows of child for each row of parent; each parent row gets count consecutive child rows.

Without this, a child table with no explicit count gets one row per parent row. child must have a foreign key to parent (checked at compile time).

Source§

impl<D, S> SeedConfig<'_, D, S>

Source

pub fn skip<T>(self, table: &T) -> Self
where T: SQLTableInfo, S: SchemaHasTable<T>,

Leaves table out: no INSERTs and no reset statements for it.

Foreign keys that point at a skipped table keep their generated (or custom) values, for example to reference rows already in the database.

Source§

impl<D, S> SeedConfig<'_, D, S>
where S: SQLSchemaImpl,

Name-based settings, for a Schema built at runtime or names that come from configuration.

They take the same effect as the typed methods. A table name may be qualified as schema.table, and must be when two namespaces have a table with that name. An unknown name is reported as a SeedError by try_generate, try_generate_rows and reset_plan (and makes generate panic).

Source

pub fn count_by_name(self, table: &str, count: usize) -> Self

Sets the row count for the table named table, like count.

Source

pub fn relation_by_name(self, parent: &str, child: &str, count: usize) -> Self

Generates count rows of child for each row of parent, like relation. child must have a foreign key to parent.

Source

pub fn skip_by_name(self, table: &str) -> Self

Leaves the table named table out, like skip.

Source

pub fn kind_by_name( self, table: &str, column: &str, kind: GeneratorKind, ) -> Self

Uses a built-in GeneratorKind for column of table, like kind.

Source

pub fn generator_by_name( self, table: &str, column: &str, generator: impl Generator + 'static, ) -> Self

Uses generator for column of table, like generator.

Auto Trait Implementations§

§

impl<'a, D, S> !RefUnwindSafe for SeedConfig<'a, D, S>

§

impl<'a, D, S> !UnwindSafe for SeedConfig<'a, D, S>

§

impl<'a, D, S> Freeze for SeedConfig<'a, D, S>

§

impl<'a, D, S> Send for SeedConfig<'a, D, S>

§

impl<'a, D, S> Sync for SeedConfig<'a, D, S>

§

impl<'a, D, S> Unpin for SeedConfig<'a, D, S>

§

impl<'a, D, S> UnsafeUnpin for SeedConfig<'a, D, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Joined, From> JoinKey<From, JoinReverse> for Joined
where From: Joinable<Joined> + ?Sized,

Source§

fn pairs() -> &'static [(&'static str, &'static str)]

(joined_column, from_column) pairs the ON condition matches, in key order, read through Self::pair.
Source§

fn pair(pair: &(&'static str, &'static str)) -> (&'static str, &'static str)

The (joined_column, from_column) names of pair.
Source§

impl<List> ListIncludes<Nil, ()> for List

Source§

impl<Mk> MarkerAggValidFor<()> for Mk

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeEq<T> for T

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V