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) FindArrayTypesBatch(batch genericBatch, oids []uint32)
- func (q *DBQuerier) FindArrayTypesScan(results pgx.BatchResults) ([]FindArrayTypesRow, error)
- func (q *DBQuerier) FindCompositeTypes(ctx context.Context, oids []uint32) ([]FindCompositeTypesRow, error)
- func (q *DBQuerier) FindCompositeTypesBatch(batch genericBatch, oids []uint32)
- func (q *DBQuerier) FindCompositeTypesScan(results pgx.BatchResults) ([]FindCompositeTypesRow, error)
- func (q *DBQuerier) FindDescendantOIDs(ctx context.Context, oids []uint32) ([]pgtype.OID, error)
- func (q *DBQuerier) FindDescendantOIDsBatch(batch genericBatch, oids []uint32)
- func (q *DBQuerier) FindDescendantOIDsScan(results pgx.BatchResults) ([]pgtype.OID, error)
- func (q *DBQuerier) FindEnumTypes(ctx context.Context, oids []uint32) ([]FindEnumTypesRow, error)
- func (q *DBQuerier) FindEnumTypesBatch(batch genericBatch, oids []uint32)
- func (q *DBQuerier) FindEnumTypesScan(results pgx.BatchResults) ([]FindEnumTypesRow, error)
- func (q *DBQuerier) FindOIDByName(ctx context.Context, name string) (pgtype.OID, error)
- func (q *DBQuerier) FindOIDByNameBatch(batch genericBatch, name string)
- func (q *DBQuerier) FindOIDByNameScan(results pgx.BatchResults) (pgtype.OID, error)
- func (q *DBQuerier) FindOIDName(ctx context.Context, oid pgtype.OID) (pgtype.Name, error)
- func (q *DBQuerier) FindOIDNameBatch(batch genericBatch, oid pgtype.OID)
- func (q *DBQuerier) FindOIDNameScan(results pgx.BatchResults) (pgtype.Name, error)
- func (q *DBQuerier) FindOIDNames(ctx context.Context, oid []uint32) ([]FindOIDNamesRow, error)
- func (q *DBQuerier) FindOIDNamesBatch(batch genericBatch, oid []uint32)
- func (q *DBQuerier) FindOIDNamesScan(results pgx.BatchResults) ([]FindOIDNamesRow, error)
- 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 pgtype.OID // 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 pgtype.OID // 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 pgtype.OID // 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
func FetchColumns ¶
FetchColumns fetches meta information about a Postgres column from the pg_class and pg_attribute catalog tables.
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 pgtype.OID // 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() pgtype.OID
func (CompositeType) String ¶
func (e CompositeType) String() string
type DBQuerier ¶
type DBQuerier struct {
// contains filtered or unexported fields
}
func NewQuerier ¶
func NewQuerier(conn genericConn) *DBQuerier
NewQuerier creates a DBQuerier that implements Querier. conn is typically *pgx.Conn, pgx.Tx, or *pgxpool.Pool.
func (*DBQuerier) FindArrayTypes ¶
FindArrayTypes implements Querier.FindArrayTypes.
func (*DBQuerier) FindArrayTypesBatch ¶
FindArrayTypesBatch implements Querier.FindArrayTypesBatch.
func (*DBQuerier) FindArrayTypesScan ¶
func (q *DBQuerier) FindArrayTypesScan(results pgx.BatchResults) ([]FindArrayTypesRow, error)
FindArrayTypesScan implements Querier.FindArrayTypesScan.
func (*DBQuerier) FindCompositeTypes ¶
func (q *DBQuerier) FindCompositeTypes(ctx context.Context, oids []uint32) ([]FindCompositeTypesRow, error)
FindCompositeTypes implements Querier.FindCompositeTypes.
func (*DBQuerier) FindCompositeTypesBatch ¶
FindCompositeTypesBatch implements Querier.FindCompositeTypesBatch.
func (*DBQuerier) FindCompositeTypesScan ¶
func (q *DBQuerier) FindCompositeTypesScan(results pgx.BatchResults) ([]FindCompositeTypesRow, error)
FindCompositeTypesScan implements Querier.FindCompositeTypesScan.
func (*DBQuerier) FindDescendantOIDs ¶
FindDescendantOIDs implements Querier.FindDescendantOIDs.
func (*DBQuerier) FindDescendantOIDsBatch ¶
FindDescendantOIDsBatch implements Querier.FindDescendantOIDsBatch.
func (*DBQuerier) FindDescendantOIDsScan ¶
FindDescendantOIDsScan implements Querier.FindDescendantOIDsScan.
func (*DBQuerier) FindEnumTypes ¶
FindEnumTypes implements Querier.FindEnumTypes.
func (*DBQuerier) FindEnumTypesBatch ¶
FindEnumTypesBatch implements Querier.FindEnumTypesBatch.
func (*DBQuerier) FindEnumTypesScan ¶
func (q *DBQuerier) FindEnumTypesScan(results pgx.BatchResults) ([]FindEnumTypesRow, error)
FindEnumTypesScan implements Querier.FindEnumTypesScan.
func (*DBQuerier) FindOIDByName ¶
FindOIDByName implements Querier.FindOIDByName.
func (*DBQuerier) FindOIDByNameBatch ¶
FindOIDByNameBatch implements Querier.FindOIDByNameBatch.
func (*DBQuerier) FindOIDByNameScan ¶
FindOIDByNameScan implements Querier.FindOIDByNameScan.
func (*DBQuerier) FindOIDName ¶
FindOIDName implements Querier.FindOIDName.
func (*DBQuerier) FindOIDNameBatch ¶
FindOIDNameBatch implements Querier.FindOIDNameBatch.
func (*DBQuerier) FindOIDNameScan ¶
FindOIDNameScan implements Querier.FindOIDNameScan.
func (*DBQuerier) FindOIDNames ¶
FindOIDNames implements Querier.FindOIDNames.
func (*DBQuerier) FindOIDNamesBatch ¶
FindOIDNamesBatch implements Querier.FindOIDNamesBatch.
func (*DBQuerier) FindOIDNamesScan ¶
func (q *DBQuerier) FindOIDNamesScan(results pgx.BatchResults) ([]FindOIDNamesRow, error)
FindOIDNamesScan implements Querier.FindOIDNamesScan.
type DomainType ¶
type DomainType struct { ID pgtype.OID // 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() pgtype.OID
func (DomainType) String ¶
func (e DomainType) String() string
type EnumType ¶
type EnumType struct { ID pgtype.OID // 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 []pgtype.OID }
type FindArrayTypesRow ¶
type FindCompositeTypesRow ¶
type FindCompositeTypesRow struct { TableTypeName string `json:"table_type_name"` TableTypeOID pgtype.OID `json:"table_type_oid"` TableName pgtype.Name `json:"table_name"` ColNames []string `json:"col_names"` ColOIDs []int `json:"col_oids"` ColOrders []int `json:"col_orders"` ColNotNulls pgtype.BoolArray `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) // FindEnumTypesBatch enqueues a FindEnumTypes query into batch to be executed // later by the batch. FindEnumTypesBatch(batch genericBatch, oids []uint32) // FindEnumTypesScan scans the result of an executed FindEnumTypesBatch query. FindEnumTypesScan(results pgx.BatchResults) ([]FindEnumTypesRow, error) FindArrayTypes(ctx context.Context, oids []uint32) ([]FindArrayTypesRow, error) // FindArrayTypesBatch enqueues a FindArrayTypes query into batch to be executed // later by the batch. FindArrayTypesBatch(batch genericBatch, oids []uint32) // FindArrayTypesScan scans the result of an executed FindArrayTypesBatch query. FindArrayTypesScan(results pgx.BatchResults) ([]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) // FindCompositeTypesBatch enqueues a FindCompositeTypes query into batch to be executed // later by the batch. FindCompositeTypesBatch(batch genericBatch, oids []uint32) // FindCompositeTypesScan scans the result of an executed FindCompositeTypesBatch query. FindCompositeTypesScan(results pgx.BatchResults) ([]FindCompositeTypesRow, error) // Recursively expands all given OIDs to all descendants through composite // types. FindDescendantOIDs(ctx context.Context, oids []uint32) ([]pgtype.OID, error) // FindDescendantOIDsBatch enqueues a FindDescendantOIDs query into batch to be executed // later by the batch. FindDescendantOIDsBatch(batch genericBatch, oids []uint32) // FindDescendantOIDsScan scans the result of an executed FindDescendantOIDsBatch query. FindDescendantOIDsScan(results pgx.BatchResults) ([]pgtype.OID, error) FindOIDByName(ctx context.Context, name string) (pgtype.OID, error) // FindOIDByNameBatch enqueues a FindOIDByName query into batch to be executed // later by the batch. FindOIDByNameBatch(batch genericBatch, name string) // FindOIDByNameScan scans the result of an executed FindOIDByNameBatch query. FindOIDByNameScan(results pgx.BatchResults) (pgtype.OID, error) FindOIDName(ctx context.Context, oid pgtype.OID) (pgtype.Name, error) // FindOIDNameBatch enqueues a FindOIDName query into batch to be executed // later by the batch. FindOIDNameBatch(batch genericBatch, oid pgtype.OID) // FindOIDNameScan scans the result of an executed FindOIDNameBatch query. FindOIDNameScan(results pgx.BatchResults) (pgtype.Name, error) FindOIDNames(ctx context.Context, oid []uint32) ([]FindOIDNamesRow, error) // FindOIDNamesBatch enqueues a FindOIDNames query into batch to be executed // later by the batch. FindOIDNamesBatch(batch genericBatch, oid []uint32) // FindOIDNamesScan scans the result of an executed FindOIDNamesBatch query. FindOIDNamesScan(results pgx.BatchResults) ([]FindOIDNamesRow, error) }
Querier is a typesafe Go interface backed by SQL queries.
Methods ending with Batch enqueue a query to run later in a pgx.Batch. After calling SendBatch on pgx.Conn, pgxpool.Pool, or pgx.Tx, use the Scan methods to parse the results.
type Type ¶
type Type interface { OID() pgtype.OID // 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 NewTypeFetcher(conn *pgx.Conn) *TypeFetcher
func (*TypeFetcher) FindTypesByOIDs ¶
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 pgtype.OID // 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() pgtype.OID
func (UnknownType) String ¶
func (e UnknownType) String() string