pgxpool

package
v0.0.0-...-a66760f Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConnStr

func GetConnStr(opts PgxpoolOptions) string

func NewPgxTracer

func NewPgxTracer() pgx.QueryTracer

func NewPgxpool

func NewPgxpool(opts PgxpoolOptions) (*pgxpool.Pool, error)

Types

type DBRouter

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

DBRouter wrapper that routes queries to appropriate pools based on operation type

func NewDBRouter

func NewDBRouter(readPool, writePool DBTX) *DBRouter

NewDBRouter creates a new DBRouter database wrapper

func (*DBRouter) Begin

func (c *DBRouter) Begin(ctx context.Context) (pgx.Tx, error)

Begin starts a transaction Transactions can contain both read and write operations, so we use the write pool to ensure consistency and avoid potential issues with read replicas

func (*DBRouter) CopyFrom

func (c *DBRouter) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

CopyFrom uses COPY protocol to insert multiple rows This is always a write operation, so it uses the write pool

func (*DBRouter) Exec

func (c *DBRouter) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)

Exec executes a query without returning any rows

func (*DBRouter) Query

func (c *DBRouter) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query executes a query that returns rows

func (*DBRouter) QueryRow

func (c *DBRouter) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

QueryRow executes a query that is expected to return at most one row

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

	Begin(context.Context) (pgx.Tx, error)
}

type PgxpoolOptions

type PgxpoolOptions struct {
	Url             string `yaml:"url"`
	Host            string `yaml:"host"`
	Port            int    `yaml:"port"`
	Username        string `yaml:"username"`
	Password        string `yaml:"password"`
	Database        string `yaml:"database"`
	MaxConnections  int32  `yaml:"maxConnections"`
	MaxConnIdleTime int32  `yaml:"maxConnIdleTime"`
}

type QueryLogger

type QueryLogger struct{}

func (*QueryLogger) TraceQueryEnd

func (ql *QueryLogger) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryEndData)

func (*QueryLogger) TraceQueryStart

func (ql *QueryLogger) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context

type TraceData

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

Jump to

Keyboard shortcuts

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