Configuration¶
db-gen is driven by a single JSON configuration file. This page explains how that file is located, how local overrides work, and how the configuration is organized. For an exhaustive list of every key, see the Configuration keys reference.
Specifying the config file¶
Pass it explicitly:
If you omit --config, db-gen tries these locations in order and uses the first that exists:
./db-gen.json./db-gen/db-gen.json./db-gen/config.json
Relative paths resolve against the config file
Template paths, the output folder, and the routines file are all resolved relative to the directory containing the config file, not your current working directory.
You can also override the connection string on the command line:
Local overrides¶
For secrets and per-developer settings, db-gen merges an optional local file on top of the main config. Given testing/db-gen.json, it looks for, in order:
testing/local.db-gen.jsontesting/.local.db-gen.jsontesting/db-gen.localtesting/db-gen.json.local
The first match is merged over the main config (overriding values). The local file is optional.
Recommended pattern
Keep your ConnectionString in local.db-gen.json and add that file to .gitignore. The committed db-gen.json stays secret-free.
How configuration is organized¶
| Area | Keys | Covered in |
|---|---|---|
| Connection & output | ConnectionString, OutputFolder, folder names, file extension/case, clear/remove options |
reference |
| What to generate | GenerateModels, GenerateProcessors, templates, Generate[] selection |
this guide + Templating |
| Type mapping | Mappings[] |
Type Mapping |
| Context parameters | UseUserContext, ContextParameterMappings[] |
Context Mapping |
| Additional generators | AdditionalGenerators[] |
Context Mapping |
| Copy targets | GenerateCopyTargets, CopyTargets[] |
Copy Targets |
| Validation | Validation |
Validation |
| Offline | RoutinesFile, UseRoutinesFile |
Offline & Change Detection |
Selecting what to generate¶
The Generate array selects schemas and functions:
{
"Generate": [
{
"Schema": "public",
"AllFunctions": true,
"Functions": {
"internal_helper": false,
"get_user_by_id": { "MappedName": "GetUser" }
}
}
]
}
AllFunctions: truegenerates everything in the schema except entries explicitly set tofalse.- A
Functionskey can be just a name (my_func) or a name with a signature (my_func(text,int)). - A value can be a boolean (generate or not) or an override object — see Templating → per-routine overrides.
Debugging¶
Add --debug (-d) to print debug logs and write debug files: