Type object
File match pgxgen.yml pgxgen.yaml
Schema URL https://catalog.lintel.tools/schemas/schemastore/pgxgen/latest.json
Source https://raw.githubusercontent.com/tkcrm/pgxgen/refs/heads/master/schemas/pgxgen-schema.json

Validate with Lintel

npx @lintel/lintel check
Type: object

Configuration file for pgxgen — code generator for PostgreSQL, MySQL, and SQLite. Replaces both pgxgen.yaml and sqlc.yaml.

Properties

version string required

Config schema version. Must be "2". Use pgxgen migrate to upgrade legacy v1 configs.

Constant: "2"
schemas schema[] required

List of schema sources. Each schema is an independent generation unit with its own engine, migrations, models, and tables. Multiple schemas allow mixing engines (e.g. PostgreSQL + SQLite) in one project.

minItems=1
templates object

Optional user-provided template directories that override the built-in templates for CRUD SQL and Go models.

2 nested properties
crud_dir string

Directory containing custom CRUD SQL templates. Files in this directory replace the built-in templates of the same name.

models_dir string

Directory containing custom Go model templates. Files in this directory replace the built-in templates of the same name.

Definitions

schema object
name string required

Human-readable schema name. Used in logs and to disambiguate output when multiple schemas are configured.

engine string required

Database engine. Controls SQL dialect, type mapping, and the sqlc engine selected when generating sqlc.yaml.

Values: "postgresql" "mysql" "sqlite"
schema_dir string required

Path to the directory (or single file) with SQL migration / schema files. Files are parsed in lexicographic order to derive table and column metadata.

models object
14 nested properties
output_dir string required

Directory where the generated Go models file will be written.

package_name string required

Go package name declared at the top of the generated models file.

output_file_name string

Name of the generated models file. Defaults to models.go.

Default: "models.go"
package_path string

Full Go import path of the models package (e.g. github.com/your-org/project/internal/models). Used by sqlc overrides and by other generated code that needs to import these models.

custom_types string[]

Names of types defined manually in the models package. The generator skips emitting these names so your hand-written definitions are preserved.

skip_tables string[]

Table or view names to exclude from model generation (e.g. internal migration tables).

skip_enums string[]

Enum type names to exclude from model generation.

emit_json_tags boolean

Add json:"…" struct tags to generated models.

Default: false
emit_db_tags boolean

Add db:"…" struct tags to generated models (useful for sqlx, scany, etc).

Default: false
emit_pointers_for_null boolean

Use Go pointer types (*T) for nullable columns instead of nullable wrappers like pgtype.Text or sql.NullString.

Default: false
include_struct_comments boolean

Add // @name StructName comments above generated structs (useful for swaggo / Swagger generators).

Default: false
sql_package string

SQL package used to choose the nullable / array type families in generated models (e.g. pgtype.Text vs sql.NullString).

Values: "pgx/v5" "pgx/v4" "database/sql"
type_overrides object[]

Override the SQL → Go type mapping for the models generator. Affects only model structs (sqlc has its own sqlc.overrides.types).

custom_tags object[]

Additional struct tags emitted on every generated model field. Combined with emit_json_tags / emit_db_tags.

sqlc object

Settings consumed when pgxgen generates .pgxgen/sqlc.yaml and runs sqlc.

3 nested properties
keep_generated_config boolean

Keep .pgxgen/sqlc.yaml after the run. When false (default), the generated config and its containing directory are removed on both success and failure.

Default: false
defaults object

Default sqlc gen.go options applied to every generated repo. Maps 1:1 to sqlc's options of the same name.

14 nested properties
sql_package string

sqlc sql_package option — selects the driver-specific nullable / array types in generated sqlc code.

Values: "pgx/v5" "pgx/v4" "database/sql"
emit_prepared_queries boolean

sqlc: emit prepared queries for performance.

emit_interface boolean

sqlc: emit a Querier interface alongside the concrete Queries struct.

emit_json_tags boolean

sqlc: add json:"…" struct tags to generated rows / params.

emit_db_tags boolean

sqlc: add db:"…" struct tags to generated rows / params.

emit_exported_queries boolean

sqlc: export the constants holding the SQL text of each query.

emit_exact_table_names boolean

sqlc: keep table names exact (no singularization). Off by default.

emit_empty_slices boolean

sqlc: emit empty slices instead of nil for :many queries that match no rows.

emit_result_struct_pointers boolean

sqlc: return *Row instead of Row from generated queries.

emit_params_struct_pointers boolean

sqlc: accept *Params instead of Params for generated queries with multi-field params.

emit_enum_valid_method boolean

sqlc: add a Valid() method on generated enum types.

emit_all_enum_values boolean

sqlc: emit a slice with all values for each generated enum.

query_parameter_limit integer

sqlc: maximum number of positional query parameters before sqlc switches the function signature to a single struct param.

json_tags_case_style string

sqlc: case style for json: tag values (camel, pascal, snake, or none).

Values: "camel" "pascal" "snake" "none"
overrides object

Maps 1:1 to the sqlc overrides section. Lets you rename generated types and remap SQL types or specific columns.

3 nested properties
rename Record<string, string>

Rename generated identifiers (e.g. { d: Params } renames a struct named D to Params).

types object[]

Override the Go type generated for a SQL type, optionally constrained to nullable columns.

columns object[]

Per-column overrides (e.g. add struct tags or change Go type for users.email).

defaults object

Defaults inherited by every table in the schema. Choose one of two layouts: per-table repos (use *_prefix) OR a single shared repo (use queries_dir / output_dir).

8 nested properties
queries_dir_prefix string

Per-table layout: queries directory is computed as {prefix}/{table_name}. Mutually exclusive with queries_dir. Not affected by package_prefix / package_suffix.

output_dir_prefix string

Per-table layout: sqlc output directory is computed as {prefix}/{package_prefix}{table_name}{package_suffix}. Mutually exclusive with output_dir.

package_prefix string

Per-table layout: prefix prepended to the table name when forming the output directory and Go package name (e.g. repo_). Does not affect queries_dir_prefix.

package_suffix string

Per-table layout: suffix appended to the table name when forming the output directory and Go package name (e.g. _repo). Does not affect queries_dir_prefix.

queries_dir string

Single-repo layout: directory where every table's queries are placed. Mutually exclusive with queries_dir_prefix.

output_dir string

Single-repo layout: directory where every table's sqlc output is written. Mutually exclusive with output_dir_prefix.

crud object

Default CRUD generation settings inherited by every table.

3 nested properties
auto_clean boolean

Remove stale generated CRUD files that no longer correspond to a configured method.

exclude_table_name boolean

Drop the table name from generated method names (e.g. GetByID instead of GetUserByID).

methods Record<string, object | null>

Default method definitions applied to every table. Per-table tables.{name}.crud.methods overrides these key-by-key.

constants object

Default constants generation settings inherited by every table.

1 nested properties
include_column_names boolean

Emit per-table column-name constants (e.g. UsersColumnEmail = "email").

tables Record<string, object>

Per-table configuration keyed by table name. Each entry merges with defaults and may override CRUD methods, constants, sqlc, and soft-delete settings.

custom_queries custom_query[]

Free-form SQL queries that are emitted alongside generated CRUD. Useful for joins, reports, or any query that does not fit the CRUD model.

models object
output_dir string required

Directory where the generated Go models file will be written.

package_name string required

Go package name declared at the top of the generated models file.

output_file_name string

Name of the generated models file. Defaults to models.go.

Default: "models.go"
package_path string

Full Go import path of the models package (e.g. github.com/your-org/project/internal/models). Used by sqlc overrides and by other generated code that needs to import these models.

custom_types string[]

Names of types defined manually in the models package. The generator skips emitting these names so your hand-written definitions are preserved.

skip_tables string[]

Table or view names to exclude from model generation (e.g. internal migration tables).

skip_enums string[]

Enum type names to exclude from model generation.

emit_json_tags boolean

Add json:"…" struct tags to generated models.

Default: false
emit_db_tags boolean

Add db:"…" struct tags to generated models (useful for sqlx, scany, etc).

Default: false
emit_pointers_for_null boolean

Use Go pointer types (*T) for nullable columns instead of nullable wrappers like pgtype.Text or sql.NullString.

Default: false
include_struct_comments boolean

Add // @name StructName comments above generated structs (useful for swaggo / Swagger generators).

Default: false
sql_package string

SQL package used to choose the nullable / array type families in generated models (e.g. pgtype.Text vs sql.NullString).

Values: "pgx/v5" "pgx/v4" "database/sql"
type_overrides object[]

Override the SQL → Go type mapping for the models generator. Affects only model structs (sqlc has its own sqlc.overrides.types).

custom_tags object[]

Additional struct tags emitted on every generated model field. Combined with emit_json_tags / emit_db_tags.

sqlc object

Settings consumed when pgxgen generates .pgxgen/sqlc.yaml and runs sqlc.

keep_generated_config boolean

Keep .pgxgen/sqlc.yaml after the run. When false (default), the generated config and its containing directory are removed on both success and failure.

Default: false
defaults object

Default sqlc gen.go options applied to every generated repo. Maps 1:1 to sqlc's options of the same name.

14 nested properties
sql_package string

sqlc sql_package option — selects the driver-specific nullable / array types in generated sqlc code.

Values: "pgx/v5" "pgx/v4" "database/sql"
emit_prepared_queries boolean

sqlc: emit prepared queries for performance.

emit_interface boolean

sqlc: emit a Querier interface alongside the concrete Queries struct.

emit_json_tags boolean

sqlc: add json:"…" struct tags to generated rows / params.

emit_db_tags boolean

sqlc: add db:"…" struct tags to generated rows / params.

emit_exported_queries boolean

sqlc: export the constants holding the SQL text of each query.

emit_exact_table_names boolean

sqlc: keep table names exact (no singularization). Off by default.

emit_empty_slices boolean

sqlc: emit empty slices instead of nil for :many queries that match no rows.

emit_result_struct_pointers boolean

sqlc: return *Row instead of Row from generated queries.

emit_params_struct_pointers boolean

sqlc: accept *Params instead of Params for generated queries with multi-field params.

emit_enum_valid_method boolean

sqlc: add a Valid() method on generated enum types.

emit_all_enum_values boolean

sqlc: emit a slice with all values for each generated enum.

query_parameter_limit integer

sqlc: maximum number of positional query parameters before sqlc switches the function signature to a single struct param.

json_tags_case_style string

sqlc: case style for json: tag values (camel, pascal, snake, or none).

Values: "camel" "pascal" "snake" "none"
overrides object

Maps 1:1 to the sqlc overrides section. Lets you rename generated types and remap SQL types or specific columns.

3 nested properties
rename Record<string, string>

Rename generated identifiers (e.g. { d: Params } renames a struct named D to Params).

types object[]

Override the Go type generated for a SQL type, optionally constrained to nullable columns.

columns object[]

Per-column overrides (e.g. add struct tags or change Go type for users.email).

defaults object

Defaults inherited by every table in the schema. Choose one of two layouts: per-table repos (use *_prefix) OR a single shared repo (use queries_dir / output_dir).

queries_dir_prefix string

Per-table layout: queries directory is computed as {prefix}/{table_name}. Mutually exclusive with queries_dir. Not affected by package_prefix / package_suffix.

output_dir_prefix string

Per-table layout: sqlc output directory is computed as {prefix}/{package_prefix}{table_name}{package_suffix}. Mutually exclusive with output_dir.

package_prefix string

Per-table layout: prefix prepended to the table name when forming the output directory and Go package name (e.g. repo_). Does not affect queries_dir_prefix.

package_suffix string

Per-table layout: suffix appended to the table name when forming the output directory and Go package name (e.g. _repo). Does not affect queries_dir_prefix.

queries_dir string

Single-repo layout: directory where every table's queries are placed. Mutually exclusive with queries_dir_prefix.

output_dir string

Single-repo layout: directory where every table's sqlc output is written. Mutually exclusive with output_dir_prefix.

crud object

Default CRUD generation settings inherited by every table.

3 nested properties
auto_clean boolean

Remove stale generated CRUD files that no longer correspond to a configured method.

exclude_table_name boolean

Drop the table name from generated method names (e.g. GetByID instead of GetUserByID).

methods Record<string, object | null>

Default method definitions applied to every table. Per-table tables.{name}.crud.methods overrides these key-by-key.

constants object

Default constants generation settings inherited by every table.

1 nested properties
include_column_names boolean

Emit per-table column-name constants (e.g. UsersColumnEmail = "email").

table object

Per-table overrides. Anything omitted here is inherited from the schema's defaults.

primary_column string

Name of the primary-key column. Used by CRUD methods like get, update, delete to build the WHERE clause when no explicit where is set.

queries_dir string

Override the queries directory for this table (otherwise resolved from defaults.queries_dir / defaults.queries_dir_prefix).

output_dir string

Override the sqlc output directory for this table (otherwise resolved from defaults.output_dir / defaults.output_dir_prefix).

sqlc object

Per-table sqlc options that override sqlc.defaults for this table only.

1 nested properties
query_parameter_limit integer

sqlc query_parameter_limit for this table only.

crud object
1 nested properties
methods Record<string, object | null>

CRUD methods to generate for this table. Method keys are well-known: create, update, delete, get, find, total, exists, batch_create. An empty object ({}) enables a method with default settings.

constants object
1 nested properties
include_column_names boolean

Override defaults.constants.include_column_names for this table.

soft_delete object

Enable soft-delete behavior. The delete method becomes an UPDATE that sets the column to now(); get and find automatically add WHERE {column} IS NULL.

1 nested properties
column string required

Name of the soft-delete timestamp column (commonly deleted_at).

method object | null

CRUD method definition. null or {} enables the method with default settings derived from the table.

name string

Override the generated Go method name (e.g. GetByID).

returning string

RETURNING clause for INSERT/UPDATE/DELETE (PostgreSQL only). Use * to return all columns.

where Record<string, object>

WHERE conditions keyed by column name. An empty object ({}) means column = $N. Use value/operator to customize.

where_additional string[]

Additional raw SQL conditions appended to the WHERE clause (e.g. "status = 'active'"). Combined with AND.

skip_columns string[]

Columns to omit from this method's INSERT/UPDATE column list (e.g. [id, created_at]).

column_values Record<string, string>

Override the generated value for specific columns with a literal SQL expression (e.g. { created_at: "now()" }). Such columns are filled by SQL instead of Go.

limit boolean

For find: emit LIMIT $N OFFSET $N and accept the corresponding parameters.

order object

ORDER BY clause for find.

2 nested properties
by string required

Column name to order by.

direction string

Sort direction. Defaults to DESC.

Default: "DESC"
Values: "ASC" "DESC"
custom_query object

Free-form SQL query emitted alongside generated CRUD.

name string required

Generated Go function name (e.g. GetActiveUsers).

type string required

sqlc query annotation: one (single row), many (slice of rows), exec (no result), copyfrom (PostgreSQL COPY FROM).

Values: "one" "many" "exec" "copyfrom"
sql string required

The SQL body. Use $1, $2, … for PostgreSQL parameters or ? for MySQL/SQLite.

table string

Optional table name. When set, the query is emitted into that table's resolved queries_dir and uses its row type.

output_dir string

Explicit output directory for the query. Takes precedence over table.