Documentation
¶
Overview ¶
Package reflectmap maps struct fields to database columns, the single definition of the name-mapping rules (sqlkit tag, exact name, snake_case, flattened embeds) shared by result scanning, INSERT value extraction, and the ORM preloader.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fields ¶
Fields maps lowercased column names to the field that maps to each. Fields register under their `sqlkit` tag name when present, otherwise under both the lowercased and snake_case forms of the field name. Embedded structs are flattened (except types that scan as a single column, such as time.Time and sql.Scanner implementations); shallower fields win conflicts.
func FieldsByColumn ¶
FieldsByColumn is the path-only view of Fields, kept for callers that need only a field's location and not its tag options.
func MapsAsStruct ¶
MapsAsStruct reports whether values of t are filled field-by-field rather than scanned as a single column.
Types ¶
type Field ¶
type Field struct {
// Path is the field index path, for reflect.Value.FieldByIndex.
Path []int
// ReadOnly marks a column scanned on read but never written by INSERT or
// UPDATE — the `readonly` option, for database-generated columns
// (identity keys, computed columns, trigger-maintained timestamps).
ReadOnly bool
// JSON marks a column whose value is the JSON encoding of the field — the
// `json` (or `jsonb`) option, so a struct/map/slice field round-trips
// through a JSON/JSONB column.
JSON bool
// Version marks the optimistic-locking version column — the `version`
// option; SetStruct bumps it and guards the UPDATE with its current value.
Version bool
// Touch marks an app-maintained timestamp column — the `touch` option; the
// field is set to CURRENT_TIMESTAMP on every INSERT and implicit SetStruct
// UPDATE rather than copied from the struct.
Touch bool
}
Field describes how a struct field maps to a column, carrying both its index path and the write-time options declared after the column name in the `sqlkit` tag (`sqlkit:"name,opt,..."`).