pg

package
v0.0.0-...-3259c9a Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

func (ArrayType) Kind

func (b ArrayType) Kind() TypeKind

func (ArrayType) OID

func (b ArrayType) OID() pgtype.OID

func (ArrayType) String

func (b ArrayType) String() string

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

func (BaseType) Kind

func (b BaseType) Kind() TypeKind

func (BaseType) OID

func (b BaseType) OID() pgtype.OID

func (BaseType) String

func (b BaseType) String() string

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

func FetchColumns(conn *pgx.Conn, keys []ColumnKey) ([]Column, error)

FetchColumns fetches meta information about a Postgres column from the pg_class and pg_attribute catalog tables.

type ColumnKey

type ColumnKey struct {
	TableOID pgtype.OID
	Number   uint16 // the number of column starting from 1
}

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.

func (*DBQuerier) FindArrayTypes

func (q *DBQuerier) FindArrayTypes(ctx context.Context, oids []uint32) ([]FindArrayTypesRow, error)

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

func (q *DBQuerier) FindDescendantOIDs(ctx context.Context, oids []uint32) ([]pgtype.OID, error)

FindDescendantOIDs implements Querier.FindDescendantOIDs.

func (*DBQuerier) FindEnumTypes

func (q *DBQuerier) FindEnumTypes(ctx context.Context, oids []uint32) ([]FindEnumTypesRow, error)

FindEnumTypes implements Querier.FindEnumTypes.

func (*DBQuerier) FindOIDByName

func (q *DBQuerier) FindOIDByName(ctx context.Context, name string) (pgtype.OID, error)

FindOIDByName implements Querier.FindOIDByName.

func (*DBQuerier) FindOIDName

func (q *DBQuerier) FindOIDName(ctx context.Context, oid pgtype.OID) (pgtype.Name, error)

FindOIDName implements Querier.FindOIDName.

func (*DBQuerier) FindOIDNames

func (q *DBQuerier) FindOIDNames(ctx context.Context, oid []uint32) ([]FindOIDNamesRow, error)

FindOIDNames implements Querier.FindOIDNames.

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
}

func (EnumType) Kind

func (e EnumType) Kind() TypeKind

func (EnumType) OID

func (e EnumType) OID() pgtype.OID

func (EnumType) String

func (e EnumType) String() string

type FindArrayTypesRow

type FindArrayTypesRow struct {
	OID      pgtype.OID   `json:"oid"`
	TypeName string       `json:"type_name"`
	ElemOID  pgtype.OID   `json:"elem_oid"`
	TypeKind pgtype.QChar `json:"type_kind"`
}

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 FindEnumTypesRow struct {
	OID         pgtype.OID   `json:"oid"`
	TypeName    string       `json:"type_name"`
	ChildOIDs   []int        `json:"child_oids"`
	Orders      []float32    `json:"orders"`
	Labels      []string     `json:"labels"`
	TypeKind    pgtype.QChar `json:"type_kind"`
	DefaultExpr string       `json:"default_expr"`
}

type FindOIDNamesRow

type FindOIDNamesRow struct {
	OID  pgtype.OID   `json:"oid"`
	Name pgtype.Name  `json:"name"`
	Kind pgtype.QChar `json:"kind"`
}

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) ([]pgtype.OID, error)

	FindOIDByName(ctx context.Context, name string) (pgtype.OID, error)

	FindOIDName(ctx context.Context, oid pgtype.OID) (pgtype.Name, 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() 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

func (tf *TypeFetcher) FindTypesByOIDs(oids ...uint32) (map[pgtype.OID]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.

const (
	KindBaseType      TypeKind = 'b' // includes array types
	KindCompositeType TypeKind = 'c'
	KindDomainType    TypeKind = 'd'
	KindEnumType      TypeKind = 'e'
	KindPseudoType    TypeKind = 'p'
	KindRangeType     TypeKind = 'r'
)

func (TypeKind) String

func (k TypeKind) String() string

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

type VoidType

type VoidType struct{}

VoidType is an empty type. A void type doesn't appear in output, but it's necessary to scan rows.

func (VoidType) Kind

func (b VoidType) Kind() TypeKind

func (VoidType) OID

func (b VoidType) OID() pgtype.OID

func (VoidType) String

func (b VoidType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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