Template Data & Functions¶
The exact data structures and helper functions available inside templates.
Source of truth
These structs are defined in ../db-gen/private/dbGen/types.go (and copyTargets.go for copy targets).
Top-level template data¶
Which struct a template receives depends on the template:
// DbContext template — all routines at once:
type DbContextData struct {
Config *Config
Functions []Routine
BuildInfo *version.BuildInformation
}
// Model and Processor templates — one routine each:
type ModelTemplateData struct {
Config *Config
Routine Routine
BuildInfo *version.BuildInformation
}
type ProcessorTemplateData struct {
Config *Config
Routine Routine
BuildInfo *version.BuildInformation
}
// Copy-target templates:
type CopyTargetTemplateData struct {
Config *Config
CopyTarget CopyTarget
BuildInfo *version.BuildInformation
}
Additional generators use ModelTemplateData (per-routine) or DbContextData (single-file).
Routine¶
type Routine struct {
FunctionName string
DbFullFunctionName string
ModelName string
ProcessorName string
Schema string
DbFunctionName string
HasReturn bool
IsProcedure bool
Parameters []Property // all parameters, in order
ReturnProperties []Property
UsesUserContext bool
ContextParameters []Property // params mapped to the context object
RegularParameters []Property // params not mapped to context
}
| Field | Notes |
|---|---|
FunctionName |
Generated name (after case + MappedName overrides). |
DbFullFunctionName / DbFunctionName |
Database names (qualified / bare). |
ModelName / ProcessorName |
Derived from FunctionName. |
HasReturn / IsProcedure |
Shape flags. |
Parameters |
All parameters in order (context + regular). |
ContextParameters / RegularParameters |
The split when UsesUserContext is true. |
ReturnProperties |
Columns of the return shape. |
Property¶
A column or parameter:
type Property struct {
DbColumnName string
DbColumnType string
PropertyName string
PropertyType string // resolved type (accounts for nullable/optional)
BaseType string // base non-nullable type
NullableReturnType string // type for nullable return values / model props
NullableParamType string // type for nullable parameters
OptionalParamType string // type for optional parameters (with DEFAULT)
Position int
MapperFunction string
Nullable bool // can be unreliable
Optional bool // parameters only: has a DEFAULT value
IsContextParameter bool
ContextPath string
ValidationRules []ValidationRule
}
| Field | Notes |
|---|---|
DbColumnName / DbColumnType |
Source name and PostgreSQL udt_name. |
PropertyName |
Generated name. |
PropertyType |
The type to use — already resolved for nullability/optionality. |
BaseType / NullableReturnType / NullableParamType / OptionalParamType |
The four type-mapping tiers. |
Position |
Source field index (parameters; data columns in copy targets). |
MapperFunction |
Reader function for this type. |
Nullable / Optional |
See nullable vs optional. |
IsContextParameter / ContextPath |
Set for context parameters. |
CopyTarget¶
type CopyTarget struct {
Schema string
Table string
DbFullTableName string // "schema.table"
StructName string
Format string // "csv" | "text" | "binary"
NullString string
ContextColumns []Property
DataColumns []Property
AllColumns []Property // context columns first, then data columns
}
See Copy Targets for the wire-order rules.
Template functions¶
| Function | Result |
|---|---|
pascalCased |
GetUserById |
camelCased |
getUserById |
snakeCased |
get_user_by_id |
normalizeStr |
strips leading underscores; keeps underscores before digits |
trimPrefix |
strips a given prefix from a string |
These are standard Go template functions used like {{pascalCased $value}} or {{trimPrefix $value "prefix_"}}.