1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::path::PathBuf;
use clap::{Args, Subcommand};
#[derive(Debug, Args)]
pub(crate) struct PgArgs {
#[command(subcommand)]
pub command: PgCommand,
}
#[derive(Debug, Subcommand)]
pub(crate) enum PgCommand {
/// Generate Harn record types from a directory of `.sql` migrations.
///
/// Replays every forward migration (`.sql`, excluding `*.down.sql`) in
/// lexicographic order and emits one `type <Table>Row = {…}` per table,
/// mirroring the live column set. Annotate a query result with the
/// generated type to type-check field access without a live database:
///
/// let receipt: ReceiptRow = pg_query_one(pool, sql, params)
///
/// Pass `--check` to verify the `--out` file is current (for CI).
Codegen(PgCodegenArgs),
}
#[derive(Debug, Args)]
pub(crate) struct PgCodegenArgs {
/// Directory holding `.sql` migration files.
#[arg(long, default_value = "migrations", value_name = "DIR")]
pub dir: PathBuf,
/// Write the generated types to this file. Prints to stdout when omitted.
#[arg(long, value_name = "FILE")]
pub out: Option<PathBuf>,
/// Verify `--out` is up to date without writing; exit non-zero on drift.
#[arg(long, requires = "out")]
pub check: bool,
/// Suffix appended to each PascalCase table name (default `Row`).
#[arg(long, value_name = "SUFFIX")]
pub suffix: Option<String>,
}