Documentation ¶
Overview ¶
Package pgtype converts between Go and PostgreSQL values.
The primary type is the Map type. It is a map of PostgreSQL types identified by OID (object ID) to a Codec. A Codec is responsible for converting between Go and PostgreSQL values. NewMap creates a Map with all supported standard PostgreSQL types already registered. Additional types can be registered with Map.RegisterType.
Use Map.Scan and Map.Encode to decode PostgreSQL values to Go and encode Go values to PostgreSQL respectively.
Base Type Mapping ¶
pgtype maps between all common base types directly between Go and PostgreSQL. In particular:
Go PostgreSQL ----------------------- string varchar text // Integers are automatically be converted to any other integer type if // it can be done without overflow or underflow. int8 int16 smallint int32 int int64 bigint int uint8 uint16 uint32 uint64 uint // Floats are strict and do not automatically convert like integers. float32 float4 float64 float8 time.Time date timestamp timestamptz netip.Addr inet netip.Prefix cidr []byte bytea
Null Values ¶
pgtype can map NULLs in two ways. The first is types that can directly represent NULL such as Int4. They work in a similar fashion to database/sql. The second is to use a pointer to a pointer.
var foo pgtype.Text var bar *string err := conn.QueryRow("select foo, bar from widgets where id=$1", 42).Scan(&foo, &bar) if err != nil { return err }
JSON Support ¶
pgtype automatically marshals and unmarshals data from json and jsonb PostgreSQL types.
Extending Existing PostgreSQL Type Support ¶
Generally, all Codecs will support interfaces that can be implemented to enable scanning and encoding. For example, PointCodec can use any Go type that implements the PointScanner and PointValuer interfaces. So rather than use pgtype.Point and application can directly use its own point type with pgtype as long as it implements those interfaces.
See example_custom_type_test.go for an example of a custom type for the PostgreSQL point type.
Sometimes pgx supports a PostgreSQL type such as numeric but the Go type is in an external package that does not have pgx support such as github.com/shopspring/decimal. These types can be registered with pgtype with custom conversion logic. See https://github.com/jackc/pgx-shopspring-decimal and https://github.com/jackc/pgx-gofrs-uuid for a example integrations.
New PostgreSQL Type Support ¶
pgtype uses the PostgreSQL OID to determine how to encode or decode a value. pgtype supports array, composite, domain, and enum types. However, any type created in PostgreSQL with CREATE TYPE will receive a new OID. This means that the OID of each new PostgreSQL type must be registered for pgtype to handle values of that type with the correct Codec.
The pgx.Conn LoadType method can return a *Type for array, composite, domain, and enum types by inspecting the database metadata. This *Type can then be registered with Map.RegisterType.
For example, the following function could be called after a connection is established:
func RegisterDataTypes(ctx context.Context, conn *pgx.Conn) error { dataTypeNames := []string{ "foo", "_foo", "bar", "_bar", } for _, typeName := range dataTypeNames { dataType, err := conn.LoadType(ctx, typeName) if err != nil { return err } conn.TypeMap().RegisterType(dataType) } return nil }
A type cannot be registered unless all types it depends on are already registered. e.g. An array type cannot be registered until its element type is registered.
ArrayCodec implements support for arrays. If pgtype supports type T then it can easily support []T by registering an ArrayCodec for the appropriate PostgreSQL OID. In addition, Array[T] type can support multi-dimensional arrays.
CompositeCodec implements support for PostgreSQL composite types. Go structs can be scanned into if the public fields of the struct are in the exact order and type of the PostgreSQL type or by implementing CompositeIndexScanner and CompositeIndexGetter.
Domain types are treated as their underlying type if the underlying type and the domain type are registered.
PostgreSQL enums can usually be treated as text. However, EnumCodec implements support for interning strings which can reduce memory usage.
While pgtype will often still work with unregistered types it is highly recommended that all types be registered due to an improvement in performance and the elimination of certain edge cases.
If an entirely new PostgreSQL type (e.g. PostGIS types) is used then the application or a library can create a new Codec. Then the OID / Codec mapping can be registered with Map.RegisterType. There is no difference between a Codec defined and registered by the application and a Codec built in to pgtype. See any of the Codecs in pgtype for Codec examples and for examples of type registration.
Encoding Unknown Types ¶
pgtype works best when the OID of the PostgreSQL type is known. But in some cases such as using the simple protocol the OID is unknown. In this case Map.RegisterDefaultPgType can be used to register an assumed OID for a particular Go type.
Renamed Types ¶
If pgtype does not recognize a type and that type is a renamed simple type simple (e.g. type MyInt32 int32) pgtype acts as if it is the underlying type. It currently cannot automatically detect the underlying type of renamed structs (eg.g. type MyTime time.Time).
Compatibility with database/sql
pgtype also includes support for custom types implementing the database/sql.Scanner and database/sql/driver.Valuer interfaces.
Child Records ¶
pgtype's support for arrays and composite records can be used to load records and their children in a single query. See example_child_records_test.go for an example.
Overview of Scanning Implementation ¶
The first step is to use the OID to lookup the correct Codec. If the OID is unavailable, Map will try to find the OID from previous calls of Map.RegisterDefaultPgType. The Map will call the Codec's PlanScan method to get a plan for scanning into the Go value. A Codec will support scanning into one or more Go types. Oftentime these Go types are interfaces rather than explicit types. For example, PointCodec can use any Go type that implments the PointScanner and PointValuer interfaces.
If a Go value is not supported directly by a Codec then Map will try wrapping it with additional logic and try again. For example, Int8Codec does not support scanning into a renamed type (e.g. type myInt64 int64). But Map will detect that myInt64 is a renamed type and create a plan that converts the value to the underlying int64 type and then passes that to the Codec (see TryFindUnderlyingTypeScanPlan).
These plan wrappers are contained in Map.TryWrapScanPlanFuncs. By default these contain shared logic to handle renamed types, pointers to pointers, slices, composite types, etc. Additional plan wrappers can be added to seamlessly integrate types that do not support pgx directly. For example, the before mentioned https://github.com/jackc/pgx-shopspring-decimal package detects decimal.Decimal values, wraps them in something implementing NumericScanner and passes that to the Codec.
Map.Scan and Map.Encode are convenience methods that wrap Map.PlanScan and Map.PlanEncode. Determining how to scan or encode a particular type may be a time consuming operation. Hence the planning and execution steps of a conversion are internally separated.
Reducing Compiled Binary Size ¶
pgx.QueryExecModeExec and pgx.QueryExecModeSimpleProtocol require the default PostgreSQL type to be registered for each Go type used as a query parameter. By default pgx does this for all supported types and their array variants. If an application does not use those query execution modes or manually registers the default PostgreSQL type for the types it uses as query parameters it can use the build tag nopgxregisterdefaulttypes. This omits the default type registration and reduces the compiled binary size by ~2MB.
Do not edit. Generated from pgtype/int.go.erb
Example (ChildRecords) ¶
This example uses a single query to return parent and child records.
package main import ( "context" "fmt" "os" "time" "gitee.com/general252/pgx" ) type Player struct { Name string Position string } type Team struct { Name string Players []Player } // This example uses a single query to return parent and child records. func main() { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() conn, err := pgx.Connect(ctx, os.Getenv("PGX_TEST_DATABASE")) if err != nil { fmt.Printf("Unable to establish connection: %v", err) return } if conn.PgConn().ParameterStatus("crdb_version") != "" { // Skip test / example when running on CockroachDB. Since an example can't be skipped fake success instead. fmt.Println(`Alpha Adam: wing Bill: halfback Charlie: fullback Beta Don: halfback Edgar: halfback Frank: fullback`) return } // Setup example schema and data. _, err = conn.Exec(ctx, ` create temporary table teams ( name text primary key ); create temporary table players ( name text primary key, team_name text, position text ); insert into teams (name) values ('Alpha'), ('Beta'); insert into players (name, team_name, position) values ('Adam', 'Alpha', 'wing'), ('Bill', 'Alpha', 'halfback'), ('Charlie', 'Alpha', 'fullback'), ('Don', 'Beta', 'halfback'), ('Edgar', 'Beta', 'halfback'), ('Frank', 'Beta', 'fullback') `) if err != nil { fmt.Printf("Unable to setup example schema and data: %v", err) return } rows, _ := conn.Query(ctx, ` select t.name, (select array_agg(row(p.name, position) order by p.name) from players p where p.team_name = t.name) from teams t order by t.name `) teams, err := pgx.CollectRows(rows, pgx.RowToStructByPos[Team]) if err != nil { fmt.Printf("CollectRows error: %v", err) return } for _, team := range teams { fmt.Println(team.Name) for _, player := range team.Players { fmt.Printf(" %s: %s\n", player.Name, player.Position) } } }
Output: Alpha Adam: wing Bill: halfback Charlie: fullback Beta Don: halfback Edgar: halfback Frank: fullback
Example (CustomType) ¶
package main import ( "context" "fmt" "os" "gitee.com/general252/pgx" "gitee.com/general252/pgx/pgtype" ) // Point represents a point that may be null. type Point struct { X, Y float32 // Coordinates of point Valid bool } func (p *Point) ScanPoint(v pgtype.Point) error { *p = Point{ X: float32(v.P.X), Y: float32(v.P.Y), Valid: v.Valid, } return nil } func (p Point) PointValue() (pgtype.Point, error) { return pgtype.Point{ P: pgtype.Vec2{X: float64(p.X), Y: float64(p.Y)}, Valid: true, }, nil } func (src *Point) String() string { if !src.Valid { return "null point" } return fmt.Sprintf("%.1f, %.1f", src.X, src.Y) } func main() { conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE")) if err != nil { fmt.Printf("Unable to establish connection: %v", err) return } defer conn.Close(context.Background()) if conn.PgConn().ParameterStatus("crdb_version") != "" { // Skip test / example when running on CockroachDB which doesn't support the point type. Since an example can't be // skipped fake success instead. fmt.Println("null point") fmt.Println("1.5, 2.5") return } p := &Point{} err = conn.QueryRow(context.Background(), "select null::point").Scan(p) if err != nil { fmt.Println(err) return } fmt.Println(p) err = conn.QueryRow(context.Background(), "select point(1.5,2.5)").Scan(p) if err != nil { fmt.Println(err) return } fmt.Println(p) }
Output: null point 1.5, 2.5
Example (Json) ¶
package main import ( "context" "fmt" "os" "gitee.com/general252/pgx" ) func main() { conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE")) if err != nil { fmt.Printf("Unable to establish connection: %v", err) return } type person struct { Name string `json:"name"` Age int `json:"age"` } input := person{ Name: "John", Age: 42, } var output person err = conn.QueryRow(context.Background(), "select $1::json", input).Scan(&output) if err != nil { fmt.Println(err) return } fmt.Println(output.Name, output.Age) }
Output: John 42
Index ¶
- Constants
- Variables
- func GetAssignToDstType(dst any) (any, bool)
- func NullAssignTo(dst any) error
- type Array
- type ArrayCodec
- 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
- type ArrayGetter
- type ArraySetter
- type Bits
- type BitsCodec
- 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
- type BitsValuer
- type Bool
- type BoolCodec
- 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
- type BoolValuer
- type BoundType
- type Box
- type BoxCodec
- 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
- type BoxValuer
- type ByteaCodec
- 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
- type BytesValuer
- type Circle
- type CircleCodec
- 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
- type CircleValuer
- type Codec
- type CompositeBinaryBuilder
- type CompositeBinaryScanner
- type CompositeCodec
- 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
- type CompositeFields
- type CompositeIndexGetter
- type CompositeIndexScanner
- type CompositeTextBuilder
- type CompositeTextScanner
- type Date
- type DateCodec
- 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
- type DateValuer
- type DriverBytes
- type EncodePlan
- type EnumCodec
- 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
- type FlatArray
- type Float4
- type Float4Codec
- 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
- type Float64Valuer
- type Float8
- 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
- func (f *Float8) ScanFloat64(n Float8) error
- func (f *Float8) ScanInt64(n Int8) error
- func (f Float8) Value() (driver.Value, error)
- type Float8Codec
- 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
- type Hstore
- type HstoreCodec
- 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
- type HstoreValuer
- type InetCodec
- 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
- type Int2
- type Int2Codec
- 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
- type Int4Codec
- 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
- type Int64Valuer
- type Int8
- type Int8Codec
- 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
- type IntervalCodec
- 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
- type IntervalValuer
- type JSONBCodec
- 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
- 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
- type LineCodec
- 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
- type LineValuer
- type Lseg
- type LsegCodec
- 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
- type LsegValuer
- type MacaddrCodec
- 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
- type Map
- func (m *Map) Encode(oid uint32, formatCode int16, value any, buf []byte) (newBuf []byte, err error)
- func (m *Map) FormatCodeForOID(oid uint32) int16
- func (m *Map) PlanEncode(oid uint32, format int16, value any) EncodePlan
- func (m *Map) PlanScan(oid uint32, formatCode int16, target any) ScanPlan
- func (m *Map) RegisterDefaultPgType(value any, name string)
- func (m *Map) RegisterType(t *Type)
- func (m *Map) SQLScanner(v any) sql.Scanner
- func (m *Map) Scan(oid uint32, formatCode int16, src []byte, dst any) error
- func (m *Map) TypeForName(name string) (*Type, bool)
- func (m *Map) TypeForOID(oid uint32) (*Type, bool)
- func (m *Map) TypeForValue(v any) (*Type, bool)
- type Multirange
- 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
- type MultirangeCodec
- 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
- type MultirangeGetter
- type MultirangeSetter
- type NetipPrefixScanner
- type NetipPrefixValuer
- type Numeric
- 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
- func (n *Numeric) ScanInt64(v Int8) error
- func (n *Numeric) ScanNumeric(v Numeric) error
- func (n *Numeric) UnmarshalJSON(src []byte) error
- func (n Numeric) Value() (driver.Value, error)
- type NumericCodec
- 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
- type NumericValuer
- type Path
- type PathCodec
- 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
- type PathValuer
- type Point
- type PointCodec
- 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
- type PointValuer
- type Polygon
- type PolygonCodec
- 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
- type PolygonValuer
- type PreallocBytes
- type QCharCodec
- 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
- type Range
- type RangeCodec
- 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
- type RangeScanner
- type RangeValuer
- type RecordCodec
- 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
- type ScanPlan
- type SkipUnderlyingTypePlanner
- type TID
- type TIDCodec
- 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
- type TIDValuer
- type Text
- type TextCodec
- 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
- type TextScanner
- type TextValuer
- type Time
- type TimeCodec
- 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
- type TimeValuer
- type Timestamp
- type TimestampCodec
- 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
- type TimestampValuer
- type Timestamptz
- func (tstz Timestamptz) MarshalJSON() ([]byte, error)
- func (tstz *Timestamptz) Scan(src any) error
- 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)
- type TimestamptzCodec
- 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
- type TimestamptzValuer
- type TryWrapEncodePlanFunc
- type TryWrapScanPlanFunc
- type Type
- type UUID
- type UUIDCodec
- 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
- type UUIDValuer
- type Uint32
- type Uint32Codec
- 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
- type Uint32Valuer
- type UndecodedBytes
- type Vec2
- type WrappedEncodePlanNextSetter
- func TryWrapArrayEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
- func TryWrapBuiltinTypeEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
- func TryWrapDerefPointerEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
- func TryWrapFindUnderlyingTypeEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
- 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)
- type WrappedScanPlanNextSetter
- func TryFindUnderlyingTypeScanPlan(dst any) (plan WrappedScanPlanNextSetter, nextDst any, ok bool)
- func TryPointerPointerScanPlan(target any) (plan WrappedScanPlanNextSetter, nextTarget any, ok bool)
- func TryWrapBuiltinTypeScanPlan(target any) (plan WrappedScanPlanNextSetter, nextDst any, ok bool)
- func TryWrapPtrArrayScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
- func TryWrapPtrMultiDimSliceScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
- func TryWrapPtrSliceScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
- func TryWrapStructScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
Examples ¶
Constants ¶
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 = 1003 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 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 oids for common types
const ( TextFormatCode = 0 BinaryFormatCode = 1 )
PostgreSQL format codes
const ( Inclusive = BoundType('i') Exclusive = BoundType('e') Unbounded = BoundType('U') Empty = BoundType('E') )
Variables ¶
var ErrScanTargetTypeChanged = errors.New("scan target type changed")
Functions ¶
func GetAssignToDstType ¶
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 ¶
Types ¶
type Array ¶
type Array[T any] struct { Elements []T Dims []ArrayDimension Valid bool }
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.
func (Array[T]) Dimensions ¶
func (a Array[T]) Dimensions() []ArrayDimension
func (Array[T]) ScanIndexType ¶
func (*Array[T]) SetDimensions ¶
func (a *Array[T]) SetDimensions(dimensions []ArrayDimension) error
type ArrayCodec ¶
type ArrayCodec struct {
ElementType *Type
}
ArrayCodec is a codec for any array type.
func (*ArrayCodec) DecodeDatabaseSQLValue ¶
func (*ArrayCodec) DecodeValue ¶
func (*ArrayCodec) FormatSupported ¶
func (c *ArrayCodec) FormatSupported(format int16) bool
func (*ArrayCodec) PlanEncode ¶
func (c *ArrayCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (*ArrayCodec) PreferredFormat ¶
func (c *ArrayCodec) PreferredFormat() int16
type ArrayDimension ¶
type ArrayGetter ¶
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 }
ArrayGetter is a type that can be converted into a PostgreSQL array.
type ArraySetter ¶
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 }
ArraySetter is a type can be set from a PostgreSQL array.
type Bits ¶
Bits represents the PostgreSQL bit and varbit types.
type BitsCodec ¶
type BitsCodec struct{}
func (BitsCodec) DecodeDatabaseSQLValue ¶
func (BitsCodec) DecodeValue ¶
func (BitsCodec) FormatSupported ¶
func (BitsCodec) PlanEncode ¶
func (BitsCodec) PreferredFormat ¶
type BitsScanner ¶
type BitsValuer ¶
type Bool ¶
func (Bool) MarshalJSON ¶
func (*Bool) UnmarshalJSON ¶
type BoolCodec ¶
type BoolCodec struct{}
func (BoolCodec) DecodeDatabaseSQLValue ¶
func (BoolCodec) DecodeValue ¶
func (BoolCodec) FormatSupported ¶
func (BoolCodec) PlanEncode ¶
func (BoolCodec) PreferredFormat ¶
type BoolScanner ¶
type BoolValuer ¶
type BoxCodec ¶
type BoxCodec struct{}
func (BoxCodec) DecodeDatabaseSQLValue ¶
func (BoxCodec) DecodeValue ¶
func (BoxCodec) FormatSupported ¶
func (BoxCodec) PlanEncode ¶
func (BoxCodec) PreferredFormat ¶
type BoxScanner ¶
type ByteaCodec ¶
type ByteaCodec struct{}
func (ByteaCodec) DecodeDatabaseSQLValue ¶
func (ByteaCodec) DecodeValue ¶
func (ByteaCodec) FormatSupported ¶
func (ByteaCodec) FormatSupported(format int16) bool
func (ByteaCodec) PlanEncode ¶
func (ByteaCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (ByteaCodec) PreferredFormat ¶
func (ByteaCodec) PreferredFormat() int16
type BytesScanner ¶
type BytesValuer ¶
type Circle ¶
func (Circle) CircleValue ¶
func (*Circle) ScanCircle ¶
type CircleCodec ¶
type CircleCodec struct{}
func (CircleCodec) DecodeDatabaseSQLValue ¶
func (CircleCodec) DecodeValue ¶
func (CircleCodec) FormatSupported ¶
func (CircleCodec) FormatSupported(format int16) bool
func (CircleCodec) PlanEncode ¶
func (CircleCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (CircleCodec) PreferredFormat ¶
func (CircleCodec) PreferredFormat() int16
type CircleScanner ¶
type CircleValuer ¶
type Codec ¶
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) }
A Codec converts between Go and PostgreSQL values.
type CompositeBinaryBuilder ¶
type CompositeBinaryBuilder struct {
// contains filtered or unexported fields
}
func NewCompositeBinaryBuilder ¶
func NewCompositeBinaryBuilder(m *Map, buf []byte) *CompositeBinaryBuilder
func (*CompositeBinaryBuilder) AppendValue ¶
func (b *CompositeBinaryBuilder) AppendValue(oid uint32, field any)
func (*CompositeBinaryBuilder) Finish ¶
func (b *CompositeBinaryBuilder) Finish() ([]byte, error)
type CompositeBinaryScanner ¶
type CompositeBinaryScanner struct {
// contains filtered or unexported fields
}
func NewCompositeBinaryScanner ¶
func NewCompositeBinaryScanner(m *Map, src []byte) *CompositeBinaryScanner
NewCompositeBinaryScanner a scanner over a binary encoded composite balue.
func (*CompositeBinaryScanner) Bytes ¶
func (cfs *CompositeBinaryScanner) Bytes() []byte
Bytes returns the bytes of the field most recently read by Scan().
func (*CompositeBinaryScanner) Err ¶
func (cfs *CompositeBinaryScanner) Err() error
Err returns any error encountered by the scanner.
func (*CompositeBinaryScanner) FieldCount ¶
func (cfs *CompositeBinaryScanner) FieldCount() int
func (*CompositeBinaryScanner) Next ¶
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 (*CompositeBinaryScanner) OID ¶
func (cfs *CompositeBinaryScanner) OID() uint32
OID returns the OID of the field most recently read by Scan().
type CompositeCodec ¶
type CompositeCodec struct {
Fields []CompositeCodecField
}
func (*CompositeCodec) DecodeDatabaseSQLValue ¶
func (*CompositeCodec) DecodeValue ¶
func (*CompositeCodec) FormatSupported ¶
func (c *CompositeCodec) FormatSupported(format int16) bool
func (*CompositeCodec) PlanEncode ¶
func (c *CompositeCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (*CompositeCodec) PreferredFormat ¶
func (c *CompositeCodec) PreferredFormat() int16
type CompositeCodecField ¶
type CompositeFields ¶
type CompositeFields []any
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.
func (CompositeFields) Index ¶
func (cf CompositeFields) Index(i int) any
func (CompositeFields) IsNull ¶
func (cf CompositeFields) IsNull() bool
func (CompositeFields) ScanIndex ¶
func (cf CompositeFields) ScanIndex(i int) any
func (CompositeFields) ScanNull ¶
func (cf CompositeFields) ScanNull() error
func (CompositeFields) SkipUnderlyingTypePlan ¶
func (cf CompositeFields) SkipUnderlyingTypePlan()
type CompositeIndexGetter ¶
type CompositeIndexGetter interface { // IsNull returns true if the value is SQL NULL. IsNull() bool // Index returns the element at i. Index(i int) any }
CompositeIndexGetter is a type accessed by index that can be converted into a PostgreSQL composite.
type CompositeIndexScanner ¶
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 }
CompositeIndexScanner is a type accessed by index that can be scanned from a PostgreSQL composite.
type CompositeTextBuilder ¶
type CompositeTextBuilder struct {
// contains filtered or unexported fields
}
func NewCompositeTextBuilder ¶
func NewCompositeTextBuilder(m *Map, buf []byte) *CompositeTextBuilder
func (*CompositeTextBuilder) AppendValue ¶
func (b *CompositeTextBuilder) AppendValue(oid uint32, field any)
func (*CompositeTextBuilder) Finish ¶
func (b *CompositeTextBuilder) Finish() ([]byte, error)
type CompositeTextScanner ¶
type CompositeTextScanner struct {
// contains filtered or unexported fields
}
func NewCompositeTextScanner ¶
func NewCompositeTextScanner(m *Map, src []byte) *CompositeTextScanner
NewCompositeTextScanner a scanner over a text encoded composite value.
func (*CompositeTextScanner) Bytes ¶
func (cfs *CompositeTextScanner) Bytes() []byte
Bytes returns the bytes of the field most recently read by Scan().
func (*CompositeTextScanner) Err ¶
func (cfs *CompositeTextScanner) Err() error
Err returns any error encountered by the scanner.
func (*CompositeTextScanner) Next ¶
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 ¶
type Date struct { Time time.Time InfinityModifier InfinityModifier Valid bool }
func (Date) MarshalJSON ¶
func (*Date) UnmarshalJSON ¶
type DateCodec ¶
type DateCodec struct{}
func (DateCodec) DecodeDatabaseSQLValue ¶
func (DateCodec) DecodeValue ¶
func (DateCodec) FormatSupported ¶
func (DateCodec) PlanEncode ¶
func (DateCodec) PreferredFormat ¶
type DateScanner ¶
type DateValuer ¶
type DriverBytes ¶
type DriverBytes []byte
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.
func (*DriverBytes) ScanBytes ¶
func (b *DriverBytes) ScanBytes(v []byte) error
type EncodePlan ¶
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) }
EncodePlan is a precompiled plan to encode a particular type into a particular OID and format.
type EnumCodec ¶
type EnumCodec struct {
// contains filtered or unexported fields
}
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.
func (*EnumCodec) DecodeDatabaseSQLValue ¶
func (*EnumCodec) DecodeValue ¶
func (EnumCodec) FormatSupported ¶
func (EnumCodec) PlanEncode ¶
func (EnumCodec) PreferredFormat ¶
type FlatArray ¶
type FlatArray[T any] []T
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.
func (FlatArray[T]) Dimensions ¶
func (a FlatArray[T]) Dimensions() []ArrayDimension
func (FlatArray[T]) ScanIndexType ¶
func (*FlatArray[T]) SetDimensions ¶
func (a *FlatArray[T]) SetDimensions(dimensions []ArrayDimension) error
type Float4 ¶
func (Float4) Float64Value ¶
func (Float4) Int64Value ¶
func (*Float4) ScanFloat64 ¶
ScanFloat64 implements the Float64Scanner interface.
type Float4Codec ¶
type Float4Codec struct{}
func (Float4Codec) DecodeDatabaseSQLValue ¶
func (Float4Codec) DecodeValue ¶
func (Float4Codec) FormatSupported ¶
func (Float4Codec) FormatSupported(format int16) bool
func (Float4Codec) PlanEncode ¶
func (Float4Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Float4Codec) PreferredFormat ¶
func (Float4Codec) PreferredFormat() int16
type Float64Scanner ¶
type Float64Valuer ¶
type Float8 ¶
func (Float8) Float64Value ¶
func (Float8) Int64Value ¶
func (*Float8) MarshalJSON ¶
func (*Float8) ScanFloat64 ¶
ScanFloat64 implements the Float64Scanner interface.
type Float8Codec ¶
type Float8Codec struct{}
func (Float8Codec) DecodeDatabaseSQLValue ¶
func (Float8Codec) DecodeValue ¶
func (Float8Codec) FormatSupported ¶
func (Float8Codec) FormatSupported(format int16) bool
func (Float8Codec) PlanEncode ¶
func (Float8Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Float8Codec) PreferredFormat ¶
func (Float8Codec) PreferredFormat() int16
type Hstore ¶
Hstore represents an hstore column that can be null or have null values associated with its keys.
func (Hstore) HstoreValue ¶
func (*Hstore) ScanHstore ¶
type HstoreCodec ¶
type HstoreCodec struct{}
func (HstoreCodec) DecodeDatabaseSQLValue ¶
func (HstoreCodec) DecodeValue ¶
func (HstoreCodec) FormatSupported ¶
func (HstoreCodec) FormatSupported(format int16) bool
func (HstoreCodec) PlanEncode ¶
func (HstoreCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (HstoreCodec) PreferredFormat ¶
func (HstoreCodec) PreferredFormat() int16
type HstoreScanner ¶
type HstoreValuer ¶
type InetCodec ¶
type InetCodec struct{}
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.
func (InetCodec) DecodeDatabaseSQLValue ¶
func (InetCodec) DecodeValue ¶
func (InetCodec) FormatSupported ¶
func (InetCodec) PlanEncode ¶
func (InetCodec) PreferredFormat ¶
type InfinityModifier ¶
type InfinityModifier int8
const ( Infinity InfinityModifier = 1 Finite InfinityModifier = 0 NegativeInfinity InfinityModifier = -Infinity )
func (InfinityModifier) String ¶
func (im InfinityModifier) String() string
type Int2 ¶
func (Int2) Int64Value ¶
func (Int2) MarshalJSON ¶
func (*Int2) UnmarshalJSON ¶
type Int2Codec ¶
type Int2Codec struct{}
func (Int2Codec) DecodeDatabaseSQLValue ¶
func (Int2Codec) DecodeValue ¶
func (Int2Codec) FormatSupported ¶
func (Int2Codec) PlanEncode ¶
func (Int2Codec) PreferredFormat ¶
type Int4 ¶
func (Int4) Int64Value ¶
func (Int4) MarshalJSON ¶
func (*Int4) UnmarshalJSON ¶
type Int4Codec ¶
type Int4Codec struct{}
func (Int4Codec) DecodeDatabaseSQLValue ¶
func (Int4Codec) DecodeValue ¶
func (Int4Codec) FormatSupported ¶
func (Int4Codec) PlanEncode ¶
func (Int4Codec) PreferredFormat ¶
type Int64Scanner ¶
type Int64Valuer ¶
type Int8 ¶
func (Int8) Int64Value ¶
func (Int8) MarshalJSON ¶
func (*Int8) UnmarshalJSON ¶
type Int8Codec ¶
type Int8Codec struct{}
func (Int8Codec) DecodeDatabaseSQLValue ¶
func (Int8Codec) DecodeValue ¶
func (Int8Codec) FormatSupported ¶
func (Int8Codec) PlanEncode ¶
func (Int8Codec) PreferredFormat ¶
type Interval ¶
func (Interval) IntervalValue ¶
func (*Interval) ScanInterval ¶
type IntervalCodec ¶
type IntervalCodec struct{}
func (IntervalCodec) DecodeDatabaseSQLValue ¶
func (IntervalCodec) DecodeValue ¶
func (IntervalCodec) FormatSupported ¶
func (IntervalCodec) FormatSupported(format int16) bool
func (IntervalCodec) PlanEncode ¶
func (IntervalCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (IntervalCodec) PreferredFormat ¶
func (IntervalCodec) PreferredFormat() int16
type IntervalScanner ¶
type IntervalValuer ¶
type JSONBCodec ¶
type JSONBCodec struct{}
func (JSONBCodec) DecodeDatabaseSQLValue ¶
func (JSONBCodec) DecodeValue ¶
func (JSONBCodec) FormatSupported ¶
func (JSONBCodec) FormatSupported(format int16) bool
func (JSONBCodec) PlanEncode ¶
func (JSONBCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (JSONBCodec) PreferredFormat ¶
func (JSONBCodec) PreferredFormat() int16
type JSONCodec ¶
type JSONCodec struct{}
func (JSONCodec) DecodeDatabaseSQLValue ¶
func (JSONCodec) DecodeValue ¶
func (JSONCodec) FormatSupported ¶
func (JSONCodec) PlanEncode ¶
func (JSONCodec) PreferredFormat ¶
type LineCodec ¶
type LineCodec struct{}
func (LineCodec) DecodeDatabaseSQLValue ¶
func (LineCodec) DecodeValue ¶
func (LineCodec) FormatSupported ¶
func (LineCodec) PlanEncode ¶
func (LineCodec) PreferredFormat ¶
type LineScanner ¶
type LineValuer ¶
type LsegCodec ¶
type LsegCodec struct{}
func (LsegCodec) DecodeDatabaseSQLValue ¶
func (LsegCodec) DecodeValue ¶
func (LsegCodec) FormatSupported ¶
func (LsegCodec) PlanEncode ¶
func (LsegCodec) PreferredFormat ¶
type LsegScanner ¶
type LsegValuer ¶
type MacaddrCodec ¶
type MacaddrCodec struct{}
func (MacaddrCodec) DecodeDatabaseSQLValue ¶
func (MacaddrCodec) DecodeValue ¶
func (MacaddrCodec) FormatSupported ¶
func (MacaddrCodec) FormatSupported(format int16) bool
func (MacaddrCodec) PlanEncode ¶
func (MacaddrCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (MacaddrCodec) PreferredFormat ¶
func (MacaddrCodec) PreferredFormat() int16
type Map ¶
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 }
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.
func (*Map) Encode ¶
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 (*Map) FormatCodeForOID ¶
FormatCodeForOID returns the preferred format code for type oid. If the type is not registered it returns the text format code.
func (*Map) PlanEncode ¶
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 (*Map) RegisterDefaultPgType ¶
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 (*Map) RegisterType ¶
func (*Map) SQLScanner ¶
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.
type Multirange ¶
type Multirange[T RangeValuer] []T
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.
func (Multirange[T]) Index ¶
func (r Multirange[T]) Index(i int) any
func (Multirange[T]) IndexType ¶
func (r Multirange[T]) IndexType() any
func (Multirange[T]) IsNull ¶
func (r Multirange[T]) IsNull() bool
func (Multirange[T]) Len ¶
func (r Multirange[T]) Len() int
func (Multirange[T]) ScanIndex ¶
func (r Multirange[T]) ScanIndex(i int) any
func (Multirange[T]) ScanIndexType ¶
func (r Multirange[T]) ScanIndexType() any
func (*Multirange[T]) ScanNull ¶
func (r *Multirange[T]) ScanNull() error
func (*Multirange[T]) SetLen ¶
func (r *Multirange[T]) SetLen(n int) error
type MultirangeCodec ¶
type MultirangeCodec struct {
ElementType *Type
}
MultirangeCodec is a codec for any multirange type.
func (*MultirangeCodec) DecodeDatabaseSQLValue ¶
func (*MultirangeCodec) DecodeValue ¶
func (*MultirangeCodec) FormatSupported ¶
func (c *MultirangeCodec) FormatSupported(format int16) bool
func (*MultirangeCodec) PlanEncode ¶
func (c *MultirangeCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (*MultirangeCodec) PreferredFormat ¶
func (c *MultirangeCodec) PreferredFormat() int16
type MultirangeGetter ¶
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 }
MultirangeGetter is a type that can be converted into a PostgreSQL multirange.
type MultirangeSetter ¶
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 }
MultirangeSetter is a type can be set from a PostgreSQL multirange.
type NetipPrefixScanner ¶
type NetipPrefixValuer ¶
type Numeric ¶
type Numeric struct { Int *big.Int Exp int32 NaN bool InfinityModifier InfinityModifier Valid bool }
func (Numeric) Float64Value ¶
func (Numeric) Int64Value ¶
func (Numeric) MarshalJSON ¶
func (Numeric) NumericValue ¶
func (*Numeric) ScanNumeric ¶
func (*Numeric) UnmarshalJSON ¶
type NumericCodec ¶
type NumericCodec struct{}
func (NumericCodec) DecodeDatabaseSQLValue ¶
func (NumericCodec) DecodeValue ¶
func (NumericCodec) FormatSupported ¶
func (NumericCodec) FormatSupported(format int16) bool
func (NumericCodec) PlanEncode ¶
func (NumericCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (NumericCodec) PreferredFormat ¶
func (NumericCodec) PreferredFormat() int16
type NumericScanner ¶
type NumericValuer ¶
type PathCodec ¶
type PathCodec struct{}
func (PathCodec) DecodeDatabaseSQLValue ¶
func (PathCodec) DecodeValue ¶
func (PathCodec) FormatSupported ¶
func (PathCodec) PlanEncode ¶
func (PathCodec) PreferredFormat ¶
type PathScanner ¶
type PathValuer ¶
type Point ¶
func (Point) MarshalJSON ¶
func (Point) PointValue ¶
func (*Point) UnmarshalJSON ¶
type PointCodec ¶
type PointCodec struct{}
func (PointCodec) DecodeDatabaseSQLValue ¶
func (PointCodec) DecodeValue ¶
func (PointCodec) FormatSupported ¶
func (PointCodec) FormatSupported(format int16) bool
func (PointCodec) PlanEncode ¶
func (PointCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (PointCodec) PreferredFormat ¶
func (PointCodec) PreferredFormat() int16
type PointScanner ¶
type PointValuer ¶
type Polygon ¶
func (Polygon) PolygonValue ¶
func (*Polygon) ScanPolygon ¶
type PolygonCodec ¶
type PolygonCodec struct{}
func (PolygonCodec) DecodeDatabaseSQLValue ¶
func (PolygonCodec) DecodeValue ¶
func (PolygonCodec) FormatSupported ¶
func (PolygonCodec) FormatSupported(format int16) bool
func (PolygonCodec) PlanEncode ¶
func (PolygonCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (PolygonCodec) PreferredFormat ¶
func (PolygonCodec) PreferredFormat() int16
type PolygonScanner ¶
type PolygonValuer ¶
type PreallocBytes ¶
type PreallocBytes []byte
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.
func (*PreallocBytes) ScanBytes ¶
func (b *PreallocBytes) ScanBytes(v []byte) error
type QCharCodec ¶
type QCharCodec struct{}
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.
func (QCharCodec) DecodeDatabaseSQLValue ¶
func (QCharCodec) DecodeValue ¶
func (QCharCodec) FormatSupported ¶
func (QCharCodec) FormatSupported(format int16) bool
func (QCharCodec) PlanEncode ¶
func (QCharCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (QCharCodec) PreferredFormat ¶
func (QCharCodec) PreferredFormat() int16
type Range ¶
Range is a generic range type.
func (Range[T]) BoundTypes ¶
func (*Range[T]) ScanBounds ¶
func (*Range[T]) SetBoundTypes ¶
type RangeCodec ¶
type RangeCodec struct {
ElementType *Type
}
RangeCodec is a codec for any range type.
func (*RangeCodec) DecodeDatabaseSQLValue ¶
func (*RangeCodec) DecodeValue ¶
func (*RangeCodec) FormatSupported ¶
func (c *RangeCodec) FormatSupported(format int16) bool
func (*RangeCodec) PlanEncode ¶
func (c *RangeCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (*RangeCodec) PreferredFormat ¶
func (c *RangeCodec) PreferredFormat() int16
type RangeScanner ¶
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 }
RangeScanner is a type can be scanned from a PostgreSQL range.
type RangeValuer ¶
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) }
RangeValuer is a type that can be converted into a PostgreSQL range.
type RecordCodec ¶
type RecordCodec struct{}
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.
func (RecordCodec) DecodeDatabaseSQLValue ¶
func (RecordCodec) DecodeValue ¶
func (RecordCodec) FormatSupported ¶
func (RecordCodec) FormatSupported(format int16) bool
func (RecordCodec) PlanEncode ¶
func (RecordCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (RecordCodec) PreferredFormat ¶
func (RecordCodec) PreferredFormat() int16
type ScanPlan ¶
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 }
ScanPlan is a precompiled plan to scan into a type of destination.
type SkipUnderlyingTypePlanner ¶
type SkipUnderlyingTypePlanner interface {
SkipUnderlyingTypePlan()
}
SkipUnderlyingTypePlanner prevents PlanScan and PlanDecode from trying to use the underlying type.
type TID ¶
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 TIDCodec ¶
type TIDCodec struct{}
func (TIDCodec) DecodeDatabaseSQLValue ¶
func (TIDCodec) DecodeValue ¶
func (TIDCodec) FormatSupported ¶
func (TIDCodec) PlanEncode ¶
func (TIDCodec) PreferredFormat ¶
type TIDScanner ¶
type Text ¶
func (Text) MarshalJSON ¶
func (*Text) UnmarshalJSON ¶
type TextCodec ¶
type TextCodec struct{}
func (TextCodec) DecodeDatabaseSQLValue ¶
func (TextCodec) DecodeValue ¶
func (TextCodec) FormatSupported ¶
func (TextCodec) PlanEncode ¶
func (TextCodec) PreferredFormat ¶
type TextFormatOnlyCodec ¶
type TextFormatOnlyCodec struct {
Codec
}
func (*TextFormatOnlyCodec) FormatSupported ¶
func (c *TextFormatOnlyCodec) FormatSupported(format int16) bool
func (TextFormatOnlyCodec) PreferredFormat ¶
func (TextFormatOnlyCodec) PreferredFormat() int16
type TextScanner ¶
type TextValuer ¶
type Time ¶
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 TimeCodec ¶
type TimeCodec struct{}
func (TimeCodec) DecodeDatabaseSQLValue ¶
func (TimeCodec) DecodeValue ¶
func (TimeCodec) FormatSupported ¶
func (TimeCodec) PlanEncode ¶
func (TimeCodec) PreferredFormat ¶
type TimeScanner ¶
type TimeValuer ¶
type Timestamp ¶
type Timestamp struct { Time time.Time // Time zone will be ignored when encoding to PostgreSQL. InfinityModifier InfinityModifier Valid bool }
Timestamp represents the PostgreSQL timestamp type.
func (*Timestamp) ScanTimestamp ¶
func (Timestamp) TimestampValue ¶
type TimestampCodec ¶
type TimestampCodec struct{}
func (TimestampCodec) DecodeDatabaseSQLValue ¶
func (TimestampCodec) DecodeValue ¶
func (TimestampCodec) FormatSupported ¶
func (TimestampCodec) FormatSupported(format int16) bool
func (TimestampCodec) PlanEncode ¶
func (TimestampCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (TimestampCodec) PreferredFormat ¶
func (TimestampCodec) PreferredFormat() int16
type TimestampScanner ¶
type TimestampValuer ¶
type Timestamptz ¶
type Timestamptz struct { Time time.Time InfinityModifier InfinityModifier Valid bool }
Timestamptz represents the PostgreSQL timestamptz type.
func (Timestamptz) MarshalJSON ¶
func (tstz Timestamptz) MarshalJSON() ([]byte, error)
func (*Timestamptz) Scan ¶
func (tstz *Timestamptz) Scan(src any) error
Scan implements the database/sql Scanner interface.
func (*Timestamptz) ScanTimestamptz ¶
func (tstz *Timestamptz) ScanTimestamptz(v Timestamptz) error
func (Timestamptz) TimestamptzValue ¶
func (tstz Timestamptz) TimestamptzValue() (Timestamptz, error)
func (*Timestamptz) UnmarshalJSON ¶
func (tstz *Timestamptz) UnmarshalJSON(b []byte) error
type TimestamptzCodec ¶
type TimestamptzCodec struct{}
func (TimestamptzCodec) DecodeDatabaseSQLValue ¶
func (TimestamptzCodec) DecodeValue ¶
func (TimestamptzCodec) FormatSupported ¶
func (TimestamptzCodec) FormatSupported(format int16) bool
func (TimestamptzCodec) PlanEncode ¶
func (TimestamptzCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (TimestamptzCodec) PreferredFormat ¶
func (TimestamptzCodec) PreferredFormat() int16
type TimestamptzScanner ¶
type TimestamptzScanner interface {
ScanTimestamptz(v Timestamptz) error
}
type TimestamptzValuer ¶
type TimestamptzValuer interface {
TimestamptzValue() (Timestamptz, error)
}
type TryWrapEncodePlanFunc ¶
type TryWrapEncodePlanFunc func(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
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 TryWrapScanPlanFunc ¶
type TryWrapScanPlanFunc func(target any) (plan WrappedScanPlanNextSetter, nextTarget 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 UUID ¶
func (UUID) MarshalJSON ¶
func (*UUID) UnmarshalJSON ¶
type UUIDCodec ¶
type UUIDCodec struct{}
func (UUIDCodec) DecodeDatabaseSQLValue ¶
func (UUIDCodec) DecodeValue ¶
func (UUIDCodec) FormatSupported ¶
func (UUIDCodec) PlanEncode ¶
func (UUIDCodec) PreferredFormat ¶
type UUIDScanner ¶
type UUIDValuer ¶
type Uint32 ¶
Uint32 is the core type that is used to represent PostgreSQL types such as OID, CID, and XID.
func (*Uint32) ScanUint32 ¶
func (Uint32) Uint32Value ¶
type Uint32Codec ¶
type Uint32Codec struct{}
func (Uint32Codec) DecodeDatabaseSQLValue ¶
func (Uint32Codec) DecodeValue ¶
func (Uint32Codec) FormatSupported ¶
func (Uint32Codec) FormatSupported(format int16) bool
func (Uint32Codec) PlanEncode ¶
func (Uint32Codec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodePlan
func (Uint32Codec) PreferredFormat ¶
func (Uint32Codec) PreferredFormat() int16
type Uint32Scanner ¶
type Uint32Valuer ¶
type UndecodedBytes ¶
type UndecodedBytes []byte
UndecodedBytes can be used as a scan target to get the raw bytes from PostgreSQL without any decoding.
type WrappedEncodePlanNextSetter ¶
type WrappedEncodePlanNextSetter interface { SetNext(EncodePlan) EncodePlan }
func TryWrapArrayEncodePlan ¶
func TryWrapArrayEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
func TryWrapBuiltinTypeEncodePlan ¶
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 ¶
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 ¶
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 ¶
func TryWrapMultiDimSliceEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
func TryWrapSliceEncodePlan ¶
func TryWrapSliceEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
func TryWrapStructEncodePlan ¶
func TryWrapStructEncodePlan(value any) (plan WrappedEncodePlanNextSetter, nextValue any, ok bool)
TryWrapStructPlan tries to wrap a struct with a wrapper that implements CompositeIndexGetter.
type WrappedScanPlanNextSetter ¶
func TryFindUnderlyingTypeScanPlan ¶
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 ¶
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 ¶
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 ¶
func TryWrapPtrArrayScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
TryWrapPtrArrayScanPlan tries to wrap a pointer to a single dimension array.
func TryWrapPtrMultiDimSliceScanPlan ¶
func TryWrapPtrMultiDimSliceScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
TryWrapPtrMultiDimSliceScanPlan tries to wrap a pointer to a multi-dimension slice.
func TryWrapPtrSliceScanPlan ¶
func TryWrapPtrSliceScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
TryWrapPtrSliceScanPlan tries to wrap a pointer to a single dimension slice.
func TryWrapStructScanPlan ¶
func TryWrapStructScanPlan(target any) (plan WrappedScanPlanNextSetter, nextValue any, ok bool)
TryWrapStructPlan tries to wrap a struct with a wrapper that implements CompositeIndexGetter.
Source Files ¶
- array.go
- array_codec.go
- bits.go
- bool.go
- box.go
- builtin_wrappers.go
- bytea.go
- circle.go
- composite.go
- convert.go
- date.go
- doc.go
- enum_codec.go
- float4.go
- float8.go
- hstore.go
- inet.go
- int.go
- interval.go
- json.go
- jsonb.go
- line.go
- lseg.go
- macaddr.go
- multirange.go
- numeric.go
- path.go
- pgtype.go
- point.go
- polygon.go
- qchar.go
- range.go
- range_codec.go
- record_codec.go
- register_default_pg_types.go
- text.go
- text_format_only_codec.go
- tid.go
- time.go
- timestamp.go
- timestamptz.go
- uint32.go
- uuid.go