pgxexec

package module
v0.0.0-...-591bdfc Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package pgxexec is the sqlkit.Executor over jackc/pgx.

It runs statements through a *pgxpool.Pool, or through the pgx.Tx a context carries, with the transaction contract every executor shares. pgx speaks only PostgreSQL, so the executor's dialect is always sqlkit.PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithTx

func ContextWithTx(ctx context.Context, tx pgx.Tx) context.Context

ContextWithTx returns a context carrying an open pgx transaction, so that a caller that began one itself can have the executor join it. The executor uses this transaction and neither commits nor rolls it back.

The key is this package's own, so a transaction a task store carries is not visible here. A host that wants one transaction across both reads it from the store's context and passes it here.

func TxFromContext

func TxFromContext(ctx context.Context) (pgx.Tx, bool)

TxFromContext returns the transaction active on a context, if any.

Types

type Executor

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

Executor runs statements through a pgx pool, or through the pgx.Tx a context carries.

func New

func New(pool *pgxpool.Pool) (*Executor, error)

New returns an executor over a pgx pool. A nil pool is a configuration error. It does not connect: the pool dials when a statement first needs it.

func (*Executor) Dialect

func (e *Executor) Dialect() sqlkit.Dialect

Dialect implements sqlkit.Executor. It is always sqlkit.PostgreSQL.

func (*Executor) Do

func (e *Executor) Do(ctx context.Context, fn func(ctx context.Context) error) error

Do implements sqlkit.Executor.

A nested call joins and flattens rather than opening the savepoint that pgx.Tx.Begin would give.

func (*Executor) Exec

func (e *Executor) Exec(ctx context.Context, statement sqlkit.Statement) (int64, error)

Exec implements sqlkit.Executor.

func (*Executor) ExecStatement

func (e *Executor) ExecStatement(ctx context.Context, sql string, args ...any) error

ExecStatement implements sqlkit.Execer.

func (*Executor) InTransaction

func (e *Executor) InTransaction(ctx context.Context) bool

InTransaction implements sqlkit.Executor.

func (*Executor) Pool

func (e *Executor) Pool() *pgxpool.Pool

Pool returns the underlying pool.

func (*Executor) Query

func (e *Executor) Query(ctx context.Context, statement sqlkit.Statement, scan func(rows sqlkit.Rows) error) error

Query implements sqlkit.Executor.

pgx reports most server errors on the rows rather than from Query itself, so the rows' error is checked after they are closed, whether or not scan read them.

func (*Executor) QueryStatement

func (e *Executor) QueryStatement(ctx context.Context, sql string, args ...any) (sqlkit.Rows, error)

QueryStatement implements sqlkit.Querier.

Jump to

Keyboard shortcuts

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