CLI Commands¶
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. |
completion [bash\|zsh\|fish\|powershell] |
Print a shell-completion script. |
version |
Print version and build information. |
help [command] |
Print help for a command. |
Flags¶
Available on the data commands (generate, routines, database-changes):
| 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. |
Examples¶
Config file resolution¶
If --config is not given, db-gen tries, in order:
./db-gen.json./db-gen/db-gen.json./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]