Skip to content

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:

db-gen generate --config path/to/db-gen.json

If you omit --config, db-gen tries these locations in order and uses the first that exists:

  1. ./db-gen.json
  2. ./db-gen/db-gen.json
  3. ./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:

db-gen generate --connectionString "postgresql://user:pass@host:5432/db"

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.json
  • testing/.local.db-gen.json
  • testing/db-gen.local
  • testing/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: true generates everything in the schema except entries explicitly set to false.
  • A Functions key 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:

db-gen generate --config db-gen.json --debug