Skip to main content

rok_db_codegen/
lib.rs

1//! Generate a rok-db crate from `.sql` files: models and enums from
2//! `CREATE TABLE` / `CREATE TYPE`, typed functions from sqlc-style annotated
3//! queries, and migrations computed from schema changes.
4//!
5//! Most people use the `rok-db-gen` binary; see the crate README.
6
7mod ddl;
8mod describe;
9mod emit;
10mod generate;
11mod ir;
12mod naming;
13mod parse;
14mod queries;
15mod split;
16mod types;
17
18pub use ddl::Rename;
19pub use generate::{Dependency, Generated, Options, differences, generate, write};
20pub use ir::{Column, EnumType, Extra, ForeignKey, Index, Query, QueryKind, Schema, Table};
21pub use parse::{Parsed, SourceFile, parse};
22
23use std::fmt;
24
25/// A generation error, with the file and line when known.
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct Error {
28    message: String,
29}
30
31impl Error {
32    pub(crate) fn new(message: impl Into<String>) -> Self {
33        Self {
34            message: message.into(),
35        }
36    }
37
38    pub(crate) fn at(location: &str, message: impl fmt::Display) -> Self {
39        Self::new(format!("{location}: {message}"))
40    }
41}
42
43impl fmt::Display for Error {
44    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45        f.write_str(&self.message)
46    }
47}
48
49impl std::error::Error for Error {}