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
generaterun. Nothing was written. - Query
Failure - A query that cannot be generated.
- Refused
File - An existing file that generation would not overwrite.
- Report
- What a
generaterun did, or would do in a dry run. - Table
Failure - A table that cannot be generated.
Enums§
- Derive
- An opt-in derive for generated types.
- Relationship
Change - What configuration does to one inferred relationship (the
[relationships]section of the config file).
Functions§
- generate
- Generates database modules as described by
config.