Documentation
¶
Overview ¶
Package postgres provides pgx pool construction, query tracing, and per-request DB stats.
Index ¶
- func NewPool(ctx context.Context, databaseURL string) (*pgxpool.Pool, error)
- func NewReqDBStatsContext(ctx context.Context) context.Context
- func SetQueryObserver(o QueryObserver)
- func WithHTTPMethod(ctx context.Context, method string) context.Context
- type QueryObserver
- type QueryObserverFunc
- type ReqDBStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewReqDBStatsContext ¶
NewReqDBStatsContext returns a new context with an empty ReqDBStats attached.
func SetQueryObserver ¶
func SetQueryObserver(o QueryObserver)
SetQueryObserver sets the global query observer (typically a Prometheus histogram).
Types ¶
type QueryObserver ¶
type QueryObserver interface {
ObserveQuery(ctx context.Context, method, route, outcome string, dur time.Duration)
}
QueryObserver receives per-query metrics (wired by main for Prometheus).
type QueryObserverFunc ¶
QueryObserverFunc adapts a plain function to QueryObserver.
func (QueryObserverFunc) ObserveQuery ¶
func (f QueryObserverFunc) ObserveQuery(ctx context.Context, method, route, outcome string, dur time.Duration)
ObserveQuery implements QueryObserver.
type ReqDBStats ¶
type ReqDBStats struct {
QueryCount int
TotalDuration time.Duration
ErrorCount int
// contains filtered or unexported fields
}
ReqDBStats accumulates per-request database query statistics.
func ReqDBStatsFromContext ¶
func ReqDBStatsFromContext(ctx context.Context) (*ReqDBStats, bool)
ReqDBStatsFromContext extracts the ReqDBStats from the context, if present.
Click to show internal directories.
Click to hide internal directories.