Documentation
¶
Overview ¶
Package postgres provides several github.com/jackc/pgx related helpers for interacting with postgres.
Index ¶
- func Connect(logger *slog.Logger, dsn string, maxConns int, maxIdleTime string, ...) (*pgxpool.Pool, error)
- func PgxErrorToHTTPError(err error) error
- type DB
- type SpanDB
- func (db *SpanDB) Begin(ctx context.Context) (pgx.Tx, error)
- func (db *SpanDB) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
- func (db *SpanDB) Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
- func (db *SpanDB) Ping(ctx context.Context) error
- func (db *SpanDB) Query(ctx context.Context, sql string, optionsAndArgs ...any) (pgx.Rows, error)
- func (db *SpanDB) QueryRow(ctx context.Context, sql string, optionsAndArgs ...any) pgx.Row
- func (db *SpanDB) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
func Connect( logger *slog.Logger, dsn string, maxConns int, maxIdleTime string, connectTimeout int, sleepBeforeRetry time.Duration, maxRetryDuration time.Duration, ) (*pgxpool.Pool, error)
Connect connects to postgres and returns a *pgxpool.Pool.
The provided arguments are:
- dsn: the url to reach the database
- maxConns: the maximum amount of open connections
- maxIdleTime: the maximum idle time of an open connection
- connectTimeout: the timeout on connecting to the database in seconds
- sleepBeforeRetry: duration to sleep before trying to connect again
- maxRetryDuration: total amount of time to try and achieve a database connection
func PgxErrorToHTTPError ¶ added in v0.1.1
PgxErrorToHTTPError converts a database error from github.com/jackc/pgx to an appropriate HTTP error.
Types ¶
type DB ¶
type DB interface { Exec( ctx context.Context, sql string, arguments ...any, ) (pgconn.CommandTag, error) Query( ctx context.Context, sql string, optionsAndArgs ...any, ) (pgx.Rows, error) QueryRow(ctx context.Context, sql string, optionsAndArgs ...any) pgx.Row SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults Begin(ctx context.Context) (pgx.Tx, error) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error) Ping(ctx context.Context) error }
DB provides a uniform interface for the postgres database connection, pools and transactions.
type SpanDB ¶
type SpanDB struct { DB DB // contains filtered or unexported fields }
SpanDB is used to wrap database actions in [sentry.Span]s.
func (*SpanDB) Begin ¶
Begin doesn't wrap Begin in a [sentry.Span] as this makes little sense for starting a transaction.
func (*SpanDB) BeginTx ¶ added in v0.1.9
BeginTx doesn't wrap BeginTx in a [sentry.Span] as this makes little sense for starting a transaction.
func (*SpanDB) Exec ¶
func (db *SpanDB) Exec( ctx context.Context, sql string, arguments ...any, ) (pgconn.CommandTag, error)
Exec is used to wrap Exec in a [sentry.Span].
func (*SpanDB) Ping ¶ added in v0.1.1
Ping doesn't wrap Ping in a [sentry.Span] as this makes little sense for pinging the db.
func (*SpanDB) Query ¶
func (db *SpanDB) Query( ctx context.Context, sql string, optionsAndArgs ...any, ) (pgx.Rows, error)
Query is used to wrap Query in a [sentry.Span].