Skip to content

CLI Commands

db-gen <command> [flags]

Commands

Command Description
generate Connect to the database (or load a routines file), read routine metadata, apply filters/mappings, and generate code. Prints schema changes since the last generation.
routines [out] Read routines from the database and write their definitions to a JSON file (default ./db-gen-routines.json, or the out argument) for offline generation.
database-changes Compare the current database schema against the last generation and print what changed — without generating.
validate Check configuration and templates without generating files. Validates settings, parses templates, and (when a database or routines file is available) renders each template against real routines. Exits non-zero on any error — for CI.
llm Print a single self-contained plain-text reference (concepts, every command and flag, the full config-key reference, the template data model, and template functions) aimed at LLM/AI coding assistants. Also available as the global --llm flag.
completion [bash\|zsh\|fish\|powershell] Print a shell-completion script.
version Print version and build information.
help [command] Print help for a command.

Running db-gen with no arguments prints version/build information followed by the help output.

Flags

Available on the data commands (generate, routines, database-changes, validate):

Flag Short Description
--config -s Path to the configuration file. If omitted, default locations are tried.
--connectionString -c PostgreSQL connection string. Overrides the value in config.
--debug -d Print debug logs and write debug files.

Additional flags:

Flag Commands Description
--useRoutinesFile generate, database-changes, validate Read routines from RoutinesFile instead of connecting to the database.
--offline validate Restrict validation to settings + template parsing; skip the database connection and the render step.
--llm root Print the LLM/AI-assistant reference (same output as the llm command).

Examples

db-gen generate --config db-gen.json
db-gen generate -s db-gen.json -c "postgresql://user:pass@host:5432/db"
db-gen routines --config db-gen.json
# or to a specific path:
db-gen routines ./snapshot/routines.json --config db-gen.json
db-gen database-changes --config db-gen.json
db-gen validate --config db-gen.json
# settings + template parsing only, no database:
db-gen validate --config db-gen.json --offline
db-gen llm        # or: db-gen --llm

Config file resolution

If --config is not given, db-gen tries, in order:

  1. ./db-gen.json
  2. ./db-gen/db-gen.json
  3. ./db-gen/config.json

Relative paths inside the config resolve against the config file's directory. See Configuration for local overrides.

How generate works

flowchart LR
    A[Load config + local override] --> B{Data source}
    B -->|Database| C[Connect to PostgreSQL]
    B -->|Offline| D[Load routines JSON]
    C --> E[Query information_schema]
    D --> E
    E --> F[Filter + map types]
    F --> G[Render templates]
    G --> H[Write output files]
    C --> I[Diff vs last generation] --> J[Print changes]