pgctx

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 5 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Committed

func Committed(ctx context.Context, f func(ctx context.Context))

Committed calls f after committed or immediate if not in tx

func Exec

func Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

Exec calls db.ExecContext

func GetTx added in v0.11.0

func GetTx(ctx context.Context) *sql.Tx

func IsInTx added in v0.6.0

func IsInTx(ctx context.Context) bool

IsInTx checks is context inside RunInTx

func Iter added in v0.5.0

func Iter(ctx context.Context, iter pgsql.Iterator, query string, args ...any) error

Iter calls pgsql.IterContext

func KeyMiddleware added in v0.10.0

func KeyMiddleware(key any, db DB) func(h http.Handler) http.Handler

func Middleware

func Middleware(db DB) func(h http.Handler) http.Handler

Middleware injects db into request's context

func NewContext

func NewContext(ctx context.Context, db DB) context.Context

NewContext creates new context

func NewKeyContext added in v0.10.0

func NewKeyContext(ctx context.Context, key any, db DB) context.Context

func Prepare added in v0.5.0

func Prepare(ctx context.Context, query string) (*sql.Stmt, error)

Prepare calls db.PrepareContext

func Query

func Query(ctx context.Context, query string, args ...any) (*pgsql.Rows, error)

Query calls db.QueryContext

func QueryRow

func QueryRow(ctx context.Context, query string, args ...any) *pgsql.Row

QueryRow calls db.QueryRowContext

func RunInReadOnlyTx added in v0.13.0

func RunInReadOnlyTx(ctx context.Context, f func(ctx context.Context) error) error

RunInReadOnlyTx calls RunInTxOptions with read only options

func RunInTx

func RunInTx(ctx context.Context, f func(ctx context.Context) error) error

RunInTx calls RunInTxOptions with default options

func RunInTxOptions added in v0.8.4

func RunInTxOptions(ctx context.Context, opt *pgsql.TxOptions, f func(ctx context.Context) error) error

RunInTxOptions starts sql tx if not started

func With added in v0.10.0

func With(ctx context.Context, key any) context.Context

With creates new empty key context with db from keyed context

Types

type DB

type DB interface {
	Queryer
	pgsql.BeginTxer
}

func GetDB added in v0.11.0

func GetDB(ctx context.Context) DB

func GetDBKey added in v0.11.0

func GetDBKey(ctx context.Context, key any) DB

type Queryer

type Queryer interface {
	QueryRowContext(context.Context, string, ...any) *sql.Row
	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
	ExecContext(context.Context, string, ...any) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
}

Queryer interface

Jump to

Keyboard shortcuts

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