Documentation
¶
Overview ¶
Package mapping resolves each field's underlying database column and sqlc query result column, either from an explicit override or by exactly one unambiguous automatic match; ambiguous or missing matches are reported as diagnostics rather than guessed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PascalCase ¶
PascalCase converts a snake_case identifier (the generator's own convention for field keys and generated Go names) to PascalCase, e.g. "created_at" -> "CreatedAt", applying Go's common-initialism convention so "id" -> "ID" rather than "Id".
Types ¶
type GoType ¶
type GoType struct {
Expr string // e.g. "pgtype.Text", "bool", "[]byte"
Import string // e.g. "github.com/jackc/pgx/v5/pgtype"; "" if none needed
// Unmapped is true when the column's Postgres type had no specific
// mapping and Expr fell back to "string" — surfaced as a warning by
// the caller rather than failing generation outright.
Unmapped bool
}
GoType is the resolved Go representation for a query result column: the type expression to use in generated code, plus any import path it needs beyond the driver package itself.
func ResolveGoType ¶
ResolveGoType maps col to its generated Go field type. Unknown/unmapped Postgres types fall back to "string" with Unmapped set, rather than failing generation — an explicit column/row_field override or a future type-mapping extension can refine this later without blocking a working baseline model today.
type ResolvedField ¶
type ResolvedField struct {
Name string // the field's declared config key
GoField string // generated Go struct field name, PascalCase(Name)
ColumnName string // the resolved query result column's exposed name
GoType GoType // exposed generated model type
PersistedGoType GoType // sqlc-compatible scan/parameter type
ValueObject *config.ValueObjectMapping
NotNull bool
}
ResolvedField is a field's mapping to a concrete query result column, fully resolved to real sqlc metadata (data-model.md "ResolvedField").
func Resolve ¶
func Resolve(fp config.FieldPolicy, columns []*pb.Column, path, context, model string) (ResolvedField, []diagnostics.Diagnostic)
Resolve determines which of columns a field policy identifies, per research.md "Column <-> row-field mapping resolution":
- column and row_field both explicit: the column whose underlying database identity (OriginalName, falling back to Name) matches `column` AND whose query-result identity (Name) matches `row_field`.
- column only: matches the column's underlying database identity.
- row_field only: matches the column's query-result identity verbatim.
- neither (automatic): the field's declared key must match exactly one column's query-result identity, case-insensitively.
Any outcome other than exactly one match is an FR-007 ambiguity/absence diagnostic — never a guess.