Skip to main content

Crate rok_sqlc

Crate rok_sqlc 

Source
Expand description

Generate SQLx Rust database modules from SQL schema and query files.

The stable library API is generate and the types it takes and returns (Config, Report, Error). It does exactly what the rok-sqlc generate command does, so a build.rs gets the same files and the same failures as the CLI:

// build.rs
fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("cargo::rerun-if-changed=migrations");
    let mut config = rok_sqlc::Config::default();
    config.schema = vec!["migrations/0001_init.sql".into()];
    config.output = "src/db".into();
    rok_sqlc::generate(&config)?;
    Ok(())
}

Anything else reachable from this crate is an implementation detail with no stability promise (see ADR 0012).

Structs§

Config
What to generate and how: the one configuration model behind the CLI and generate.
Conventions
Opt-in conventions: columns that mean the same thing in every table that has them (ADR 0010). Each convention applies only to the tables that have the named column, and all are off by default.
Error
A failed generate run. Nothing was written.
QueryFailure
A query that cannot be generated.
RefusedFile
An existing file that generation would not overwrite.
Report
What a generate run did, or would do in a dry run.
TableFailure
A table that cannot be generated.

Enums§

Derive
An opt-in derive for generated types.
RelationshipChange
What configuration does to one inferred relationship (the [relationships] section of the config file).

Functions§

generate
Generates database modules as described by config.

Type Aliases§

Result
The result of a generate run.