#[non_exhaustive]pub struct Config {
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 relationships: BTreeMap<String, BTreeMap<String, RelationshipChange>>,
}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 only the table with this SQL or module name.
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.
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);