{ "$schema": "https://json-schema.org/draft-07/schema#", "title": "pgxgen configuration", "description": "Configuration file for pgxgen code generator", "type": "object", "required": ["version", "schemas"], "properties": { "version": { "type": "string", "const": "2", "description": "Config version (must be '2')" }, "schemas": { "type": "array", "minItems": 1, "description": "Array of schema configurations, each with its own engine and tables", "items": { "$ref": "#/definitions/schema" } }, "templates": { "type": "object", "description": "User-provided template directories", "properties": { "crud_dir": { "type": "string", "description": "Directory with custom CRUD SQL templates" }, "models_dir": { "type": "string", "description": "Directory with custom Go model templates" } } } }, "definitions": { "schema": { "type": "object", "required": ["name", "engine", "schema_dir"], "properties": { "name": { "type": "string", "description": "Human-readable schema name" }, "engine": { "type": "string", "enum": ["postgresql", "mysql", "sqlite"], "description": "Database engine" }, "schema_dir": { "type": "string", "description": "Path to SQL migration/schema files" }, "models": { "$ref": "#/definitions/models" }, "sqlc": { "$ref": "#/definitions/sqlc" }, "defaults": { "$ref": "#/definitions/defaults" }, "tables": { "type": "object", "description": "Per-table configuration (crud + constants + sqlc)", "additionalProperties": { "$ref": "#/definitions/table" } }, "custom_queries": { "type": "array", "items": { "$ref": "#/definitions/custom_query" } } } }, "models": { "type": "object", "required": ["output_dir", "package_name"], "properties": { "output_dir": { "type": "string" }, "output_file_name": { "type": "string", "default": "models.go" }, "package_name": { "type": "string" }, "package_path": { "type": "string", "description": "Full Go import path for the models package" }, "custom_types": { "type": "array", "items": { "type": "string" }, "description": "Custom types defined in the models package" }, "skip_tables": { "type": "array", "items": { "type": "string" }, "description": "Table/view names to exclude from model generation" }, "skip_enums": { "type": "array", "items": { "type": "string" }, "description": "Enum names to exclude from model generation" }, "emit_json_tags": { "type": "boolean", "default": false }, "emit_db_tags": { "type": "boolean", "default": false }, "emit_pointers_for_null": { "type": "boolean", "default": false }, "include_struct_comments": { "type": "boolean", "default": false, "description": "Add // @name StructName comments to generated structs (useful for Swagger)" }, "sql_package": { "type": "string", "enum": ["pgx/v5", "pgx/v4", "database/sql"] } } }, "sqlc": { "type": "object", "properties": { "defaults": { "type": "object", "description": "Default sqlc gen.go options applied to all repos", "properties": { "sql_package": { "type": "string", "enum": ["pgx/v5", "pgx/v4", "database/sql"] }, "emit_prepared_queries": { "type": "boolean" }, "emit_interface": { "type": "boolean" }, "emit_json_tags": { "type": "boolean" }, "emit_db_tags": { "type": "boolean" }, "emit_exported_queries": { "type": "boolean" }, "emit_exact_table_names": { "type": "boolean" }, "emit_empty_slices": { "type": "boolean" }, "emit_result_struct_pointers": { "type": "boolean" }, "emit_params_struct_pointers": { "type": "boolean" }, "emit_enum_valid_method": { "type": "boolean" }, "emit_all_enum_values": { "type": "boolean" }, "query_parameter_limit": { "type": "integer" }, "json_tags_case_style": { "type": "string" } } }, "overrides": { "type": "object", "properties": { "rename": { "type": "object", "additionalProperties": { "type": "string" } }, "types": { "type": "array", "items": { "type": "object", "required": ["db_type", "go_type"], "properties": { "db_type": { "type": "string" }, "go_type": {}, "nullable": { "type": "boolean" } } } }, "columns": { "type": "array", "items": { "type": "object", "required": ["column"], "properties": { "column": { "type": "string" }, "go_type": {}, "go_struct_tag": { "type": "string" } } } } } } } }, "defaults": { "type": "object", "properties": { "queries_dir_prefix": { "type": "string", "description": "Per-table repos: queries_dir = {prefix}/{table_name} (not affected by package_prefix/package_suffix)" }, "output_dir_prefix": { "type": "string", "description": "Per-table repos: output_dir = {prefix}/{package_prefix}{table_name}{package_suffix}" }, "package_prefix": { "type": "string", "description": "Per-table repos: prefix for the output directory/package name (does not affect queries_dir_prefix), e.g. repo_" }, "package_suffix": { "type": "string", "description": "Per-table repos: suffix for the output directory/package name (does not affect queries_dir_prefix), e.g. _repo" }, "queries_dir": { "type": "string", "description": "Single repo: all queries in one directory" }, "output_dir": { "type": "string", "description": "Single repo: all output in one directory" }, "crud": { "type": "object", "properties": { "auto_clean": { "type": "boolean" }, "exclude_table_name": { "type": "boolean" }, "methods": { "type": "object", "additionalProperties": { "$ref": "#/definitions/method" } } } }, "constants": { "type": "object", "properties": { "include_column_names": { "type": "boolean" } } } } }, "table": { "type": "object", "properties": { "primary_column": { "type": "string" }, "queries_dir": { "type": "string", "description": "Override queries directory" }, "output_dir": { "type": "string", "description": "Override output directory" }, "sqlc": { "type": "object", "properties": { "query_parameter_limit": { "type": "integer" } } }, "crud": { "type": "object", "properties": { "methods": { "type": "object", "additionalProperties": { "$ref": "#/definitions/method" } } } }, "constants": { "type": "object", "properties": { "include_column_names": { "type": "boolean" } } }, "soft_delete": { "type": "object", "required": ["column"], "properties": { "column": { "type": "string" } } } } }, "method": { "type": ["object", "null"], "properties": { "name": { "type": "string", "description": "Override method name" }, "returning": { "type": "string", "description": "RETURNING clause (PostgreSQL)" }, "where": { "type": "object", "additionalProperties": { "type": "object", "properties": { "value": { "type": "string" }, "operator": { "type": "string", "default": "=" } } } }, "where_additional": { "type": "array", "items": { "type": "string" } }, "skip_columns": { "type": "array", "items": { "type": "string" } }, "column_values": { "type": "object", "additionalProperties": { "type": "string" } }, "limit": { "type": "boolean" }, "order": { "type": "object", "required": ["by"], "properties": { "by": { "type": "string" }, "direction": { "type": "string", "enum": ["ASC", "DESC"], "default": "DESC" } } } } }, "custom_query": { "type": "object", "required": ["name", "type", "sql"], "properties": { "name": { "type": "string" }, "type": { "type": "string", "enum": ["one", "many", "exec", "copyfrom"] }, "table": { "type": "string", "description": "Output to this table's queries_dir" }, "output_dir": { "type": "string" }, "sql": { "type": "string" } } } } }