#[non_exhaustive]pub struct Config {Show 13 fields
pub schema: Vec<PathBuf>,
pub queries: Vec<PathBuf>,
pub output: PathBuf,
pub resource: Option<String>,
pub dry_run: bool,
pub check: bool,
pub force: bool,
pub lenient: bool,
pub conventions: Conventions,
pub derive: Vec<Derive>,
pub extractors: Vec<Extractor>,
pub relationships: BTreeMap<String, BTreeMap<String, RelationshipChange>>,
pub modules: BTreeMap<String, String>,
}Expand description
What to generate and how: the one configuration model behind the CLI and
generate.
New fields may be added in minor releases, so build a Config from
Config::default and assign the fields you need:
let mut config = rok_sqlc::Config::default();
config.schema = vec!["migrations/0001_init.sql".into()];
config.output = "src/db".into();
rok_sqlc::generate(&config)?;Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.schema: Vec<PathBuf>Schema inputs, combined in the order given: a file, or a directory
whose *.sql migrations are read in filename order, skipping
*.down.sql.
queries: Vec<PathBuf>Annotated query files or directories. A single file becomes the
generated queries.rs. A directory (its *.sql files) or several
inputs become one queries/<stem>.rs module per file, declared by a
generated queries/mod.rs; each stem must be a snake_case Rust
module name, and stems must be unique.
Switching between the two layouts removes the old layout’s generated
files as stale. Left empty, a previously generated queries.rs or
queries/ is kept and still declared.
output: PathBufThe directory generated modules are written to. Defaults to src/db.
resource: Option<String>Generate the table with this SQL or module name and regenerate the resources already generated in the output directory; tables not generated yet stay ungenerated.
dry_run: boolPlan the run and report it without touching the filesystem.
check: boolWrite and remove nothing; report missing, changed, and stale files.
Any such drift fails the run. Takes precedence over dry_run.
force: boolOverwrite existing files that were not generated by rok-sqlc.
lenient: boolSkip unsupported tables and queries (listed in the report) instead of failing.
conventions: ConventionsOpt-in conventions about what certain columns mean across tables.
All off by default; Conventions::rok gives the Rok preset.
derive: Vec<Derive>Extra derives for the generated rows, typed ids, key structs, enums, inputs, and patches (ADR 0013). Empty by default.
extractors: Vec<Extractor>HTTP frameworks to generate validated-body extractors for, into
http/ of the output: mod.rs and a module per framework (ADR 0015).
Needs Derive::Validate, and reserves the module name http. Empty
by default.
relationships: BTreeMap<String, BTreeMap<String, RelationshipChange>>Renames and opt-outs of inferred relationships (ADR 0014), by table (its SQL name, schema-qualified name, or module name) and then by the relationship’s inferred name. Empty by default.
use rok_sqlc::RelationshipChange;
let mut config = rok_sqlc::Config::default();
let invoices = config.relationships.entry("invoices".into()).or_default();
invoices.insert("created_by_user".into(), RelationshipChange::Rename("author".into()));
invoices.insert("approved_by_user".into(), RelationshipChange::OptOut);modules: BTreeMap<String, String>Module renames, by table (its schema-qualified name or its SQL name;
public. may be left out): the table generates as this module, and
its row struct, typed id, and key struct are named after it. This is
how same-named tables of two schemas both generate. Each new name must
be a snake_case Rust identifier, and every entry must name a table of
the schema. Empty by default.
let mut config = rok_sqlc::Config::default();
config.modules.insert("audit.users".into(), "audit_users".into());