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>
impl<'a, D, S> SeedConfig<'a, D, S>
Sourcepub const fn seed(self, seed: u64) -> Self
pub const fn seed(self, seed: u64) -> Self
Sets the RNG seed (default 0). The same seed gives the same rows.
Sourcepub const fn default_count(self, count: usize) -> Self
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).
Sourcepub fn max_params(self, limit: usize) -> Self
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,
impl<D, S> SeedConfig<'_, D, S>where
S: SQLSchemaImpl,
Sourcepub fn count<T>(self, table: &T, count: usize) -> Selfwhere
T: SQLTableInfo,
S: SchemaHasTable<T>,
pub fn count<T>(self, table: &T, count: usize) -> Selfwhere
T: SQLTableInfo,
S: SchemaHasTable<T>,
Sets the row count for table.
This wins over relation and
default_count.
Sourcepub fn relation<P, C>(self, parent: &P, child: &C, count: usize) -> Self
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>
impl<D, S> SeedConfig<'_, D, S>
Sourcepub fn skip<T>(self, table: &T) -> Selfwhere
T: SQLTableInfo,
S: SchemaHasTable<T>,
pub fn skip<T>(self, table: &T) -> Selfwhere
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.
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).
Sourcepub fn count_by_name(self, table: &str, count: usize) -> Self
pub fn count_by_name(self, table: &str, count: usize) -> Self
Sets the row count for the table named table, like
count.
Sourcepub fn relation_by_name(self, parent: &str, child: &str, count: usize) -> Self
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.
Sourcepub fn skip_by_name(self, table: &str) -> Self
pub fn skip_by_name(self, table: &str) -> Self
Leaves the table named table out, like skip.
Sourcepub fn kind_by_name(
self,
table: &str,
column: &str,
kind: GeneratorKind,
) -> Self
pub fn kind_by_name( self, table: &str, column: &str, kind: GeneratorKind, ) -> Self
Uses a built-in GeneratorKind for column of table, like
kind.
Sourcepub fn generator_by_name(
self,
table: &str,
column: &str,
generator: impl Generator + 'static,
) -> Self
pub fn generator_by_name( self, table: &str, column: &str, generator: impl Generator + 'static, ) -> Self
Uses generator for column of table, like generator.