Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scanner ¶
type Scanner[T any] struct { // contains filtered or unexported fields }
Scanner pre-computes struct reflection at construction time and caches column-to-field mappings keyed by the actual column layout returned by PostgreSQL. Different PG versions returning different columns from SELECT * each get their own cached mapping. Scanner is safe for concurrent use.
Usage:
var pgStatScanner = pgxutil.NewScanner[PgStatDatabase]() rows, err := pool.Query(ctx, "SELECT * FROM pg_stat_database") results, err := pgx.CollectRows(rows, pgStatScanner.Scan)
func NewScanner ¶
NewScanner creates a Scanner for struct type T. Call this once at package init or startup. It holds a map from field name (as expected from the database) to the index path of the struct. This "cuts" out the index lookup that would be required at runtime if instead it relied on `reflect.Value.FieldByName`.
Panics if T is not a struct.