Help us shape the future of Go! Take the 2026 Go Developer Survey

pgtypes

package
v0.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 2 Imported by: 0

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

View Source
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

func ArrayElementName(sqlType, udtName string) (string, bool)

ArrayElementName returns the element type of an array type, and whether the type is an array at all.

func GoTypeFor

func GoTypeFor(m Mapping, nullable bool) string

GoTypeFor renders the Go type for a column, adding a pointer for nullable columns whose type does not already carry a nil state.

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

func EnumMapping(goType string) Mapping

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

func Lookup(sqlType, udtName string) (m Mapping, isArray bool, ok bool)

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.

func Primitive

func Primitive(irType string) (Mapping, bool)

Primitive returns the mapping for an API primitive type name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL