custom_types

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTypes added in v0.0.3

func RegisterTypes(ctx context.Context, conn *pgx.Conn) error

RegisterTypes registers custom Postgres types (composites and enums) with the pgx connection's TypeMap so that they can be scanned and encoded correctly. Call this once per connection after connecting.

For pgxpool.Pool, use config.AfterConnect:

config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
	return RegisterTypes(ctx, conn)
}

Types

type CustomInt

type CustomInt int

CustomInt is a custom type in the same package as the query file.

type CustomTypesRow

type CustomTypesRow struct {
	Column mytype.String `json:"?column?"`
	Int8   CustomInt     `json:"int8"`
}

type DBQuerier

type DBQuerier struct {
	// contains filtered or unexported fields
}

func NewQuerier

func NewQuerier(conn genericConn) *DBQuerier

NewQuerier creates a DBQuerier that implements Querier. conn is typically *pgx.Conn, pgx.Tx, or *pgxpool.Pool.

func (*DBQuerier) CustomMyInt

func (q *DBQuerier) CustomMyInt(ctx context.Context) (int, error)

CustomMyInt implements Querier.CustomMyInt.

func (*DBQuerier) CustomMyIntBatch

func (q *DBQuerier) CustomMyIntBatch(batch genericBatch)

CustomMyIntBatch implements Querier.CustomMyIntBatch.

func (*DBQuerier) CustomMyIntScan

func (q *DBQuerier) CustomMyIntScan(results pgx.BatchResults) (int, error)

CustomMyIntScan implements Querier.CustomMyIntScan.

func (*DBQuerier) CustomTypes

func (q *DBQuerier) CustomTypes(ctx context.Context) (CustomTypesRow, error)

CustomTypes implements Querier.CustomTypes.

func (*DBQuerier) CustomTypesBatch

func (q *DBQuerier) CustomTypesBatch(batch genericBatch)

CustomTypesBatch implements Querier.CustomTypesBatch.

func (*DBQuerier) CustomTypesScan

func (q *DBQuerier) CustomTypesScan(results pgx.BatchResults) (CustomTypesRow, error)

CustomTypesScan implements Querier.CustomTypesScan.

func (*DBQuerier) IntArray

func (q *DBQuerier) IntArray(ctx context.Context) ([][]int32, error)

IntArray implements Querier.IntArray.

func (*DBQuerier) IntArrayBatch

func (q *DBQuerier) IntArrayBatch(batch genericBatch)

IntArrayBatch implements Querier.IntArrayBatch.

func (*DBQuerier) IntArrayScan

func (q *DBQuerier) IntArrayScan(results pgx.BatchResults) ([][]int32, error)

IntArrayScan implements Querier.IntArrayScan.

type Querier

type Querier interface {
	CustomTypes(ctx context.Context) (CustomTypesRow, error)
	// CustomTypesBatch enqueues a CustomTypes query into batch to be executed
	// later by the batch.
	CustomTypesBatch(batch genericBatch)
	// CustomTypesScan scans the result of an executed CustomTypesBatch query.
	CustomTypesScan(results pgx.BatchResults) (CustomTypesRow, error)

	CustomMyInt(ctx context.Context) (int, error)
	// CustomMyIntBatch enqueues a CustomMyInt query into batch to be executed
	// later by the batch.
	CustomMyIntBatch(batch genericBatch)
	// CustomMyIntScan scans the result of an executed CustomMyIntBatch query.
	CustomMyIntScan(results pgx.BatchResults) (int, error)

	IntArray(ctx context.Context) ([][]int32, error)
	// IntArrayBatch enqueues a IntArray query into batch to be executed
	// later by the batch.
	IntArrayBatch(batch genericBatch)
	// IntArrayScan scans the result of an executed IntArrayBatch query.
	IntArrayScan(results pgx.BatchResults) ([][]int32, error)
}

Querier is a typesafe Go interface backed by SQL queries.

Methods ending with Batch enqueue a query to run later in a pgx.Batch. After calling SendBatch on pgx.Conn, pgxpool.Pool, or pgx.Tx, use the Scan methods to parse the results.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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