Skip to main content

Config

Struct Config 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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: PathBuf

The 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: bool

Plan the run and report it without touching the filesystem.

§check: bool

Write and remove nothing; report missing, changed, and stale files. Any such drift fails the run. Takes precedence over dry_run.

§force: bool

Overwrite existing files that were not generated by rok-sqlc.

§lenient: bool

Skip unsupported tables and queries (listed in the report) instead of failing.

§conventions: Conventions

Opt-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);

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Config

Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.