gotype

package
v0.0.0-...-765d1ad Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

View Source
var (
	PgBool             = MustParseKnownType("github.com/jackc/pgtype.Bool", pg.Bool)
	PgQChar            = MustParseKnownType("github.com/jackc/pgtype.QChar", pg.QChar)
	PgName             = MustParseKnownType("github.com/jackc/pgtype.Name", pg.Name)
	PgInt8             = MustParseKnownType("github.com/jackc/pgtype.Int8", pg.Int8)
	PgInt2             = MustParseKnownType("github.com/jackc/pgtype.Int2", pg.Int2)
	PgInt4             = MustParseKnownType("github.com/jackc/pgtype.Int4", pg.Int4)
	PgText             = MustParseKnownType("github.com/jackc/pgtype.Text", pg.Text)
	PgBytea            = MustParseKnownType("github.com/jackc/pgtype.Bytea", pg.Bytea)
	PgOID              = MustParseKnownType("github.com/jackc/pgtype.OID", pg.OID)
	PgTID              = MustParseKnownType("github.com/jackc/pgtype.TID", pg.TID)
	PgXID              = MustParseKnownType("github.com/jackc/pgtype.XID", pg.XID)
	PgCID              = MustParseKnownType("github.com/jackc/pgtype.CID", pg.CID)
	PgJSON             = MustParseKnownType("github.com/jackc/pgtype.JSON", pg.JSON)
	PgPoint            = MustParseKnownType("github.com/jackc/pgtype.Point", pg.Point)
	PgLseg             = MustParseKnownType("github.com/jackc/pgtype.Lseg", pg.Lseg)
	PgPath             = MustParseKnownType("github.com/jackc/pgtype.Path", pg.Path)
	PgBox              = MustParseKnownType("github.com/jackc/pgtype.Box", pg.Box)
	PgPolygon          = MustParseKnownType("github.com/jackc/pgtype.Polygon", pg.Polygon)
	PgLine             = MustParseKnownType("github.com/jackc/pgtype.Line", pg.Line)
	PgCIDR             = MustParseKnownType("github.com/jackc/pgtype.CIDR", pg.CIDR)
	PgCIDRArray        = MustParseKnownType("github.com/jackc/pgtype.CIDRArray", pg.CIDRArray)
	PgFloat4           = MustParseKnownType("github.com/jackc/pgtype.Float4", pg.Float4)
	PgFloat8           = MustParseKnownType("github.com/jackc/pgtype.Float8", pg.Float8)
	PgUnknown          = MustParseKnownType("github.com/jackc/pgtype.Unknown", pg.Unknown)
	PgCircle           = MustParseKnownType("github.com/jackc/pgtype.Circle", pg.Circle)
	PgMacaddr          = MustParseKnownType("github.com/jackc/pgtype.Macaddr", pg.Macaddr)
	PgInet             = MustParseKnownType("github.com/jackc/pgtype.Inet", pg.Inet)
	PgBoolArray        = MustParseKnownType("github.com/jackc/pgtype.BoolArray", pg.BoolArray)
	PgByteaArray       = MustParseKnownType("github.com/jackc/pgtype.ByteaArray", pg.ByteaArray)
	PgInt2Array        = MustParseKnownType("github.com/jackc/pgtype.Int2Array", pg.Int2Array)
	PgInt4Array        = MustParseKnownType("github.com/jackc/pgtype.Int4Array", pg.Int4Array)
	PgTextArray        = MustParseKnownType("github.com/jackc/pgtype.TextArray", pg.TextArray)
	PgBPCharArray      = MustParseKnownType("github.com/jackc/pgtype.BPCharArray", pg.BPCharArray)
	PgVarcharArray     = MustParseKnownType("github.com/jackc/pgtype.VarcharArray", pg.VarcharArray)
	PgInt8Array        = MustParseKnownType("github.com/jackc/pgtype.Int8Array", pg.Int8Array)
	PgFloat4Array      = MustParseKnownType("github.com/jackc/pgtype.Float4Array", pg.Float4Array)
	PgFloat8Array      = MustParseKnownType("github.com/jackc/pgtype.Float8Array", pg.Float8Array)
	PgACLItem          = MustParseKnownType("github.com/jackc/pgtype.ACLItem", pg.ACLItem)
	PgACLItemArray     = MustParseKnownType("github.com/jackc/pgtype.ACLItemArray", pg.ACLItemArray)
	PgInetArray        = MustParseKnownType("github.com/jackc/pgtype.InetArray", pg.InetArray)
	PgMacaddrArray     = MustParseKnownType("github.com/jackc/pgtype.MacaddrArray", pg.MacaddrArray)
	PgBPChar           = MustParseKnownType("github.com/jackc/pgtype.BPChar", pg.BPChar)
	PgVarchar          = MustParseKnownType("github.com/jackc/pgtype.Varchar", pg.Varchar)
	PgDate             = MustParseKnownType("github.com/jackc/pgtype.Date", pg.Date)
	PgTime             = MustParseKnownType("github.com/jackc/pgtype.Time", pg.Time)
	PgTimestamp        = MustParseKnownType("github.com/jackc/pgtype.Timestamp", pg.Timestamp)
	PgTimestampArray   = MustParseKnownType("github.com/jackc/pgtype.TimestampArray", pg.TimestampArray)
	PgDateArray        = MustParseKnownType("github.com/jackc/pgtype.DateArray", pg.DateArray)
	PgTimestamptz      = MustParseKnownType("github.com/jackc/pgtype.Timestamptz", pg.Timestamptz)
	PgTimestamptzArray = MustParseKnownType("github.com/jackc/pgtype.TimestamptzArray", pg.TimestamptzArray)
	PgInterval         = MustParseKnownType("github.com/jackc/pgtype.Interval", pg.Interval)
	PgNumericArray     = MustParseKnownType("github.com/jackc/pgtype.NumericArray", pg.NumericArray)
	PgBit              = MustParseKnownType("github.com/jackc/pgtype.Bit", pg.Bit)
	PgVarbit           = MustParseKnownType("github.com/jackc/pgtype.Varbit", pg.Varbit)
	PgVoid             = &VoidType{}
	PgNumeric          = MustParseKnownType("github.com/jackc/pgtype.Numeric", pg.Numeric)
	PgRecord           = MustParseKnownType("github.com/jackc/pgtype.Record", pg.Record)
	PgUUID             = MustParseKnownType("github.com/jackc/pgtype.UUID", pg.UUID)
	PgUUIDArray        = MustParseKnownType("github.com/jackc/pgtype.UUIDArray", pg.UUIDArray)
	PgJSONB            = MustParseKnownType("github.com/jackc/pgtype.JSONB", pg.JSONB)
	PgJSONBArray       = MustParseKnownType("github.com/jackc/pgtype.JSONBArray", pg.JSONBArray)
	PgInt4range        = MustParseKnownType("github.com/jackc/pgtype.Int4range", pg.Int4range)
	PgNumrange         = MustParseKnownType("github.com/jackc/pgtype.Numrange", pg.Numrange)
	PgTsrange          = MustParseKnownType("github.com/jackc/pgtype.Tsrange", pg.Tsrange)
	PgTstzrange        = MustParseKnownType("github.com/jackc/pgtype.Tstzrange", pg.Tstzrange)
	PgDaterange        = MustParseKnownType("github.com/jackc/pgtype.Daterange", pg.Daterange)
	PgInt8range        = MustParseKnownType("github.com/jackc/pgtype.Int8range", pg.Int8range)
)

pgtype types prefixed with "pg".

Functions

func ChooseFallbackName

func ChooseFallbackName(pgName string, prefix string) string

func ExtractShortPackage

func ExtractShortPackage(pkgPath []byte) string

ExtractShortPackage gets the last part of a package path like "generate" in "github.com/eddiefisher/pggen/generate".

func HasArrayType

func HasArrayType(t Type) bool

HasArrayType returns true if t or any of t's descendants (for array and composite types) is an array type.

func HasCompositeType

func HasCompositeType(t Type) bool

HasCompositeType returns true if t or any of t's descendants (for array and composite types) is a composite type.

func IsPgxSupportedArray

func IsPgxSupportedArray(typ *ArrayType) bool

IsPgxSupportedArray returns true if pgx can handle the translation from the Go array type into the Postgres type.

func QualifyType

func QualifyType(typ Type, otherPkgPath string) string

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.

func (*ArrayType) BaseName

func (a *ArrayType) BaseName() string

func (*ArrayType) Import

func (a *ArrayType) Import() string

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.

func (*EnumType) BaseName

func (e *EnumType) BaseName() string

func (*EnumType) Import

func (e *EnumType) Import() string

type ImportType

type ImportType struct {
	PkgPath string // fully qualified package path, like "github.com/eddiefisher/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/eddiefisher/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

func FindKnownTypeNonNullable(oid pgtype.OID) (Type, bool)

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

func FindKnownTypeNullable(oid pgtype.OID) (Type, bool)

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

func FindKnownTypePgx(oid pgtype.OID) (Type, bool)

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

func MustParseKnownType(qualType string, pgType pg.Type) Type

MustParseKnownType creates a gotype.Type by parsing a fully qualified Go type that pgx supports natively like "github.com/jackc/pgtype.Int4Array", or most builtin types like "string" and []*int16.

func MustParseOpaqueType

func MustParseOpaqueType(qualType string) Type

MustParseOpaqueType creates a gotype.Type by parsing a fully qualified Go type unsupported by pgx supports natively like "github.com/example/Foo"

func NewArrayType

func NewArrayType(pgArray pg.ArrayType, elemType Type) Type

func NewEnumType

func NewEnumType(pkgPath string, pgEnum pg.EnumType, caser casing.Caser) Type

func ParseOpaqueType

func ParseOpaqueType(qualType string, pgType pg.Type) (Type, error)

ParseOpaqueType creates a Type by parsing a fully qualified Go type like "github.com/eddiefisher/custom.Int4" with the backing pg.Type.

  • []int
  • []*int
  • *example.com/foo.Qux
  • []*example.com/foo.Qux

func UnwrapNestedType

func UnwrapNestedType(typ Type) Type

UnwrapNestedType returns the first type under gotype.ImportType or gotype.PointerType.

type VoidType

type VoidType struct{}

VoidType is a placeholder type that should never appear in output. We need a placeholder to scan pgx rows, but we ultimately ignore the results in the return values.

func (*VoidType) BaseName

func (e *VoidType) BaseName() string

func (*VoidType) Import

func (e *VoidType) Import() string

Jump to

Keyboard shortcuts

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