pgxhook

package module
v0.0.0-...-30718cf Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 3 Imported by: 0

README

pgxhook

hooks for pgx

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterHook

type AfterHook interface {
	After(ctx context.Context, input *HookData) (context.Context, error)
}

type BeforeHook

type BeforeHook interface {
	Before(ctx context.Context, input *HookData) (context.Context, error)
}

type CallerType

type CallerType string
const (
	CallerExec      CallerType = "exec"
	CallerQuery     CallerType = "query"
	CallerQueryRow  CallerType = "query_row"
	CallerSendBatch CallerType = "send_batch"
	CallerPing      CallerType = "ping"
	CallerClose     CallerType = "close"
	CallerPrepare   CallerType = "prepare"
	CallerBegin     CallerType = "begin"
	CallerCommit    CallerType = "commit"
	CallerRollback  CallerType = "rollback"
)

type Conn

type Conn interface {
	Begin(ctx context.Context) (Tx, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (Tx, error)

	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	SendBatch(ctx context.Context, b *pgx.Batch) (br pgx.BatchResults)

	Ping(ctx context.Context) error
	Close(ctx context.Context) error

	Conn() InputConn
}

type ConnCloser

type ConnCloser interface {
	Close(ctx context.Context) error
}

type FullHook

type FullHook interface {
	BeforeHook
	AfterHook
}

type HookConn

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

func NewHookConn

func NewHookConn(conn InputConn, opts ...HookConnOption) *HookConn

func (*HookConn) Begin

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

func (*HookConn) BeginTx

func (c *HookConn) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (Tx, error)

func (*HookConn) Close

func (c *HookConn) Close(ctx context.Context) error

func (*HookConn) Conn

func (c *HookConn) Conn() InputConn

func (*HookConn) Exec

func (c *HookConn) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)

func (*HookConn) Ping

func (c *HookConn) Ping(ctx context.Context) error

func (*HookConn) Query

func (c *HookConn) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

func (*HookConn) QueryRow

func (c *HookConn) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

func (*HookConn) SendBatch

func (c *HookConn) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults

type HookConnOption

type HookConnOption interface {
	// contains filtered or unexported methods
}

func WithAfterHooks

func WithAfterHooks(hooks ...AfterHook) HookConnOption

func WithBeforeHooks

func WithBeforeHooks(hooks ...BeforeHook) HookConnOption

func WithHooks

func WithHooks(hooks ...FullHook) HookConnOption

type HookData

type HookData struct {
	Query   string
	InBatch bool
	InTx    bool
	Error   error
	Caller  CallerType
	Args    []any
}

type HookTx

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

func (*HookTx) Begin

func (t *HookTx) Begin(_ context.Context) (Tx, error)

func (*HookTx) Commit

func (t *HookTx) Commit(ctx context.Context) error

func (*HookTx) Conn

func (t *HookTx) Conn() *pgx.Conn

func (*HookTx) CopyFrom

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

func (*HookTx) Exec

func (t *HookTx) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)

func (*HookTx) LargeObjects

func (t *HookTx) LargeObjects() pgx.LargeObjects

func (*HookTx) Prepare

func (t *HookTx) Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)

func (*HookTx) Query

func (t *HookTx) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

func (*HookTx) QueryRow

func (t *HookTx) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

func (*HookTx) Rollback

func (t *HookTx) Rollback(ctx context.Context) error

func (*HookTx) SendBatch

func (t *HookTx) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults

type InputConn

type InputConn interface {
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	SendBatch(ctx context.Context, b *pgx.Batch) (br pgx.BatchResults)

	Begin(ctx context.Context) (Tx, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (Tx, error)
	Ping(ctx context.Context) error
}

type PoolCloser

type PoolCloser interface {
	Close()
}

type Tx

type Tx = pgx.Tx

Directories

Path Synopsis
gen
internal

Jump to

Keyboard shortcuts

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