Documentation
¶
Index ¶
- func MigrateV1ToV2(pgxgenPath, sqlcPath string) ([]byte, error)
- type ConstantsDefaultsConfig
- type CrudDefaultsConfig
- type CustomQueryConfig
- type CustomTagConfig
- type DefaultsConfig
- type MethodConfig
- type ModelsConfig
- type OrderConfig
- type SchemaConfig
- type SoftDeleteConfig
- type SqlcColumnOverride
- type SqlcConfig
- type SqlcDefaultsConfig
- type SqlcOverridesConfig
- type SqlcTypeOverride
- type TableConfig
- type TableConstantsConfig
- type TableCrudConfig
- type TableSqlcConfig
- type TemplatesConfig
- type TypeOverrideConfig
- type V2Config
- type WhereParamConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MigrateV1ToV2 ¶
MigrateV1ToV2 reads v1 pgxgen.yaml and optionally sqlc.yaml, returns v2 YAML.
Types ¶
type ConstantsDefaultsConfig ¶
type ConstantsDefaultsConfig struct {
IncludeColumnNames bool `yaml:"include_column_names,omitempty"`
}
ConstantsDefaultsConfig defines default constants settings.
type CrudDefaultsConfig ¶
type CrudDefaultsConfig struct {
AutoClean bool `yaml:"auto_clean,omitempty"`
ExcludeTableName bool `yaml:"exclude_table_name,omitempty"`
Methods map[string]*MethodConfig `yaml:"methods,omitempty"`
}
CrudDefaultsConfig defines default CRUD settings for all tables.
type CustomQueryConfig ¶
type CustomQueryConfig struct {
Name string `yaml:"name" validate:"required"`
Type string `yaml:"type" validate:"required,oneof=one many exec copyfrom"`
Table string `yaml:"table,omitempty"`
OutputDir string `yaml:"output_dir,omitempty"`
SQL string `yaml:"sql" validate:"required"`
}
CustomQueryConfig defines a custom SQL query.
type CustomTagConfig ¶
type CustomTagConfig struct {
Name string `yaml:"name" validate:"required"`
Format string `yaml:"format,omitempty"` // applied to NOT NULL columns
}
CustomTagConfig defines an additional struct tag to emit.
type DefaultsConfig ¶
type DefaultsConfig struct {
// Pattern A: per-table repos
QueriesDirPrefix string `yaml:"queries_dir_prefix,omitempty"`
OutputDirPrefix string `yaml:"output_dir_prefix,omitempty"`
// Pattern B: single repo
QueriesDir string `yaml:"queries_dir,omitempty"`
OutputDir string `yaml:"output_dir,omitempty"`
Crud *CrudDefaultsConfig `yaml:"crud,omitempty"`
Constants *ConstantsDefaultsConfig `yaml:"constants,omitempty"`
}
DefaultsConfig defines defaults inherited by all tables in this schema.
type MethodConfig ¶
type MethodConfig struct {
Name string `yaml:"name,omitempty"`
Returning string `yaml:"returning,omitempty"`
Where map[string]WhereParamConfig `yaml:"where,omitempty"`
WhereAdditional []string `yaml:"where_additional,omitempty"`
SkipColumns []string `yaml:"skip_columns,omitempty"`
ColumnValues map[string]string `yaml:"column_values,omitempty"`
Limit bool `yaml:"limit,omitempty"`
Order *OrderConfig `yaml:"order,omitempty"`
}
MethodConfig defines a single CRUD method.
type ModelsConfig ¶
type ModelsConfig struct {
OutputDir string `yaml:"output_dir" validate:"required"`
OutputFileName string `yaml:"output_file_name,omitempty"`
PackageName string `yaml:"package_name" validate:"required"`
PackagePath string `yaml:"package_path,omitempty"`
CustomTypes []string `yaml:"custom_types,omitempty"`
SkipTables []string `yaml:"skip_tables,omitempty"`
SkipEnums []string `yaml:"skip_enums,omitempty"`
EmitJsonTags bool `yaml:"emit_json_tags,omitempty"`
EmitDbTags bool `yaml:"emit_db_tags,omitempty"`
EmitPointersForNull bool `yaml:"emit_pointers_for_null,omitempty"`
IncludeStructComments bool `yaml:"include_struct_comments,omitempty"`
SqlPackage string `yaml:"sql_package,omitempty" validate:"omitempty,oneof=pgx/v5 pgx/v4 database/sql"`
TypeOverrides []TypeOverrideConfig `yaml:"type_overrides,omitempty"`
CustomTags []CustomTagConfig `yaml:"custom_tags,omitempty"`
}
ModelsConfig defines Go model generation settings.
func (*ModelsConfig) GetOutputFileName ¶
func (c *ModelsConfig) GetOutputFileName() string
GetOutputFileName returns the output file name, defaulting to "models.go".
type OrderConfig ¶
type OrderConfig struct {
By string `yaml:"by" validate:"required"`
Direction string `yaml:"direction,omitempty"` // default: DESC
}
OrderConfig defines ORDER BY settings.
func (*OrderConfig) GetDirection ¶
func (o *OrderConfig) GetDirection() string
GetDirection returns the direction, defaulting to DESC.
type SchemaConfig ¶
type SchemaConfig struct {
Name string `yaml:"name" validate:"required"`
Engine string `yaml:"engine" validate:"required,oneof=postgresql mysql sqlite"`
SchemaDir string `yaml:"schema_dir" validate:"required"`
Models *ModelsConfig `yaml:"models,omitempty"`
Sqlc *SqlcConfig `yaml:"sqlc,omitempty"`
Defaults *DefaultsConfig `yaml:"defaults,omitempty"`
Tables map[string]TableConfig `yaml:"tables,omitempty"`
CustomQueries []CustomQueryConfig `yaml:"custom_queries,omitempty"`
}
SchemaConfig defines a single schema source with its engine, paths, and generation options.
func (*SchemaConfig) IsPerTableMode ¶
func (s *SchemaConfig) IsPerTableMode() bool
IsPerTableMode returns true if per-table repos pattern is used.
func (*SchemaConfig) ResolveOutputDir ¶
func (s *SchemaConfig) ResolveOutputDir(tableName string) string
ResolveOutputDir returns the sqlc output directory for a table.
func (*SchemaConfig) ResolveQueriesDir ¶
func (s *SchemaConfig) ResolveQueriesDir(tableName string) string
ResolveQueriesDir returns the queries directory for a table.
type SoftDeleteConfig ¶
type SoftDeleteConfig struct {
Column string `yaml:"column" validate:"required"`
}
SoftDeleteConfig enables soft delete for a table.
type SqlcColumnOverride ¶
type SqlcColumnOverride struct {
Column string `yaml:"column" validate:"required"`
GoType interface{} `yaml:"go_type,omitempty"`
GoStructTag string `yaml:"go_struct_tag,omitempty"`
}
SqlcColumnOverride defines per-column overrides (struct tags, go types).
type SqlcConfig ¶
type SqlcConfig struct {
Defaults *SqlcDefaultsConfig `yaml:"defaults,omitempty"`
Overrides *SqlcOverridesConfig `yaml:"overrides,omitempty"`
}
SqlcConfig defines sqlc auto-generation settings.
type SqlcDefaultsConfig ¶
type SqlcDefaultsConfig struct {
SqlPackage string `yaml:"sql_package,omitempty" validate:"omitempty,oneof=pgx/v5 pgx/v4 database/sql"`
EmitPreparedQueries bool `yaml:"emit_prepared_queries"`
EmitInterface bool `yaml:"emit_interface"`
EmitJsonTags bool `yaml:"emit_json_tags"`
EmitDbTags bool `yaml:"emit_db_tags"`
EmitExportedQueries bool `yaml:"emit_exported_queries"`
EmitExactTableNames bool `yaml:"emit_exact_table_names"`
EmitEmptySlices bool `yaml:"emit_empty_slices"`
EmitResultStructPointers bool `yaml:"emit_result_struct_pointers"`
EmitParamsStructPointers bool `yaml:"emit_params_struct_pointers"`
EmitEnumValidMethod bool `yaml:"emit_enum_valid_method"`
EmitAllEnumValues bool `yaml:"emit_all_enum_values"`
QueryParameterLimit *int `yaml:"query_parameter_limit,omitempty"`
JsonTagsCaseStyle string `yaml:"json_tags_case_style,omitempty"`
}
SqlcDefaultsConfig holds default sqlc gen.go options applied to all repos.
type SqlcOverridesConfig ¶
type SqlcOverridesConfig struct {
Rename map[string]string `yaml:"rename,omitempty"`
Types []SqlcTypeOverride `yaml:"types,omitempty"`
Columns []SqlcColumnOverride `yaml:"columns,omitempty"`
}
SqlcOverridesConfig maps 1:1 to sqlc's overrides section.
type SqlcTypeOverride ¶
type SqlcTypeOverride struct {
DbType string `yaml:"db_type" validate:"required"`
GoType interface{} `yaml:"go_type" validate:"required"` // string or {type: ..., import: ...}
Nullable bool `yaml:"nullable,omitempty"`
}
SqlcTypeOverride defines a db_type → go_type mapping.
type TableConfig ¶
type TableConfig struct {
PrimaryColumn string `yaml:"primary_column,omitempty"`
QueriesDir string `yaml:"queries_dir,omitempty"` // override
OutputDir string `yaml:"output_dir,omitempty"` // override
Sqlc *TableSqlcConfig `yaml:"sqlc,omitempty"`
Crud *TableCrudConfig `yaml:"crud,omitempty"`
Constants *TableConstantsConfig `yaml:"constants,omitempty"`
SoftDelete *SoftDeleteConfig `yaml:"soft_delete,omitempty"`
}
TableConfig defines per-table settings (crud + constants + sqlc overrides).
type TableConstantsConfig ¶
type TableConstantsConfig struct {
IncludeColumnNames *bool `yaml:"include_column_names,omitempty"`
}
TableConstantsConfig holds per-table constants settings.
type TableCrudConfig ¶
type TableCrudConfig struct {
Methods map[string]*MethodConfig `yaml:"methods,omitempty"`
}
TableCrudConfig holds per-table CRUD settings.
type TableSqlcConfig ¶
type TableSqlcConfig struct {
QueryParameterLimit *int `yaml:"query_parameter_limit,omitempty"`
}
TableSqlcConfig holds per-table sqlc overrides.
type TemplatesConfig ¶
type TemplatesConfig struct {
CrudDir string `yaml:"crud_dir,omitempty"`
ModelsDir string `yaml:"models_dir,omitempty"`
}
TemplatesConfig allows user-provided templates.
type TypeOverrideConfig ¶
type TypeOverrideConfig struct {
SqlType string `yaml:"sql_type" validate:"required"`
GoType string `yaml:"go_type" validate:"required"`
Import string `yaml:"import,omitempty"`
}
TypeOverrideConfig overrides SQL type → Go type mapping.
type V2Config ¶
type V2Config struct {
Version string `yaml:"version" validate:"required,eq=2"`
Schemas []SchemaConfig `yaml:"schemas" validate:"required,min=1,dive"`
Templates *TemplatesConfig `yaml:"templates,omitempty"`
}
V2Config is the root configuration for pgxgen v2.
func LoadV2Config ¶
LoadV2Config loads and validates a v2 pgxgen config file.
type WhereParamConfig ¶
type WhereParamConfig struct {
Value string `yaml:"value,omitempty"`
Operator string `yaml:"operator,omitempty"` // default: =
}
WhereParamConfig defines a WHERE condition.