Documentation
¶
Index ¶
- Variables
- type ArrayType
- type BaseType
- type Column
- type ColumnKey
- type CompositeType
- type DBQuerier
- func (q *DBQuerier) FindArrayTypes(ctx context.Context, oids []uint32) ([]FindArrayTypesRow, error)
- func (q *DBQuerier) FindCompositeTypes(ctx context.Context, oids []uint32) ([]FindCompositeTypesRow, error)
- func (q *DBQuerier) FindDescendantOIDs(ctx context.Context, oids []uint32) ([]uint32, error)
- func (q *DBQuerier) FindEnumTypes(ctx context.Context, oids []uint32) ([]FindEnumTypesRow, error)
- func (q *DBQuerier) FindOIDByName(ctx context.Context, name string) (uint32, error)
- func (q *DBQuerier) FindOIDName(ctx context.Context, oid uint32) (string, error)
- func (q *DBQuerier) FindOIDNames(ctx context.Context, oid []uint32) ([]FindOIDNamesRow, error)
- type DebugCodec
- func (d *DebugCodec) DecodeDatabaseSQLValue(m *pgtype.Map, oid uint32, format int16, src []byte) (driver.Value, error)
- func (d *DebugCodec) DecodeValue(m *pgtype.Map, oid uint32, format int16, src []byte) (any, error)
- func (d *DebugCodec) FormatSupported(int16) bool
- func (d *DebugCodec) PlanEncode(m *pgtype.Map, oid uint32, format int16, value any) pgtype.EncodePlan
- func (d *DebugCodec) PlanScan(m *pgtype.Map, oid uint32, format int16, target any) pgtype.ScanPlan
- func (d *DebugCodec) PreferredFormat() int16
- type DomainType
- type EnumType
- type FindArrayTypesRow
- type FindCompositeTypesRow
- type FindEnumTypesRow
- type FindOIDNamesRow
- type Querier
- type Type
- type TypeFetcher
- type TypeKind
- type UnknownType
- type VoidType
Constants ¶
This section is empty.
Variables ¶
var ( Bool = BaseType{ID: pgtype.BoolOID, Name: "bool"} Bytea = BaseType{ID: pgtype.ByteaOID, Name: "bytea"} QChar = BaseType{ID: pgtype.QCharOID, Name: "char"} Name = BaseType{ID: pgtype.NameOID, Name: "name"} Int8 = BaseType{ID: pgtype.Int8OID, Name: "int8"} Int2 = BaseType{ID: pgtype.Int2OID, Name: "int2"} Int4 = BaseType{ID: pgtype.Int4OID, Name: "int4"} Text = BaseType{ID: pgtype.TextOID, Name: "text"} OID = BaseType{ID: pgtype.OIDOID, Name: "oid"} TID = BaseType{ID: pgtype.TIDOID, Name: "tid"} XID = BaseType{ID: pgtype.XIDOID, Name: "xid"} CID = BaseType{ID: pgtype.CIDOID, Name: "cid"} JSON = BaseType{ID: pgtype.JSONOID, Name: "json"} PgNodeTree = BaseType{ID: pgoid.PgNodeTree, Name: "pg_node_tree"} Point = BaseType{ID: pgtype.PointOID, Name: "point"} Lseg = BaseType{ID: pgtype.LsegOID, Name: "lseg"} Path = BaseType{ID: pgtype.PathOID, Name: "path"} Box = BaseType{ID: pgtype.BoxOID, Name: "box"} Polygon = BaseType{ID: pgtype.PolygonOID, Name: "polygon"} Line = BaseType{ID: pgtype.LineOID, Name: "line"} CIDR = BaseType{ID: pgtype.CIDROID, Name: "cidr"} CIDRArray = ArrayType{ID: pgtype.CIDRArrayOID, Name: "_cidr"} Float4 = BaseType{ID: pgtype.Float4OID, Name: "float4"} Float8 = BaseType{ID: pgtype.Float8OID, Name: "float8"} Unknown = BaseType{ID: pgtype.UnknownOID, Name: "unknown"} Circle = BaseType{ID: pgtype.CircleOID, Name: "circle"} Macaddr = BaseType{ID: pgtype.MacaddrOID, Name: "macaddr"} Inet = BaseType{ID: pgtype.InetOID, Name: "inet"} BoolArray = ArrayType{ID: pgtype.BoolArrayOID, Name: "_bool"} ByteaArray = ArrayType{ID: pgtype.ByteaArrayOID, Name: "_bytea"} Int2Array = ArrayType{ID: pgtype.Int2ArrayOID, Name: "_int2"} Int4Array = ArrayType{ID: pgtype.Int4ArrayOID, Name: "_int4"} TextArray = ArrayType{ID: pgtype.TextArrayOID, Name: "_text"} BPCharArray = ArrayType{ID: pgtype.BPCharArrayOID, Name: "_bpchar"} VarcharArray = ArrayType{ID: pgtype.VarcharArrayOID, Name: "_varchar"} Int8Array = ArrayType{ID: pgtype.Int8ArrayOID, Name: "_int8"} Float4Array = ArrayType{ID: pgtype.Float4ArrayOID, Name: "_float4"} Float8Array = ArrayType{ID: pgtype.Float8ArrayOID, Name: "_float8"} OIDArray = ArrayType{ID: pgoid.OIDArray, Name: "_oid"} ACLItem = BaseType{ID: pgtype.ACLItemOID, Name: "aclitem"} ACLItemArray = ArrayType{ID: pgtype.ACLItemArrayOID, Name: "_aclitem"} InetArray = ArrayType{ID: pgtype.InetArrayOID, Name: "_inet"} MacaddrArray = ArrayType{ID: pgoid.MacaddrArray, Name: "_macaddr"} BPChar = BaseType{ID: pgtype.BPCharOID, Name: "bpchar"} Varchar = BaseType{ID: pgtype.VarcharOID, Name: "varchar"} Date = BaseType{ID: pgtype.DateOID, Name: "date"} Time = BaseType{ID: pgtype.TimeOID, Name: "time"} Timestamp = BaseType{ID: pgtype.TimestampOID, Name: "timestamp"} TimestampArray = ArrayType{ID: pgtype.TimestampArrayOID, Name: "_timestamp"} DateArray = ArrayType{ID: pgtype.DateArrayOID, Name: "_date"} Timestamptz = BaseType{ID: pgtype.TimestamptzOID, Name: "timestamptz"} TimestamptzArray = ArrayType{ID: pgtype.TimestamptzArrayOID, Name: "_timestamptz"} Interval = BaseType{ID: pgtype.IntervalOID, Name: "interval"} NumericArray = ArrayType{ID: pgtype.NumericArrayOID, Name: "_numeric"} Bit = BaseType{ID: pgtype.BitOID, Name: "bit"} Varbit = BaseType{ID: pgtype.VarbitOID, Name: "varbit"} Numeric = BaseType{ID: pgtype.NumericOID, Name: "numeric"} Record = BaseType{ID: pgtype.RecordOID, Name: "record"} Void = VoidType{} UUID = BaseType{ID: pgtype.UUIDOID, Name: "uuid"} UUIDArray = ArrayType{ID: pgtype.UUIDArrayOID, Name: "_uuid"} JSONB = BaseType{ID: pgtype.JSONBOID, Name: "jsonb"} JSONBArray = ArrayType{ID: pgtype.JSONBArrayOID, Name: "_jsonb"} Int4range = BaseType{ID: pgtype.Int4rangeOID, Name: "int4range"} Numrange = BaseType{ID: pgtype.NumrangeOID, Name: "numrange"} Tsrange = BaseType{ID: pgtype.TsrangeOID, Name: "tsrange"} Tstzrange = BaseType{ID: pgtype.TstzrangeOID, Name: "tstzrange"} Daterange = BaseType{ID: pgtype.DaterangeOID, Name: "daterange"} Int8range = BaseType{ID: pgtype.Int8rangeOID, Name: "int8range"} )
If you add to this list, also add to defaultKnownTypes below.
Functions ¶
This section is empty.
Types ¶
type ArrayType ¶
type ArrayType struct {
ID uint32 // pg_type.oid: row identifier
// The name of the type, like _int4. Array types in Postgres typically
// begin with an underscore. From pg_type.typname.
Name string
// pg_type.typelem: the element type of the array
Elem Type
}
ArrayType is an array type where pg_type.typelem != 0 and the name begins with an underscore.
type BaseType ¶
type BaseType struct {
ID uint32 // pg_type.oid: row identifier
Name string // pg_type.typname: data type name
}
BaseType is a fundamental Postgres type like text and bool. https://www.postgresql.org/docs/13/catalog-pg-type.html
type Column ¶
type Column struct {
Name string // pg_attribute.attname: column name
TableOID uint32 // pg_attribute:attrelid: table the column belongs to
TableName string // pg_class.relname: name of table that owns the column
Number uint16 // pg_attribute.attnum: the number of column starting from 1
Type Type // pg_attribute.atttypid: data type of the column
Null bool // pg_attribute.attnotnull: represents a not-null constraint
}
Column stores information about a column in a TableOID. https://www.postgresql.org/docs/13/catalog-pg-attribute.html
type ColumnKey ¶
ColumnKey is a composite key of a table OID and the number of the column within the table.
type CompositeType ¶
type CompositeType struct {
ID uint32 // pg_class.oid: row identifier
Name string // pg_class.relname: name of the composite type
ColumnNames []string // pg_attribute.attname: names of the column, in order
ColumnTypes []Type // pg_attribute JOIN pg_type: information about columns of the composite type
}
CompositeType is a type containing multiple columns and is represented as a class. https://www.postgresql.org/docs/13/catalog-pg-class.html
func (CompositeType) Kind ¶
func (e CompositeType) Kind() TypeKind
func (CompositeType) OID ¶
func (e CompositeType) OID() uint32
func (CompositeType) String ¶
func (e CompositeType) String() string
type DBQuerier ¶
type DBQuerier struct {
// contains filtered or unexported fields
}
func NewQuerier ¶
NewQuerier creates a DBQuerier that implements Querier.
func (*DBQuerier) FindArrayTypes ¶
FindArrayTypes implements Querier.FindArrayTypes.
func (*DBQuerier) FindCompositeTypes ¶
func (q *DBQuerier) FindCompositeTypes(ctx context.Context, oids []uint32) ([]FindCompositeTypesRow, error)
FindCompositeTypes implements Querier.FindCompositeTypes.
func (*DBQuerier) FindDescendantOIDs ¶
FindDescendantOIDs implements Querier.FindDescendantOIDs.
func (*DBQuerier) FindEnumTypes ¶
FindEnumTypes implements Querier.FindEnumTypes.
func (*DBQuerier) FindOIDByName ¶
FindOIDByName implements Querier.FindOIDByName.
func (*DBQuerier) FindOIDName ¶
FindOIDName implements Querier.FindOIDName.
func (*DBQuerier) FindOIDNames ¶
FindOIDNames implements Querier.FindOIDNames.
type DebugCodec ¶ added in v1.1.0
type DebugCodec struct {
}
func (*DebugCodec) DecodeDatabaseSQLValue ¶ added in v1.1.0
func (d *DebugCodec) DecodeDatabaseSQLValue(m *pgtype.Map, oid uint32, format int16, src []byte) (driver.Value, error)
DecodeDatabaseSQLValue implements pgtype.Codec.
func (*DebugCodec) DecodeValue ¶ added in v1.1.0
DecodeValue implements pgtype.Codec.
func (*DebugCodec) FormatSupported ¶ added in v1.1.0
func (d *DebugCodec) FormatSupported(int16) bool
FormatSupported implements pgtype.Codec.
func (*DebugCodec) PlanEncode ¶ added in v1.1.0
func (d *DebugCodec) PlanEncode(m *pgtype.Map, oid uint32, format int16, value any) pgtype.EncodePlan
PlanEncode implements pgtype.Codec.
func (*DebugCodec) PreferredFormat ¶ added in v1.1.0
func (d *DebugCodec) PreferredFormat() int16
PreferredFormat implements pgtype.Codec.
type DomainType ¶
type DomainType struct {
ID uint32 // pg_type.oid: row identifier
Name string // pg_type.typname: data type name
IsNotNull bool // pg_type.typnotnull: domains only, not null constraint for domains
HasDefault bool // pg_type.typdefault: domains only, if there's a default value
BaseType BaseType // pg_type.typbasetype: domains only, the base type
Dimensions int // pg_type.typndims: domains on array type only, 0 otherwise, number of array dimensions
}
DomainType is a user-create domain type.
func (DomainType) Kind ¶
func (e DomainType) Kind() TypeKind
func (DomainType) OID ¶
func (e DomainType) OID() uint32
func (DomainType) String ¶
func (e DomainType) String() string
type EnumType ¶
type EnumType struct {
ID uint32 // pg_type.oid: row identifier
// The name of the enum, like 'device_type' in:
// CREATE TYPE device_type AS ENUM ('foo');
// From pg_type.typname.
Name string
// All textual labels for this enum in sort order.
Labels []string
// When an enum type is created, its members are assigned sort-order
// positions 1...n. But members added later might be given negative or
// fractional values of enumsortorder. The only requirement on these
// values is that they be correctly ordered and unique within each enum
// type.
Orders []float32
ChildOIDs []uint32
}
type FindArrayTypesRow ¶
type FindCompositeTypesRow ¶
type FindCompositeTypesRow struct {
TableTypeName string `json:"table_type_name"`
TableTypeOID uint32 `json:"table_type_oid"`
TableName string `json:"table_name"`
ColNames []string `json:"col_names"`
ColOIDs []int `json:"col_oids"`
ColOrders []int `json:"col_orders"`
ColNotNulls []bool `json:"col_not_nulls"`
ColTypeNames []string `json:"col_type_names"`
}
type FindEnumTypesRow ¶
type FindOIDNamesRow ¶
type Querier ¶
type Querier interface {
FindEnumTypes(ctx context.Context, oids []uint32) ([]FindEnumTypesRow, error)
FindArrayTypes(ctx context.Context, oids []uint32) ([]FindArrayTypesRow, error)
// A composite type represents a row or record, defined implicitly for each
// table, or explicitly with CREATE TYPE.
// https://www.postgresql.org/docs/13/rowtypes.html
FindCompositeTypes(ctx context.Context, oids []uint32) ([]FindCompositeTypesRow, error)
// Recursively expands all given OIDs to all descendants through composite
// types.
FindDescendantOIDs(ctx context.Context, oids []uint32) ([]uint32, error)
FindOIDByName(ctx context.Context, name string) (uint32, error)
FindOIDName(ctx context.Context, oid uint32) (string, error)
FindOIDNames(ctx context.Context, oid []uint32) ([]FindOIDNamesRow, error)
}
Querier is a typesafe Go interface backed by SQL queries.
type Type ¶
type Type interface {
OID() uint32 // pg_type.oid: row identifier
String() string // pg_type.typname: data type name
Kind() TypeKind
}
Type is a Postgres type.
type TypeFetcher ¶
type TypeFetcher struct {
// contains filtered or unexported fields
}
TypeFetcher fetches Postgres types by the OID.
func NewTypeFetcher ¶
func (*TypeFetcher) FindTypesByOIDs ¶
func (tf *TypeFetcher) FindTypesByOIDs(oids ...uint32) (map[uint32]Type, error)
FindTypesByOIDs returns a map of a type OID to the Type description. The returned map contains every unique OID in oids (oids may contain duplicates) unless there's an error.
type TypeKind ¶
type TypeKind byte
TypeKind is the pg_type.typtype column, describing the meta type of Type.
type UnknownType ¶
type UnknownType struct {
ID uint32 // pg_type.oid: row identifier
Name string // pg_type.typname: data type name
PgKind TypeKind
}
UnknownType is a Postgres type that's not a well-known type in defaultKnownTypes, and not an enum, domain, or composite type. The code generator might be able to resolve this type from a user-provided mapping like --go-type my_int=int.
func (UnknownType) Kind ¶
func (e UnknownType) Kind() TypeKind
func (UnknownType) OID ¶
func (e UnknownType) OID() uint32
func (UnknownType) String ¶
func (e UnknownType) String() string