pub mod numeric;
pub mod special;
pub mod string;
pub mod temporal;
#[derive(Debug, Clone, PartialEq)]
pub enum SeedValue {
Default,
Null,
Integer(i64),
Float(f64),
Text(String),
Bool(bool),
Blob(Vec<u8>),
CurrentTime,
}
pub trait Generator: Send + Sync {
fn generate(&self, rng: &mut dyn RngCore, index: usize, sql_type: &str) -> SeedValue;
fn name(&self) -> &'static str;
}
pub use rand::RngCore;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GeneratorKind {
IntPrimaryKey,
Int,
Float,
Bool,
Text,
FirstName,
LastName,
FullName,
Email,
Phone,
City,
Country,
Address,
JobTitle,
Company,
LoremIpsum,
Uuid,
Json,
Date,
Timestamp,
Time,
TimeTz,
Interval,
Blob,
PgInet,
PgCidr,
PgMacAddr,
PgMacAddr8,
PgPoint,
PgLine,
PgLseg,
PgBox,
PgPath,
PgPolygon,
PgCircle,
PgBit,
PgVarBit,
PgArray,
}
impl GeneratorKind {
#[must_use]
pub fn into_generator(self) -> Box<dyn Generator> {
match self {
Self::IntPrimaryKey => Box::new(numeric::IntPrimaryKeyGen),
Self::Int => Box::new(numeric::IntGen {
min: 0,
max: 10_000,
}),
Self::Float => Box::new(numeric::FloatGen {
min: 0.0,
max: 10_000.0,
}),
Self::Bool => Box::new(numeric::BoolGen),
Self::Text => Box::new(string::TextGen {
min_len: 5,
max_len: 50,
}),
Self::FirstName => Box::new(string::FirstNameGen),
Self::LastName => Box::new(string::LastNameGen),
Self::FullName => Box::new(string::FullNameGen),
Self::Email => Box::new(string::EmailGen),
Self::Phone => Box::new(string::PhoneGen),
Self::City => Box::new(string::CityGen),
Self::Country => Box::new(string::CountryGen),
Self::Address => Box::new(string::AddressGen),
Self::JobTitle => Box::new(string::JobTitleGen),
Self::Company => Box::new(string::CompanyGen),
Self::LoremIpsum => Box::new(string::LoremGen { words: 10 }),
Self::Uuid => Box::new(special::UuidGen),
Self::Json => Box::new(special::JsonGen),
Self::Date => Box::new(temporal::DateGen),
Self::Timestamp => Box::new(temporal::TimestampGen),
Self::Time => Box::new(temporal::TimeGen),
Self::TimeTz => Box::new(temporal::TimeTzGen),
Self::Interval => Box::new(temporal::IntervalGen),
Self::Blob => Box::new(special::BlobGen { size: 32 }),
Self::PgInet => Box::new(special::InetGen),
Self::PgCidr => Box::new(special::CidrGen),
Self::PgMacAddr => Box::new(special::MacAddrGen),
Self::PgMacAddr8 => Box::new(special::MacAddr8Gen),
Self::PgPoint => Box::new(special::PointGen),
Self::PgLine => Box::new(special::LineGen),
Self::PgLseg => Box::new(special::LsegGen),
Self::PgBox => Box::new(special::BoxGen),
Self::PgPath => Box::new(special::PathGen),
Self::PgPolygon => Box::new(special::PolygonGen),
Self::PgCircle => Box::new(special::CircleGen),
Self::PgBit => Box::new(special::BitGen {
min_len: 8,
max_len: 8,
}),
Self::PgVarBit => Box::new(special::BitGen {
min_len: 1,
max_len: 32,
}),
Self::PgArray => Box::new(special::ArrayGen),
}
}
}