Documentation ¶
Index ¶
- Variables
- func ChooseFallbackName(pgName string, prefix string) string
- func ExtractShortPackage(pkgPath []byte) string
- func HasArrayType(t Type) bool
- func HasCompositeType(t Type) bool
- func IsPgxSupportedArray(typ *ArrayType) bool
- func QualifyType(typ Type, otherPkgPath string) string
- type ArrayType
- type CompositeType
- type EnumType
- type ImportType
- type OpaqueType
- type PointerType
- type Type
- func FindKnownTypeNonNullable(oid uint32) (Type, bool)
- func FindKnownTypeNullable(oid uint32) (Type, bool)
- func FindKnownTypePgx(oid uint32) (Type, bool)
- func MustParseKnownType(qualType string, pgType pg.Type) Type
- func MustParseOpaqueType(qualType string) Type
- func NewArrayType(pgArray pg.ArrayType, elemType Type) Type
- func NewEnumType(pkgPath string, pgEnum pg.EnumType, caser casing.Caser) Type
- func ParseOpaqueType(qualType string, pgType pg.Type) (Type, error)
- func UnwrapNestedType(typ Type) Type
- type VoidType
Constants ¶
This section is empty.
Variables ¶
var ( Bool = MustParseKnownType("bool", pg.Bool) Boolp = MustParseKnownType("*bool", pg.Bool) Int = MustParseKnownType("int", pg.Int8) Intp = MustParseKnownType("*int", pg.Int8) IntSlice = MustParseKnownType("[]int", pg.Int8Array) IntpSlice = MustParseKnownType("[]*int", pg.Int8Array) Int16 = MustParseKnownType("int16", pg.Int2) Int16p = MustParseKnownType("*int16", pg.Int2) Int16Slice = MustParseKnownType("[]int16", pg.Int2Array) Int16pSlice = MustParseKnownType("[]*int16", pg.Int2Array) Int32 = MustParseKnownType("int32", pg.Int4) Int32p = MustParseKnownType("*int32", pg.Int4) Int32Slice = MustParseKnownType("[]int32", pg.Int4Array) Int32pSlice = MustParseKnownType("[]*int32", pg.Int4Array) Int64 = MustParseKnownType("int64", pg.Int8) Int64p = MustParseKnownType("*int64", pg.Int8) Int64Slice = MustParseKnownType("[]int64", pg.Int8Array) Int64pSlice = MustParseKnownType("[]*int64", pg.Int8Array) Uint = MustParseKnownType("uint", pg.Int8) UintSlice = MustParseKnownType("[]uint", pg.Int8Array) Uint16 = MustParseKnownType("uint16", pg.Int2) Uint16Slice = MustParseKnownType("[]uint16", pg.Int2Array) Uint32 = MustParseKnownType("uint32", pg.Int4) Uint32Slice = MustParseKnownType("[]uint32", pg.Int4Array) Uint64 = MustParseKnownType("uint64", pg.Int8) Uint64Slice = MustParseKnownType("[]uint64", pg.Int8Array) String = MustParseKnownType("string", pg.Text) Stringp = MustParseKnownType("*string", pg.Text) StringSlice = MustParseKnownType("[]string", pg.TextArray) StringpSlice = MustParseKnownType("[]*string", pg.TextArray) Float32 = MustParseKnownType("float32", pg.Float4) Float32p = MustParseKnownType("*float32", pg.Float4) Float32Slice = MustParseKnownType("[]float32", pg.Float4Array) Float32pSlice = MustParseKnownType("[]*float32", pg.Float4Array) Float64 = MustParseKnownType("float64", pg.Float8) Float64p = MustParseKnownType("*float64", pg.Float8) Float64Slice = MustParseKnownType("[]float64", pg.Float8Array) Float64pSlice = MustParseKnownType("[]*float64", pg.Float8Array) ByteSlice = MustParseKnownType("[]byte", pg.Bytea) )
Native go types are not prefixed.
var ( PgBool = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Bool", pg.Bool) PgQChar = MustParseKnownType("byte", pg.QChar) PgName = MustParseKnownType("string", pg.Name) PgInt8 = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Int8", pg.Int8) PgInt2 = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Int2", pg.Int2) PgInt4 = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Int4", pg.Int4) PgText = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Text", pg.Text) PgBytea = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Bytea", pg.Bytea) PgOID = MustParseKnownType("uint32", pg.OID) PgTID = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.TID", pg.TID) PgXID = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.XID", pg.XID) PgCID = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.CID", pg.CID) PgJSON = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.JSON", pg.JSON) PgPoint = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Point", pg.Point) PgLseg = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Lseg", pg.Lseg) PgPath = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Path", pg.Path) PgBox = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Box", pg.Box) PgPolygon = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Polygon", pg.Polygon) PgLine = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Line", pg.Line) PgCIDR = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.CIDR", pg.CIDR) PgCIDRArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.CIDRArray", pg.CIDRArray) PgFloat4 = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Float4", pg.Float4) PgFloat8 = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Float8", pg.Float8) PgUnknown = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Unknown", pg.Unknown) PgCircle = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Circle", pg.Circle) PgMacaddr = MustParseKnownType("net.HardwareAddr", pg.Macaddr) PgInet = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Inet", pg.Inet) PgBoolArray = MustParseKnownType("[]bool", pg.BoolArray) PgByteaArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.ByteaArray", pg.ByteaArray) PgInt2Array = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Int2Array", pg.Int2Array) PgInt4Array = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Int4Array", pg.Int4Array) PgTextArray = MustParseKnownType("[]string", pg.TextArray) PgBPCharArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.BPCharArray", pg.BPCharArray) PgVarcharArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.VarcharArray", pg.VarcharArray) PgInt8Array = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Int8Array", pg.Int8Array) PgFloat4Array = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Float4Array", pg.Float4Array) PgFloat8Array = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Float8Array", pg.Float8Array) PgACLItem = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.ACLItem", pg.ACLItem) PgACLItemArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.ACLItemArray", pg.ACLItemArray) PgInetArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.InetArray", pg.InetArray) PgMacaddrArray = MustParseKnownType("[]net.HardwareAddr", pg.MacaddrArray) PgBPChar = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.BPChar", pg.BPChar) PgVarchar = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Varchar", pg.Varchar) PgDate = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Date", pg.Date) PgTime = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Time", pg.Time) PgTimestamp = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Timestamp", pg.Timestamp) PgTimestampArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.TimestampArray", pg.TimestampArray) PgDateArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.DateArray", pg.DateArray) PgTimestamptz = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Timestamptz", pg.Timestamptz) PgTimestamptzArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.TimestamptzArray", pg.TimestamptzArray) PgInterval = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Interval", pg.Interval) PgNumericArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.NumericArray", pg.NumericArray) PgBit = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Bit", pg.Bit) PgVarbit = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Varbit", pg.Varbit) PgVoid = &VoidType{} PgNumeric = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Numeric", pg.Numeric) PgRecord = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Record", pg.Record) PgUUID = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.UUID", pg.UUID) PgUUIDArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.UUIDArray", pg.UUIDArray) PgJSONB = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.JSONB", pg.JSONB) PgJSONBArray = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.JSONBArray", pg.JSONBArray) PgInt4range = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Int4range", pg.Int4range) PgNumrange = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Numrange", pg.Numrange) PgTsrange = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Tsrange", pg.Tsrange) PgTstzrange = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Tstzrange", pg.Tstzrange) PgDaterange = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Daterange", pg.Daterange) PgInt8range = MustParseKnownType("github.com/jackc/pgx/v5/pgtype.Int8range", pg.Int8range) )
pgtype types prefixed with "pg".
Functions ¶
func ChooseFallbackName ¶
func ExtractShortPackage ¶
ExtractShortPackage gets the last part of a package path like "generate" in "github.com/robbert229/pggen/generate".
func HasArrayType ¶
HasArrayType returns true if t or any of t's descendants (for array and composite types) is an array type.
func HasCompositeType ¶
HasCompositeType returns true if t or any of t's descendants (for array and composite types) is a composite type.
func IsPgxSupportedArray ¶
IsPgxSupportedArray returns true if pgx can handle the translation from the Go array type into the Postgres type.
func QualifyType ¶
Types ¶
type ArrayType ¶
type ArrayType struct { PgArray pg.ArrayType // original Postgres array type Elem Type // element type of the slice, like int for []int }
ArrayType is a Go slice type.
type CompositeType ¶
type CompositeType struct { PgComposite pg.CompositeType // original Postgres composite type Name string // Go-style type name in UpperCamelCase FieldNames []string // Go-style child names in UpperCamelCase FieldTypes []Type }
CompositeType is a struct type that represents a Postgres composite type.
func (*CompositeType) BaseName ¶
func (c *CompositeType) BaseName() string
func (*CompositeType) Import ¶
func (c *CompositeType) Import() string
type EnumType ¶
type EnumType struct { PgEnum pg.EnumType // the original Postgres enum type Name string // name of the unqualified Go type // Labels of the Postgres enum formatted as Go identifiers ordered in the // same order as in Postgres. Labels []string // The string constant associated with a label. Labels[i] represents // Values[i]. Values []string }
EnumType is a string type with constant values that maps to the labels of a Postgres enum.
type ImportType ¶
type ImportType struct { PkgPath string // fully qualified package path, like "github.com/robbert229/pggen" Type Type // type to import }
ImportType is an imported type.
func (*ImportType) BaseName ¶
func (e *ImportType) BaseName() string
func (*ImportType) Import ¶
func (e *ImportType) Import() string
type OpaqueType ¶
type OpaqueType struct { PgType pg.Type // original Postgres type Name string // name of the unqualified Go type }
OpaqueType is a type where only the name is known, as with a user-provided custom type.
func (*OpaqueType) BaseName ¶
func (o *OpaqueType) BaseName() string
func (*OpaqueType) Import ¶
func (o *OpaqueType) Import() string
type PointerType ¶
type PointerType struct {
Elem Type // the pointed-to type
}
PointerType is a pointer to another Go type.
func (*PointerType) BaseName ¶
func (o *PointerType) BaseName() string
func (*PointerType) Import ¶
func (o *PointerType) Import() string
type Type ¶
type Type interface { // Import returns the full package path, like "github.com/robbert229/pggen/foo". // Empty for builtin types. Import() string // BaseName returns the unqualified, base name of the type, like "Foo" in: // type Foo int, or "[]*Foo". BaseName() string }
Type is a Go type.
func FindKnownTypeNonNullable ¶
FindKnownTypeNonNullable returns the non-nullable type like string, if known, for a Postgres OID. Falls back to the nullable type and pgNative type. If there is no known type for the OID, returns nil.
func FindKnownTypeNullable ¶
FindKnownTypeNullable returns the nullable type, like *string, if known, for a Postgres OID. Falls back to the pgNative type. If there is no known type for the OID, returns nil.
func FindKnownTypePgx ¶
FindKnownTypePgx returns the native pgx type, like pgtype.Text, if known, for a Postgres OID. If there is no known type, returns nil.
func MustParseKnownType ¶
MustParseKnownType creates a gotype.Type by parsing a fully qualified Go type that pgx supports natively like "github.com/jackc/pgx/v5/pgtype.Int4Array", or most builtin types like "string" and []*int16.
func MustParseOpaqueType ¶
MustParseOpaqueType creates a gotype.Type by parsing a fully qualified Go type unsupported by pgx supports natively like "github.com/example/Foo"
func ParseOpaqueType ¶
ParseOpaqueType creates a Type by parsing a fully qualified Go type like "github.com/robbert229/custom.Int4" with the backing pg.Type.
- []int
- []*int
- *example.com/foo.Qux
- []*example.com/foo.Qux
func UnwrapNestedType ¶
UnwrapNestedType returns the first type under gotype.ImportType or gotype.PointerType.