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 ¶
- func ContextWithTx(ctx context.Context, tx pgx.Tx) context.Context
- func TxFromContext(ctx context.Context) (pgx.Tx, bool)
- type Executor
- func (e *Executor) Dialect() sqlkit.Dialect
- func (e *Executor) Do(ctx context.Context, fn func(ctx context.Context) error) error
- func (e *Executor) Exec(ctx context.Context, statement sqlkit.Statement) (int64, error)
- func (e *Executor) ExecStatement(ctx context.Context, sql string, args ...any) error
- func (e *Executor) InTransaction(ctx context.Context) bool
- func (e *Executor) Pool() *pgxpool.Pool
- func (e *Executor) Query(ctx context.Context, statement sqlkit.Statement, ...) error
- func (e *Executor) QueryStatement(ctx context.Context, sql string, args ...any) (sqlkit.Rows, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithTx ¶
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.
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 ¶
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 ¶
Dialect implements sqlkit.Executor. It is always sqlkit.PostgreSQL.
func (*Executor) Do ¶
Do implements sqlkit.Executor.
A nested call joins and flattens rather than opening the savepoint that pgx.Tx.Begin would give.
func (*Executor) Exec ¶
Exec implements sqlkit.Executor.
func (*Executor) ExecStatement ¶
ExecStatement implements sqlkit.Execer.
func (*Executor) InTransaction ¶
InTransaction implements sqlkit.Executor.
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.