Documentation
¶
Index ¶
- func CollectAll[T any](rows pgx.Rows, err error) ([]T, error)
- func CollectOne[T any](rows pgx.Rows, err error) (*T, error)
- func CollectOneScalar[T any](rows pgx.Rows, err error) (T, error)
- func InTransaction(ctx context.Context) bool
- type Option
- type Postgres
- func (p *Postgres) Close()
- func (p *Postgres) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
- func (p *Postgres) Ping(ctx context.Context) error
- func (p *Postgres) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
- func (p *Postgres) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- type Querier
- type TransactionManager
- type TxManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectAll ¶
CollectAll scans all rows into a slice of T using struct field name matching. Returns an empty slice if no rows are found.
func CollectOne ¶
CollectOne scans a single row into T using struct field name matching. Returns nil, nil if no rows are found.
func CollectOneScalar ¶
CollectOneScalar scans a single scalar value from one row. Returns the zero value of T if no rows are found.
func InTransaction ¶
InTransaction reports whether ctx contains an active transaction.
Types ¶
type Option ¶
Option configures a pgxpool.Config.
func WithMaxConns ¶
WithMaxConns sets the maximum number of connections in the pool.
func WithMinConns ¶
WithMinConns sets the minimum number of connections in the pool.
type Postgres ¶
Postgres wraps a pgxpool.Pool and implements DB.
type Querier ¶
type Querier 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
}
Querier is the common interface for *pgxpool.Pool and pgx.Tx. It allows repository methods to work transparently within or outside transactions.
type TransactionManager ¶
type TransactionManager interface {
WithinTransaction(ctx context.Context, fn func(ctx context.Context) error) error
}
TransactionManager defines the interface for running code within a transaction.
type TxManager ¶
type TxManager struct {
// contains filtered or unexported fields
}
TxManager implements TransactionManager using pgxpool.
func NewTxManager ¶
NewTxManager returns a new TxManager backed by pool.