pgxt

package
v0.0.0-...-bcb87c1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToUrl

func ConnectToUrl(url string, opts ...func(*pgxpool.Config)) (*pgxpool.Pool, error)

ConnectToUrl opens a connection pool using the given URL.

func GetScalar

func GetScalar[T any](ctx context.Context, db IQueryRow, stmt string, args ...any) (T, error)

GetScalar returns a value like int(123) from the query "SELECT 123".

func GetScalars

func GetScalars[T any](ctx context.Context, db IQuery, stmt string, args ...any) ([]T, error)

GetScalars returns a slice like []int{123, 123} from the query "SELECT 123 FROM generate_series(0,1)".

func LogIgnore

func LogIgnore(ctx context.Context) context.Context

func LogUnignore

func LogUnignore(ctx context.Context) context.Context

func WithTransaction

func WithTransaction(ctx context.Context, db IBegin, cb func(pgx.Tx) error) error

Types

type IBegin

type IBegin interface {
	Begin(context.Context) (pgx.Tx, error)
}

type IExec

type IExec interface {
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
}

type IQuery

type IQuery interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}

type IQueryRow

type IQueryRow interface {
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

type LoggingTracer

type LoggingTracer struct{}

LoggingTracer logs all SQL statements to the logger in the context, using logctx.Logger. Or add Ignore into the context to skip logging, like when calling River. Until River supports some alternative context factory or similar, there's not much we can do. See https://github.com/riverqueue/river/issues/511 for more info.

func NewLoggingTracer

func NewLoggingTracer() *LoggingTracer

func (*LoggingTracer) TraceQueryEnd

func (lt *LoggingTracer) TraceQueryEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryEndData)

func (*LoggingTracer) TraceQueryStart

func (lt *LoggingTracer) TraceQueryStart(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryStartData) context.Context

type LoggingTracerCtxKey

type LoggingTracerCtxKey string
const Ignore LoggingTracerCtxKey = "pgxt.loggingtracer.ignore"

Jump to

Keyboard shortcuts

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