Documentation
¶
Overview ¶
Package pgtypes maps Postgres types onto Go types and scan strategies.
The mapping lives in one table so that the persistence generator, the API generator, and the TypeScript generator all derive their view of a column from the same decision. When a type is not in the table, rig refuses to generate rather than guessing: a silently wrong scan is far worse to debug than a message naming the column.
Index ¶
Constants ¶
const ( ImportTime = "time" ImportUUID = "github.com/google/uuid" ImportJSON = "encoding/json" ImportNetip = "net/netip" ImportPgtype = "github.com/jackc/pgx/v5/pgtype" ImportDecimal = ImportPgtype )
Import paths for the Go types the mapping table refers to.
Variables ¶
This section is empty.
Functions ¶
func ArrayElementName ¶
ArrayElementName returns the element type of an array type, and whether the type is an array at all.
Types ¶
type Mapping ¶
type Mapping struct {
// IRType is the API-facing primitive name, one of the ir.Type* constants.
IRType string
// GoType is the Go type for a NOT NULL column. Nullable columns take a
// pointer to it, except for types that are already nilable.
GoType string
// Import is the package GoType comes from, empty for builtins.
Import string
// Scan tells the persistence layer how to move the value in and out of pgx.
Scan ir.ScanStrategy
// TSType is the TypeScript type for the value.
TSType string
// NilableGoType marks Go types that already carry a nil state, such as
// slices. Making them pointers would add a second, meaningless nil.
NilableGoType bool
}
Mapping is everything rig needs to know about a column's type.
func EnumMapping ¶
EnumMapping is the mapping for a column whose type is a Postgres enum. The Go type is the generated enum, which the caller names.
func Lookup ¶
Lookup resolves a column's type.
sqlType is the type as written in the schema and udtName is the underlying pg_type name; they differ for arrays, where udtName is the element type prefixed with an underscore. An array yields the element's mapping with a slice Go type and the Array scan strategy, so callers see one mapping rather than having to unwrap element types themselves.