Documentation
¶
Overview ¶
Package scan maps database result sets to Go structs using cached field metadata from the schema package. It is driver-agnostic: callers provide implementations of the Row and Rows interfaces (compatible with the driver package), and the scanner handles column-to-field resolution, pointer construction, and slice population.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldPtr ¶
FieldPtr returns a scan destination for the struct field identified by the schema Field, suitable for passing to database/sql or pgx Scan. It navigates nested structs using the field's GoIndex chain.
time.Time and *time.Time fields are wrapped in sql.Scanner adapters: TEXT-affinity drivers (sqlite, turso) return timestamps as RFC3339 strings, which the raw pointers cannot accept. Drivers that already produce time.Time (postgres, clickhouse) pass through the adapter unchanged.
v must be the reflect.Value of the struct (not a pointer to it).
func IsNilable ¶
IsNilable returns true if the given type can hold a nil value. This includes pointers, interfaces, slices, maps, channels, and functions.
func ScanRow ¶
ScanRow scans a single row into a struct using the provided table metadata. dest must be a pointer to a struct. The function builds a slice of field pointers from the struct based on the Table's Fields ordering and calls row.Scan with those pointers.
func ScanRows ¶
ScanRows scans all rows from a result set into a slice of structs using the provided table metadata. dest must be a pointer to a slice of structs (e.g., *[]User). The function uses column names from the result set to resolve which table fields correspond to which scan positions, allowing queries that return a subset of columns to work correctly.
After initial column resolution the hot loop performs zero allocations beyond the new struct values appended to the slice.
Types ¶
type ColumnMap ¶
type ColumnMap struct {
// contains filtered or unexported fields
}
ColumnMap maps database column names to schema fields for efficient scanning. It is built once from a Table's field list and reused across queries.
func NewColumnMap ¶
NewColumnMap creates a ColumnMap from a Table's fields. It reuses the pre-built FieldsByColumn map from the table instead of rebuilding one on every call.