mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-22 00:15:20 +01:00
create Generation Options structs
This commit is contained in:
@@ -25,9 +25,7 @@ impl GenerationContext for SimulatorEnv {
|
||||
&self.tables.tables
|
||||
}
|
||||
|
||||
fn opts(&self) -> sql_generation::generation::Opts {
|
||||
sql_generation::generation::Opts {
|
||||
indexes: self.opts.experimental_indexes,
|
||||
}
|
||||
fn opts(&self) -> &sql_generation::generation::Opts {
|
||||
&self.gen_opts
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use std::sync::Arc;
|
||||
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
use sql_generation::generation::Opts;
|
||||
use sql_generation::model::table::Table;
|
||||
use turso_core::Database;
|
||||
|
||||
@@ -59,6 +60,7 @@ impl Deref for SimulatorTables {
|
||||
|
||||
pub(crate) struct SimulatorEnv {
|
||||
pub(crate) opts: SimulatorOpts,
|
||||
pub gen_opts: Opts,
|
||||
pub(crate) connections: Vec<SimConnection>,
|
||||
pub(crate) io: Arc<SimulatorIO>,
|
||||
pub(crate) db: Option<Arc<Database>>,
|
||||
@@ -85,6 +87,7 @@ impl SimulatorEnv {
|
||||
paths: self.paths.clone(),
|
||||
type_: self.type_,
|
||||
phase: self.phase,
|
||||
gen_opts: self.gen_opts.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,6 +294,11 @@ impl SimulatorEnv {
|
||||
.map(|_| SimConnection::Disconnected)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let gen_opts = Opts {
|
||||
indexes: opts.experimental_indexes,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
SimulatorEnv {
|
||||
opts,
|
||||
tables: SimulatorTables::new(),
|
||||
@@ -301,6 +309,7 @@ impl SimulatorEnv {
|
||||
db: Some(db),
|
||||
type_: simulation_type,
|
||||
phase: SimulationPhase::Test,
|
||||
gen_opts,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,24 +3,13 @@ use std::{iter::Sum, ops::SubAssign};
|
||||
use anarchist_readable_name_generator_lib::readable_name_custom;
|
||||
use rand::{distr::uniform::SampleUniform, Rng};
|
||||
|
||||
use crate::model::table::Table;
|
||||
|
||||
pub mod opts;
|
||||
pub mod expr;
|
||||
pub mod predicate;
|
||||
pub mod query;
|
||||
pub mod table;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Opts {
|
||||
/// Indexes enabled
|
||||
pub indexes: bool,
|
||||
}
|
||||
|
||||
/// Trait used to provide context to generation functions
|
||||
pub trait GenerationContext {
|
||||
fn tables(&self) -> &Vec<Table>;
|
||||
fn opts(&self) -> Opts;
|
||||
}
|
||||
pub use opts::*;
|
||||
|
||||
type ArbitraryFromFunc<'a, R, T> = Box<dyn Fn(&mut R) -> T + 'a>;
|
||||
type Choice<'a, R, T> = (usize, Box<dyn Fn(&mut R) -> Option<T> + 'a>);
|
||||
|
||||
62
sql_generation/generation/opts.rs
Normal file
62
sql_generation/generation/opts.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use crate::model::table::Table;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Opts {
|
||||
/// Indexes enabled
|
||||
pub indexes: bool,
|
||||
pub table: TableOpts,
|
||||
}
|
||||
|
||||
impl Default for Opts {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
indexes: true,
|
||||
table: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait used to provide context to generation functions
|
||||
pub trait GenerationContext {
|
||||
fn tables(&self) -> &Vec<Table>;
|
||||
fn opts(&self) -> &Opts;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TableOpts {
|
||||
pub large_table: LargeTableOpts,
|
||||
/// Range of numbers of columns to generate
|
||||
pub column_range: Range<u32>,
|
||||
}
|
||||
|
||||
impl Default for TableOpts {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
large_table: Default::default(),
|
||||
// Up to 10 columns
|
||||
column_range: 1..11,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Options for generating large tables
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LargeTableOpts {
|
||||
pub enable: bool,
|
||||
pub large_table_prob: f32,
|
||||
/// Range of numbers of columns to generate
|
||||
pub column_range: Range<u32>,
|
||||
}
|
||||
|
||||
impl Default for LargeTableOpts {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enable: true,
|
||||
large_table_prob: 0.1,
|
||||
// todo: make this higher (128+)
|
||||
column_range: 64..125,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user