PostgreSQL oids for common types
const ( BoolOID = 16 ByteaOID = 17 QCharOID = 18 NameOID = 19 Int8OID = 20 Int2OID = 21 Int4OID = 23 TextOID = 25 OIDOID = 26 TIDOID = 27 XIDOID = 28 CIDOID = 29 JSONOID = 114 JSONArrayOID = 199 PointOID = 600 LsegOID = 601 PathOID = 602 BoxOID = 603 PolygonOID = 604 LineOID = 628 LineArrayOID = 629 CIDROID = 650 CIDRArrayOID = 651 Float4OID = 700 Float8OID = 701 CircleOID = 718 CircleArrayOID = 719 UnknownOID = 705 MacaddrOID = 829 InetOID = 869 BoolArrayOID = 1000 QCharArrayOID = 1002 NameArrayOID = 1003 Int2ArrayOID = 1005 Int4ArrayOID = 1007 TextArrayOID = 1009 TIDArrayOID = 1010 ByteaArrayOID = 1001 XIDArrayOID = 1011 CIDArrayOID = 1012 BPCharArrayOID = 1014 VarcharArrayOID = 1015 Int8ArrayOID = 1016 PointArrayOID = 1017 LsegArrayOID = 1018 PathArrayOID = 1019 BoxArrayOID = 1020 Float4ArrayOID = 1021 Float8ArrayOID = 1022 PolygonArrayOID = 1027 OIDArrayOID = 1028 ACLItemOID = 1033 ACLItemArrayOID = 1034 MacaddrArrayOID = 1040 InetArrayOID = 1041 BPCharOID = 1042 VarcharOID = 1043 DateOID = 1082 TimeOID = 1083 TimestampOID = 1114 TimestampArrayOID = 1115 DateArrayOID = 1182 TimeArrayOID = 1183 TimestamptzOID = 1184 TimestamptzArrayOID = 1185 IntervalOID = 1186 IntervalArrayOID = 1187 NumericArrayOID = 1231 TimetzOID = 1266 TimetzArrayOID = 1270 BitOID = 1560 BitArrayOID = 1561 VarbitOID = 1562 VarbitArrayOID = 1563 NumericOID = 1700 RecordOID = 2249 RecordArrayOID = 2287 UUIDOID = 2950 UUIDArrayOID = 2951 JSONBOID = 3802 JSONBArrayOID = 3807 DaterangeOID = 3912 DaterangeArrayOID = 3913 Int4rangeOID = 3904 Int4rangeArrayOID = 3905 NumrangeOID = 3906 NumrangeArrayOID = 3907 TsrangeOID = 3908 TsrangeArrayOID = 3909 TstzrangeOID = 3910 TstzrangeArrayOID = 3911 Int8rangeOID = 3926 Int8rangeArrayOID = 3927 JSONPathOID = 4072 JSONPathArrayOID = 4073 Int4multirangeOID = 4451 NummultirangeOID = 4532 TsmultirangeOID = 4533 TstzmultirangeOID = 4534 DatemultirangeOID = 4535 Int8multirangeOID = 4536 Int4multirangeArrayOID = 6150 NummultirangeArrayOID = 6151 TsmultirangeArrayOID = 6152 TstzmultirangeArrayOID = 6153 DatemultirangeArrayOID = 6155 Int8multirangeArrayOID = 6157 )
PostgreSQL format codes
const ( TextFormatCode = 0 BinaryFormatCode = 1 )
const ( Inclusive = BoundType('i') Exclusive = BoundType('e') Unbounded = BoundType('U') Empty = BoundType('E') )
var ErrScanTargetTypeChanged = errors.New("scan target type changed")
func GetAssignToDstType(dst any) (any, bool)
GetAssignToDstType attempts to convert dst to something AssignTo can assign to. If dst is a pointer to pointer it allocates a value and returns the dereferences pointer. If dst is a named type such as *Foo where Foo is type Foo int16, it converts dst to *int16.
GetAssignToDstType returns the converted dst and a bool representing if any change was made.
func NullAssignTo(dst any) error
Array represents a PostgreSQL array for T. It implements the ArrayGetter and ArraySetter interfaces. It preserves PostgreSQL dimensions and custom lower bounds. Use FlatArray if these are not needed.
type Array[T any] struct { Elements []T Dims []ArrayDimension Valid bool }
func (a Array[T]) Dimensions() []ArrayDimension
func (a Array[T]) Index(i int) any
func (a Array[T]) IndexType() any
func (a Array[T]) ScanIndex(i int) any
func (a Array[T]) ScanIndexType() any
func (a *Array[T]) SetDimensions(dimensions []ArrayDimension) error
ArrayCodec is a codec for any array type.
type ArrayCodec struct { ElementType *Type }
func (c *ArrayCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c *ArrayCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (c *ArrayCodec) FormatSupported(format int16) bool
func (c *ArrayCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (c *ArrayCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (c *ArrayCodec) PreferredFormat() int16
type ArrayDimension struct { Length int32 LowerBound int32 }
ArrayGetter is a type that can be converted into a PostgreSQL array.
type ArrayGetter interface { // Dimensions returns the array dimensions. If array is nil then nil is returned. Dimensions() []ArrayDimension // Index returns the element at i. Index(i int) any // IndexType returns a non-nil scan target of the type Index will return. This is used by ArrayCodec.PlanEncode. IndexType() any }
ArraySetter is a type can be set from a PostgreSQL array.
type ArraySetter interface { // SetDimensions prepares the value such that ScanIndex can be called for each element. This will remove any existing // elements. dimensions may be nil to indicate a NULL array. If unable to exactly preserve dimensions SetDimensions // may return an error or silently flatten the array dimensions. SetDimensions(dimensions []ArrayDimension) error // ScanIndex returns a value usable as a scan target for i. SetDimensions must be called before ScanIndex. ScanIndex(i int) any // ScanIndexType returns a non-nil scan target of the type ScanIndex will return. This is used by // ArrayCodec.PlanScan. ScanIndexType() any }
Bits represents the PostgreSQL bit and varbit types.
type Bits struct { Bytes []byte Len int32 // Number of bits Valid bool }
func (b Bits) BitsValue() (Bits, error)
func (dst *Bits) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (b *Bits) ScanBits(v Bits) error
func (src Bits) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type BitsCodec struct{}
func (c BitsCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c BitsCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (BitsCodec) FormatSupported(format int16) bool
func (BitsCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (BitsCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (BitsCodec) PreferredFormat() int16
type BitsScanner interface { ScanBits(v Bits) error }
type BitsValuer interface { BitsValue() (Bits, error) }
type Bool struct { Bool bool Valid bool }
func (b Bool) BoolValue() (Bool, error)
func (src Bool) MarshalJSON() ([]byte, error)
func (dst *Bool) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (b *Bool) ScanBool(v Bool) error
func (dst *Bool) UnmarshalJSON(b []byte) error
func (src Bool) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type BoolCodec struct{}
func (c BoolCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c BoolCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (BoolCodec) FormatSupported(format int16) bool
func (BoolCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (BoolCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (BoolCodec) PreferredFormat() int16
type BoolScanner interface { ScanBool(v Bool) error }
type BoolValuer interface { BoolValue() (Bool, error) }
type BoundType byte
func (bt BoundType) String() string
type Box struct { P [2]Vec2 Valid bool }
func (b Box) BoxValue() (Box, error)
func (dst *Box) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (b *Box) ScanBox(v Box) error
func (src Box) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type BoxCodec struct{}
func (c BoxCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c BoxCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (BoxCodec) FormatSupported(format int16) bool
func (BoxCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (BoxCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (BoxCodec) PreferredFormat() int16
type BoxScanner interface { ScanBox(v Box) error }
type BoxValuer interface { BoxValue() (Box, error) }
type ByteaCodec struct{}
func (c ByteaCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c ByteaCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (ByteaCodec) FormatSupported(format int16) bool
func (ByteaCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (ByteaCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (ByteaCodec) PreferredFormat() int16
type BytesScanner interface { // ScanBytes receives a byte slice of driver memory that is only valid until the next database method call. ScanBytes(v []byte) error }
type BytesValuer interface { // BytesValue returns a byte slice of the byte data. The caller must not change the returned slice. BytesValue() ([]byte, error) }
type Circle struct { P Vec2 R float64 Valid bool }
func (c Circle) CircleValue() (Circle, error)
func (dst *Circle) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (c *Circle) ScanCircle(v Circle) error
func (src Circle) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type CircleCodec struct{}
func (c CircleCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c CircleCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (CircleCodec) FormatSupported(format int16) bool
func (CircleCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (CircleCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (CircleCodec) PreferredFormat() int16
type CircleScanner interface { ScanCircle(v Circle) error }
type CircleValuer interface { CircleValue() (Circle, error) }
A Codec converts between Go and PostgreSQL values. A Codec must not be mutated after it is registered with a Map.
type Codec interface { // FormatSupported returns true if the format is supported. FormatSupported(int16) bool // PreferredFormat returns the preferred format. PreferredFormat() int16 // PlanEncode returns an EncodePlan for encoding value into PostgreSQL format for oid and format. If no plan can be // found then nil is returned. PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan // PlanScan returns a ScanPlan for scanning a PostgreSQL value into a destination with the same type as target. If // no plan can be found then nil is returned. PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan // DecodeDatabaseSQLValue returns src decoded into a value compatible with the sql.Scanner interface. DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) // DecodeValue returns src decoded into its default format. DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error) }
type CompositeBinaryBuilder struct {
// contains filtered or unexported fields
}
func NewCompositeBinaryBuilder(m *Map, buf []byte) *CompositeBinaryBuilder
func (b *CompositeBinaryBuilder) AppendValue(oid uint32, field any)
func (b *CompositeBinaryBuilder) Finish() ([]byte, error)
type CompositeBinaryScanner struct {
// contains filtered or unexported fields
}
func NewCompositeBinaryScanner(m *Map, src []byte) *CompositeBinaryScanner
NewCompositeBinaryScanner a scanner over a binary encoded composite balue.
func (cfs *CompositeBinaryScanner) Bytes() []byte
Bytes returns the bytes of the field most recently read by Scan().
func (cfs *CompositeBinaryScanner) Err() error
Err returns any error encountered by the scanner.
func (cfs *CompositeBinaryScanner) FieldCount() int
func (cfs *CompositeBinaryScanner) Next() bool
Next advances the scanner to the next field. It returns false after the last field is read or an error occurs. After Next returns false, the Err method can be called to check if any errors occurred.
func (cfs *CompositeBinaryScanner) OID() uint32
OID returns the OID of the field most recently read by Scan().
type CompositeCodec struct { Fields []CompositeCodecField }
func (c *CompositeCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c *CompositeCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (c *CompositeCodec) FormatSupported(format int16) bool
func (c *CompositeCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (c *CompositeCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (c *CompositeCodec) PreferredFormat() int16
type CompositeCodecField struct { Name string Type *Type }
CompositeFields represents the values of a composite value. It can be used as an encoding source or as a scan target. It cannot scan a NULL, but the composite fields can be NULL.
type CompositeFields []any
func (cf CompositeFields) Index(i int) any
func (cf CompositeFields) IsNull() bool
func (cf CompositeFields) ScanIndex(i int) any
func (cf CompositeFields) ScanNull() error
func (cf CompositeFields) SkipUnderlyingTypePlan()
CompositeIndexGetter is a type accessed by index that can be converted into a PostgreSQL composite.
type CompositeIndexGetter interface { // IsNull returns true if the value is SQL NULL. IsNull() bool // Index returns the element at i. Index(i int) any }
CompositeIndexScanner is a type accessed by index that can be scanned from a PostgreSQL composite.
type CompositeIndexScanner interface { // ScanNull sets the value to SQL NULL. ScanNull() error // ScanIndex returns a value usable as a scan target for i. ScanIndex(i int) any }
type CompositeTextBuilder struct {
// contains filtered or unexported fields
}
func NewCompositeTextBuilder(m *Map, buf []byte) *CompositeTextBuilder
func (b *CompositeTextBuilder) AppendValue(oid uint32, field any)
func (b *CompositeTextBuilder) Finish() ([]byte, error)
type CompositeTextScanner struct {
// contains filtered or unexported fields
}
func NewCompositeTextScanner(m *Map, src []byte) *CompositeTextScanner
NewCompositeTextScanner a scanner over a text encoded composite value.
func (cfs *CompositeTextScanner) Bytes() []byte
Bytes returns the bytes of the field most recently read by Scan().
func (cfs *CompositeTextScanner) Err() error
Err returns any error encountered by the scanner.
func (cfs *CompositeTextScanner) Next() bool
Next advances the scanner to the next field. It returns false after the last field is read or an error occurs. After Next returns false, the Err method can be called to check if any errors occurred.
type Date struct { Time time.Time InfinityModifier InfinityModifier Valid bool }
func (d Date) DateValue() (Date, error)
func (src Date) MarshalJSON() ([]byte, error)
func (dst *Date) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (d *Date) ScanDate(v Date) error
func (dst *Date) UnmarshalJSON(b []byte) error
func (src Date) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type DateCodec struct{}
func (c DateCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c DateCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (DateCodec) FormatSupported(format int16) bool
func (DateCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (DateCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (DateCodec) PreferredFormat() int16
type DateScanner interface { ScanDate(v Date) error }
type DateValuer interface { DateValue() (Date, error) }
DriverBytes is a byte slice that holds a reference to memory owned by the driver. It is only valid from the time it is scanned until Rows.Next or Rows.Close is called. It is never safe to use DriverBytes with QueryRow as Row.Scan internally calls Rows.Close before returning.
type DriverBytes []byte
func (b *DriverBytes) ScanBytes(v []byte) error
EncodePlan is a precompiled plan to encode a particular type into a particular OID and format.
type EncodePlan interface { // Encode appends the encoded bytes of value to buf. If value is the SQL value NULL then append nothing and return // (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data // written. Encode(value any, buf []byte) (newBuf []byte, err error) }
EnumCodec is a codec that caches the strings it decodes. If the same string is read multiple times only one copy is allocated. These strings are only garbage collected when the EnumCodec is garbage collected. EnumCodec can be used for any text type not only enums, but it should only be used when there are a small number of possible values.
type EnumCodec struct {
// contains filtered or unexported fields
}
func (c *EnumCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c *EnumCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (EnumCodec) FormatSupported(format int16) bool
func (EnumCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (c *EnumCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (EnumCodec) PreferredFormat() int16
FlatArray implements the ArrayGetter and ArraySetter interfaces for any slice of T. It ignores PostgreSQL dimensions and custom lower bounds. Use Array to preserve these.
type FlatArray[T any] []T
func (a FlatArray[T]) Dimensions() []ArrayDimension
func (a FlatArray[T]) Index(i int) any
func (a FlatArray[T]) IndexType() any
func (a FlatArray[T]) ScanIndex(i int) any
func (a FlatArray[T]) ScanIndexType() any
func (a *FlatArray[T]) SetDimensions(dimensions []ArrayDimension) error
type Float4 struct { Float32 float32 Valid bool }
func (f Float4) Float64Value() (Float8, error)
func (f Float4) Int64Value() (Int8, error)
func (f Float4) MarshalJSON() ([]byte, error)
func (f *Float4) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (f *Float4) ScanFloat64(n Float8) error
ScanFloat64 implements the Float64Scanner interface.
func (f *Float4) ScanInt64(n Int8) error
func (f *Float4) UnmarshalJSON(b []byte) error
func (f Float4) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Float4Codec struct{}
func (c Float4Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c Float4Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (Float4Codec) FormatSupported(format int16) bool
func (Float4Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Float4Codec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (Float4Codec) PreferredFormat() int16
type Float64Scanner interface { ScanFloat64(Float8) error }
type Float64Valuer interface { Float64Value() (Float8, error) }
type Float8 struct { Float64 float64 Valid bool }
func (f Float8) Float64Value() (Float8, error)
func (f Float8) Int64Value() (Int8, error)
func (f Float8) MarshalJSON() ([]byte, error)
func (f *Float8) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (f *Float8) ScanFloat64(n Float8) error
ScanFloat64 implements the Float64Scanner interface.
func (f *Float8) ScanInt64(n Int8) error
func (f *Float8) UnmarshalJSON(b []byte) error
func (f Float8) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Float8Codec struct{}
func (c Float8Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c Float8Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (Float8Codec) FormatSupported(format int16) bool
func (Float8Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Float8Codec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (Float8Codec) PreferredFormat() int16
Hstore represents an hstore column that can be null or have null values associated with its keys.
type Hstore map[string]*string
func (h Hstore) HstoreValue() (Hstore, error)
func (h *Hstore) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (h *Hstore) ScanHstore(v Hstore) error
func (h Hstore) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type HstoreCodec struct{}
func (c HstoreCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c HstoreCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (HstoreCodec) FormatSupported(format int16) bool
func (HstoreCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (HstoreCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (HstoreCodec) PreferredFormat() int16
type HstoreScanner interface { ScanHstore(v Hstore) error }
type HstoreValuer interface { HstoreValue() (Hstore, error) }
InetCodec handles both inet and cidr PostgreSQL types. The preferred Go types are netip.Prefix and netip.Addr. If IsValid() is false then they are treated as SQL NULL.
type InetCodec struct{}
func (c InetCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c InetCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (InetCodec) FormatSupported(format int16) bool
func (InetCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (InetCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (InetCodec) PreferredFormat() int16
type InfinityModifier int8
const ( Infinity InfinityModifier = 1 Finite InfinityModifier = 0 NegativeInfinity InfinityModifier = -Infinity )
func (im InfinityModifier) String() string
type Int2 struct { Int16 int16 Valid bool }
func (n Int2) Int64Value() (Int8, error)
func (src Int2) MarshalJSON() ([]byte, error)
func (dst *Int2) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (dst *Int2) ScanInt64(n Int8) error
ScanInt64 implements the Int64Scanner interface.
func (dst *Int2) UnmarshalJSON(b []byte) error
func (src Int2) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Int2Codec struct{}
func (c Int2Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c Int2Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (Int2Codec) FormatSupported(format int16) bool
func (Int2Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Int2Codec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (Int2Codec) PreferredFormat() int16
type Int4 struct { Int32 int32 Valid bool }
func (n Int4) Int64Value() (Int8, error)
func (src Int4) MarshalJSON() ([]byte, error)
func (dst *Int4) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (dst *Int4) ScanInt64(n Int8) error
ScanInt64 implements the Int64Scanner interface.
func (dst *Int4) UnmarshalJSON(b []byte) error
func (src Int4) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Int4Codec struct{}
func (c Int4Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c Int4Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (Int4Codec) FormatSupported(format int16) bool
func (Int4Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Int4Codec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (Int4Codec) PreferredFormat() int16
type Int64Scanner interface { ScanInt64(Int8) error }
type Int64Valuer interface { Int64Value() (Int8, error) }
type Int8 struct { Int64 int64 Valid bool }
func (n Int8) Int64Value() (Int8, error)
func (src Int8) MarshalJSON() ([]byte, error)
func (dst *Int8) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (dst *Int8) ScanInt64(n Int8) error
ScanInt64 implements the Int64Scanner interface.
func (dst *Int8) UnmarshalJSON(b []byte) error
func (src Int8) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Int8Codec struct{}
func (c Int8Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c Int8Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (Int8Codec) FormatSupported(format int16) bool
func (Int8Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Int8Codec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (Int8Codec) PreferredFormat() int16
type Interval struct { Microseconds int64 Days int32 Months int32 Valid bool }
func (interval Interval) IntervalValue() (Interval, error)
func (interval *Interval) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (interval *Interval) ScanInterval(v Interval) error
func (interval Interval) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type IntervalCodec struct{}
func (c IntervalCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c IntervalCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (IntervalCodec) FormatSupported(format int16) bool
func (IntervalCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (IntervalCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (IntervalCodec) PreferredFormat() int16
type IntervalScanner interface { ScanInterval(v Interval) error }
type IntervalValuer interface { IntervalValue() (Interval, error) }
type JSONBCodec struct{}
func (c JSONBCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c JSONBCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (JSONBCodec) FormatSupported(format int16) bool
func (JSONBCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (JSONBCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (JSONBCodec) PreferredFormat() int16
type JSONCodec struct{}
func (c JSONCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c JSONCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (JSONCodec) FormatSupported(format int16) bool
func (c JSONCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (JSONCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (JSONCodec) PreferredFormat() int16
type Line struct { A, B, C float64 Valid bool }
func (line Line) LineValue() (Line, error)
func (line *Line) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (line *Line) ScanLine(v Line) error
func (line *Line) Set(src any) error
func (line Line) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type LineCodec struct{}
func (c LineCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c LineCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (LineCodec) FormatSupported(format int16) bool
func (LineCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (LineCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (LineCodec) PreferredFormat() int16
type LineScanner interface { ScanLine(v Line) error }
type LineValuer interface { LineValue() (Line, error) }
type Lseg struct { P [2]Vec2 Valid bool }
func (lseg Lseg) LsegValue() (Lseg, error)
func (lseg *Lseg) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (lseg *Lseg) ScanLseg(v Lseg) error
func (lseg Lseg) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type LsegCodec struct{}
func (c LsegCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c LsegCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (LsegCodec) FormatSupported(format int16) bool
func (LsegCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (LsegCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (LsegCodec) PreferredFormat() int16
type LsegScanner interface { ScanLseg(v Lseg) error }
type LsegValuer interface { LsegValue() (Lseg, error) }
type LtreeCodec struct{}
func (l LtreeCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
DecodeDatabaseSQLValue returns src decoded into a value compatible with the sql.Scanner interface.
func (l LtreeCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
DecodeValue returns src decoded into its default format.
func (l LtreeCodec) FormatSupported(format int16) bool
func (l LtreeCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
PlanEncode returns an EncodePlan for encoding value into PostgreSQL format for oid and format. If no plan can be found then nil is returned.
func (l LtreeCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
PlanScan returns a ScanPlan for scanning a PostgreSQL value into a destination with the same type as target. If no plan can be found then nil is returned.
func (l LtreeCodec) PreferredFormat() int16
PreferredFormat returns the preferred format.
type MacaddrCodec struct{}
func (c MacaddrCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c MacaddrCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (MacaddrCodec) FormatSupported(format int16) bool
func (MacaddrCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (MacaddrCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (MacaddrCodec) PreferredFormat() int16
Map is the mapping between PostgreSQL server types and Go type handling logic. It can encode values for transmission to a PostgreSQL server and scan received values.
type Map struct { // TryWrapEncodePlanFuncs is a slice of functions that will wrap a value that cannot be encoded by the Codec. Every // time a wrapper is found the PlanEncode method will be recursively called with the new value. This allows several layers of wrappers // to be built up. There are default functions placed in this slice by NewMap(). In most cases these functions // should run last. i.e. Additional functions should typically be prepended not appended. TryWrapEncodePlanFuncs []TryWrapEncodePlanFunc // TryWrapScanPlanFuncs is a slice of functions that will wrap a target that cannot be scanned into by the Codec. Every // time a wrapper is found the PlanScan method will be recursively called with the new target. This allows several layers of wrappers // to be built up. There are default functions placed in this slice by NewMap(). In most cases these functions // should run last. i.e. Additional functions should typically be prepended not appended. TryWrapScanPlanFuncs []TryWrapScanPlanFunc // contains filtered or unexported fields }
func NewMap() *Map
func (m *Map) Encode(oid uint32, formatCode int16, value any, buf []byte) (newBuf []byte, err error)
Encode appends the encoded bytes of value to buf. If value is the SQL value NULL then append nothing and return (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data written.
func (m *Map) FormatCodeForOID(oid uint32) int16
FormatCodeForOID returns the preferred format code for type oid. If the type is not registered it returns the text format code.
func (m *Map) PlanEncode(oid uint32, format int16, value any) EncodePlan
PlanEncode returns an Encode plan for encoding value into PostgreSQL format for oid and format. If no plan can be found then nil is returned.
func (m *Map) PlanScan(oid uint32, formatCode int16, target any) ScanPlan
PlanScan prepares a plan to scan a value into target.
func (m *Map) RegisterDefaultPgType(value any, name string)
RegisterDefaultPgType registers a mapping of a Go type to a PostgreSQL type name. Typically the data type to be encoded or decoded is determined by the PostgreSQL OID. But if the OID of a value to be encoded or decoded is unknown, this additional mapping will be used by TypeForValue to determine a suitable data type.
func (m *Map) RegisterType(t *Type)
RegisterType registers a data type with the Map. t must not be mutated after it is registered.
func (m *Map) SQLScanner(v any) sql.Scanner
SQLScanner returns a database/sql.Scanner for v. This is necessary for types like Array[T] and Range[T] where the type needs assistance from Map to implement the sql.Scanner interface. It is not necessary for types like Box that implement sql.Scanner directly.
This uses the type of v to look up the PostgreSQL OID that v presumably came from. This means v must be registered with m by calling RegisterDefaultPgType.
func (m *Map) Scan(oid uint32, formatCode int16, src []byte, dst any) error
func (m *Map) TypeForName(name string) (*Type, bool)
TypeForName returns the Type registered for the given name. The returned Type must not be mutated.
func (m *Map) TypeForOID(oid uint32) (*Type, bool)
TypeForOID returns the Type registered for the given OID. The returned Type must not be mutated.
func (m *Map) TypeForValue(v any) (*Type, bool)
TypeForValue finds a data type suitable for v. Use RegisterType to register types that can encode and decode themselves. Use RegisterDefaultPgType to register that can be handled by a registered data type. The returned Type must not be mutated.
Multirange is a generic multirange type.
T should implement RangeValuer and *T should implement RangeScanner. However, there does not appear to be a way to enforce the RangeScanner constraint.
type Multirange[T RangeValuer] []T
func (r Multirange[T]) Index(i int) any
func (r Multirange[T]) IndexType() any
func (r Multirange[T]) IsNull() bool
func (r Multirange[T]) Len() int
func (r Multirange[T]) ScanIndex(i int) any
func (r Multirange[T]) ScanIndexType() any
func (r *Multirange[T]) ScanNull() error
func (r *Multirange[T]) SetLen(n int) error
MultirangeCodec is a codec for any multirange type.
type MultirangeCodec struct { ElementType *Type }
func (c *MultirangeCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c *MultirangeCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (c *MultirangeCodec) FormatSupported(format int16) bool
func (c *MultirangeCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (c *MultirangeCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (c *MultirangeCodec) PreferredFormat() int16
MultirangeGetter is a type that can be converted into a PostgreSQL multirange.
type MultirangeGetter interface { // IsNull returns true if the value is SQL NULL. IsNull() bool // Len returns the number of elements in the multirange. Len() int // Index returns the element at i. Index(i int) any // IndexType returns a non-nil scan target of the type Index will return. This is used by MultirangeCodec.PlanEncode. IndexType() any }
MultirangeSetter is a type can be set from a PostgreSQL multirange.
type MultirangeSetter interface { // ScanNull sets the value to SQL NULL. ScanNull() error // SetLen prepares the value such that ScanIndex can be called for each element. This will remove any existing // elements. SetLen(n int) error // ScanIndex returns a value usable as a scan target for i. SetLen must be called before ScanIndex. ScanIndex(i int) any // ScanIndexType returns a non-nil scan target of the type ScanIndex will return. This is used by // MultirangeCodec.PlanScan. ScanIndexType() any }
type NetipPrefixScanner interface { ScanNetipPrefix(v netip.Prefix) error }
type NetipPrefixValuer interface { NetipPrefixValue() (netip.Prefix, error) }
type Numeric struct { Int *big.Int Exp int32 NaN bool InfinityModifier InfinityModifier Valid bool }
func (n Numeric) Float64Value() (Float8, error)
func (n Numeric) Int64Value() (Int8, error)
func (n Numeric) MarshalJSON() ([]byte, error)
func (n Numeric) NumericValue() (Numeric, error)
func (n *Numeric) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (n *Numeric) ScanInt64(v Int8) error
func (n *Numeric) ScanNumeric(v Numeric) error
func (n *Numeric) ScanScientific(src string) error
func (n *Numeric) UnmarshalJSON(src []byte) error
func (n Numeric) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type NumericCodec struct{}
func (c NumericCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c NumericCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (NumericCodec) FormatSupported(format int16) bool
func (NumericCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (NumericCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (NumericCodec) PreferredFormat() int16
type NumericScanner interface { ScanNumeric(v Numeric) error }
type NumericValuer interface { NumericValue() (Numeric, error) }
type Path struct { P []Vec2 Closed bool Valid bool }
func (path Path) PathValue() (Path, error)
func (path *Path) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (path *Path) ScanPath(v Path) error
func (path Path) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type PathCodec struct{}
func (c PathCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c PathCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (PathCodec) FormatSupported(format int16) bool
func (PathCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (PathCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (PathCodec) PreferredFormat() int16
type PathScanner interface { ScanPath(v Path) error }
type PathValuer interface { PathValue() (Path, error) }
type Point struct { P Vec2 Valid bool }
func (src Point) MarshalJSON() ([]byte, error)
func (p Point) PointValue() (Point, error)
func (dst *Point) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (p *Point) ScanPoint(v Point) error
func (dst *Point) UnmarshalJSON(point []byte) error
func (src Point) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type PointCodec struct{}
func (c PointCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c PointCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (PointCodec) FormatSupported(format int16) bool
func (PointCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (PointCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (PointCodec) PreferredFormat() int16
type PointScanner interface { ScanPoint(v Point) error }
type PointValuer interface { PointValue() (Point, error) }
type Polygon struct { P []Vec2 Valid bool }
func (p Polygon) PolygonValue() (Polygon, error)
func (p *Polygon) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (p *Polygon) ScanPolygon(v Polygon) error
func (p Polygon) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type PolygonCodec struct{}
func (c PolygonCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c PolygonCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (PolygonCodec) FormatSupported(format int16) bool
func (PolygonCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (PolygonCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (PolygonCodec) PreferredFormat() int16
type PolygonScanner interface { ScanPolygon(v Polygon) error }
type PolygonValuer interface { PolygonValue() (Polygon, error) }
PreallocBytes is a byte slice of preallocated memory that scanned bytes will be copied to. If it is too small a new slice will be allocated.
type PreallocBytes []byte
func (b *PreallocBytes) ScanBytes(v []byte) error
QCharCodec is for PostgreSQL's special 8-bit-only "char" type more akin to the C language's char type, or Go's byte type. (Note that the name in PostgreSQL itself is "char", in double-quotes, and not char.) It gets used a lot in PostgreSQL's system tables to hold a single ASCII character value (eg pg_class.relkind). It is named Qchar for quoted char to disambiguate from SQL standard type char.
type QCharCodec struct{}
func (c QCharCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c QCharCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (QCharCodec) FormatSupported(format int16) bool
func (QCharCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (QCharCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (QCharCodec) PreferredFormat() int16
Range is a generic range type.
type Range[T any] struct { Lower T Upper T LowerType BoundType UpperType BoundType Valid bool }
func (r Range[T]) BoundTypes() (lower, upper BoundType)
func (r Range[T]) Bounds() (lower, upper any)
func (r Range[T]) IsNull() bool
func (r *Range[T]) ScanBounds() (lowerTarget, upperTarget any)
func (r *Range[T]) ScanNull() error
func (r *Range[T]) SetBoundTypes(lower, upper BoundType) error
RangeCodec is a codec for any range type.
type RangeCodec struct { ElementType *Type }
func (c *RangeCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c *RangeCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (c *RangeCodec) FormatSupported(format int16) bool
func (c *RangeCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (c *RangeCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (c *RangeCodec) PreferredFormat() int16
RangeScanner is a type can be scanned from a PostgreSQL range.
type RangeScanner interface { // ScanNull sets the value to SQL NULL. ScanNull() error // ScanBounds returns values usable as a scan target. The returned values may not be scanned if the range is empty or // the bound type is unbounded. ScanBounds() (lowerTarget, upperTarget any) // SetBoundTypes sets the lower and upper bound types. ScanBounds will be called and the returned values scanned // (if appropriate) before SetBoundTypes is called. If the bound types are unbounded or empty this method must // also set the bound values. SetBoundTypes(lower, upper BoundType) error }
RangeValuer is a type that can be converted into a PostgreSQL range.
type RangeValuer interface { // IsNull returns true if the value is SQL NULL. IsNull() bool // BoundTypes returns the lower and upper bound types. BoundTypes() (lower, upper BoundType) // Bounds returns the lower and upper range values. Bounds() (lower, upper any) }
RecordCodec is a codec for the generic PostgreSQL record type such as is created with the "row" function. Record can only decode the binary format. The text format output format from PostgreSQL does not include type information and is therefore impossible to decode. Encoding is impossible because PostgreSQL does not support input of generic records.
type RecordCodec struct{}
func (RecordCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (RecordCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (RecordCodec) FormatSupported(format int16) bool
func (RecordCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (RecordCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (RecordCodec) PreferredFormat() int16
ScanPlan is a precompiled plan to scan into a type of destination.
type ScanPlan interface { // Scan scans src into target. src is only valid during the call to Scan. The ScanPlan must not retain a reference to // src. Scan(src []byte, target any) error }
SkipUnderlyingTypePlanner prevents PlanScan and PlanDecode from trying to use the underlying type.
type SkipUnderlyingTypePlanner interface { SkipUnderlyingTypePlan() }
TID is PostgreSQL's Tuple Identifier type.
When one does
select ctid, * from some_table;
it is the data type of the ctid hidden system column.
It is currently implemented as a pair unsigned two byte integers. Its conversion functions can be found in src/backend/utils/adt/tid.c in the PostgreSQL sources.
type TID struct { BlockNumber uint32 OffsetNumber uint16 Valid bool }
func (dst *TID) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (b *TID) ScanTID(v TID) error
func (b TID) TIDValue() (TID, error)
func (src TID) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type TIDCodec struct{}
func (c TIDCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c TIDCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (TIDCodec) FormatSupported(format int16) bool
func (TIDCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (TIDCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (TIDCodec) PreferredFormat() int16
type TIDScanner interface { ScanTID(v TID) error }
type TIDValuer interface { TIDValue() (TID, error) }
type Text struct { String string Valid bool }
func (src Text) MarshalJSON() ([]byte, error)
func (dst *Text) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (t *Text) ScanText(v Text) error
func (t Text) TextValue() (Text, error)
func (dst *Text) UnmarshalJSON(b []byte) error
func (src Text) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type TextCodec struct{}
func (c TextCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c TextCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (TextCodec) FormatSupported(format int16) bool
func (TextCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (TextCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (TextCodec) PreferredFormat() int16
type TextFormatOnlyCodec struct { Codec }
func (c *TextFormatOnlyCodec) FormatSupported(format int16) bool
func (TextFormatOnlyCodec) PreferredFormat() int16
type TextScanner interface { ScanText(v Text) error }
type TextValuer interface { TextValue() (Text, error) }
Time represents the PostgreSQL time type. The PostgreSQL time is a time of day without time zone.
Time is represented as the number of microseconds since midnight in the same way that PostgreSQL does. Other time and date types in pgtype can use time.Time as the underlying representation. However, pgtype.Time type cannot due to needing to handle 24:00:00. time.Time converts that to 00:00:00 on the following day.
type Time struct { Microseconds int64 // Number of microseconds since midnight Valid bool }
func (t *Time) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (t *Time) ScanTime(v Time) error
func (t Time) TimeValue() (Time, error)
func (t Time) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type TimeCodec struct{}
func (c TimeCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c TimeCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (TimeCodec) FormatSupported(format int16) bool
func (TimeCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (TimeCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (TimeCodec) PreferredFormat() int16
type TimeScanner interface { ScanTime(v Time) error }
type TimeValuer interface { TimeValue() (Time, error) }
Timestamp represents the PostgreSQL timestamp type.
type Timestamp struct { Time time.Time // Time zone will be ignored when encoding to PostgreSQL. InfinityModifier InfinityModifier Valid bool }
func (ts Timestamp) MarshalJSON() ([]byte, error)
func (ts *Timestamp) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (ts *Timestamp) ScanTimestamp(v Timestamp) error
func (ts Timestamp) TimestampValue() (Timestamp, error)
func (ts *Timestamp) UnmarshalJSON(b []byte) error
func (ts Timestamp) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type TimestampCodec struct{}
func (c TimestampCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c TimestampCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (TimestampCodec) FormatSupported(format int16) bool
func (TimestampCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (TimestampCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (TimestampCodec) PreferredFormat() int16
type TimestampScanner interface { ScanTimestamp(v Timestamp) error }
type TimestampValuer interface { TimestampValue() (Timestamp, error) }
Timestamptz represents the PostgreSQL timestamptz type.
type Timestamptz struct { Time time.Time InfinityModifier InfinityModifier Valid bool }
func (tstz Timestamptz) MarshalJSON() ([]byte, error)
func (tstz *Timestamptz) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (tstz *Timestamptz) ScanTimestamptz(v Timestamptz) error
func (tstz Timestamptz) TimestamptzValue() (Timestamptz, error)
func (tstz *Timestamptz) UnmarshalJSON(b []byte) error
func (tstz Timestamptz) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type TimestamptzCodec struct{}
func (c TimestamptzCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c TimestamptzCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (TimestamptzCodec) FormatSupported(format int16) bool
func (TimestamptzCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (TimestamptzCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (TimestamptzCodec) PreferredFormat() int16
type TimestamptzScanner interface { ScanTimestamptz(v Timestamptz) error }
type TimestamptzValuer interface { TimestamptzValue() (Timestamptz, error) }
TryWrapEncodePlanFunc is a function that tries to create a wrapper plan for value. If successful it returns a plan that will convert the value passed to Encode and then call the next plan. nextValue is value as it will be converted by plan. It must be used to find another suitable EncodePlan. When it is found SetNext must be called on plan for it to be usabled. ok indicates if a suitable wrapper was found.
type TryWrapEncodePlanFunc func(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
TryWrapScanPlanFunc is a function that tries to create a wrapper plan for target. If successful it returns a plan that will convert the target passed to Scan and then call the next plan. nextTarget is target as it will be converted by plan. It must be used to find another suitable ScanPlan. When it is found SetNext must be called on plan for it to be usabled. ok indicates if a suitable wrapper was found.
type TryWrapScanPlanFunc func(target any) (plan WrappedScanPlanNextSetter, nextTarget any, ok bool)
Type represents a PostgreSQL data type. It must not be mutated after it is registered with a Map.
type Type struct { Codec Codec Name string OID uint32 }
type UUID struct { Bytes [16]byte Valid bool }
func (src UUID) MarshalJSON() ([]byte, error)
func (dst *UUID) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (b *UUID) ScanUUID(v UUID) error
func (b UUID) UUIDValue() (UUID, error)
func (dst *UUID) UnmarshalJSON(src []byte) error
func (src UUID) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type UUIDCodec struct{}
func (c UUIDCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c UUIDCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (UUIDCodec) FormatSupported(format int16) bool
func (UUIDCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (UUIDCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (UUIDCodec) PreferredFormat() int16
type UUIDScanner interface { ScanUUID(v UUID) error }
type UUIDValuer interface { UUIDValue() (UUID, error) }
Uint32 is the core type that is used to represent PostgreSQL types such as OID, CID, and XID.
type Uint32 struct { Uint32 uint32 Valid bool }
func (dst *Uint32) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (n *Uint32) ScanUint32(v Uint32) error
func (n Uint32) Uint32Value() (Uint32, error)
func (src Uint32) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Uint32Codec struct{}
func (c Uint32Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
func (c Uint32Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error)
func (Uint32Codec) FormatSupported(format int16) bool
func (Uint32Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Uint32Codec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
func (Uint32Codec) PreferredFormat() int16
type Uint32Scanner interface { ScanUint32(v Uint32) error }
type Uint32Valuer interface { Uint32Value() (Uint32, error) }
UndecodedBytes can be used as a scan target to get the raw bytes from PostgreSQL without any decoding.
type UndecodedBytes []byte
type Vec2 struct { X float64 Y float64 }
type WrappedEncodePlanNextSetter interface { SetNext(EncodePlan) EncodePlan }
func TryWrapArrayEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
func TryWrapBuiltinTypeEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
TryWrapBuiltinTypeEncodePlan tries to wrap a builtin type with a wrapper that provides additional methods. e.g. If value was of type int32 then a wrapper plan would be returned that converts value to a type that implements Int64Valuer.
func TryWrapDerefPointerEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
TryWrapDerefPointerEncodePlan tries to dereference a pointer. e.g. If value was of type *string then a wrapper plan would be returned that derefences the value.
func TryWrapFindUnderlyingTypeEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
TryWrapFindUnderlyingTypeEncodePlan tries to convert to a Go builtin type. e.g. If value was of type MyString and MyString was defined as a string then a wrapper plan would be returned that converts MyString to string.
func TryWrapMultiDimSliceEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
func TryWrapSliceEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
func TryWrapStructEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
TryWrapStructPlan tries to wrap a struct with a wrapper that implements CompositeIndexGetter.
type WrappedScanPlanNextSetter interface { SetNext(ScanPlan) ScanPlan }
func TryFindUnderlyingTypeScanPlan(dst any) (plan WrappedScanPlanNextSetter, nextDst any, ok bool)
TryFindUnderlyingTypeScanPlan tries to convert to a Go builtin type. e.g. If value was of type MyString and MyString was defined as a string then a wrapper plan would be returned that converts MyString to string.
func TryPointerPointerScanPlan(target any) (plan WrappedScanPlanNextSetter, nextTarget any, ok bool)
TryPointerPointerScanPlan handles a pointer to a pointer by setting the target to nil for SQL NULL and allocating and scanning for non-NULL.
func TryWrapBuiltinTypeScanPlan(target any) (plan WrappedScanPlanNextSetter, nextDst any, ok bool)
TryWrapBuiltinTypeScanPlan tries to wrap a builtin type with a wrapper that provides additional methods. e.g. If value was of type int32 then a wrapper plan would be returned that converts target to a value that implements Int64Scanner.
func TryWrapPtrArrayScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
TryWrapPtrArrayScanPlan tries to wrap a pointer to a single dimension array.
func TryWrapPtrMultiDimSliceScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
TryWrapPtrMultiDimSliceScanPlan tries to wrap a pointer to a multi-dimension slice.
func TryWrapPtrSliceScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
TryWrapPtrSliceScanPlan tries to wrap a pointer to a single dimension slice.
func TryWrapStructScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
TryWrapStructPlan tries to wrap a struct with a wrapper that implements CompositeIndexGetter.