Documentation ¶
Index ¶
- Constants
- Variables
- func FromContext(ctx context.Context) (*pgxpool.Pool, error)
- func FromRequest(req *http.Request) (*pgxpool.Pool, error)
- func IsNotFoundError(err error) bool
- func IsPoolClosed(err error) bool
- func IsUniqueViolationError(err error) bool
- func Middleware(db *pgxpool.Pool) httpmiddleware.MiddlewareFunc
- func MustPool(ctx context.Context, connString string, cfgs ...func(*pgxpool.Config)) *pgxpool.Pool
- func NewPool(ctx context.Context, connString string, cfgs ...func(*pgxpool.Config)) (pool *pgxpool.Pool, err error)
- func WithContext(ctx context.Context, pool *pgxpool.Pool) context.Context
- func WithTracer(t pgx.QueryTracer) func(c *pgxpool.Config)
- func WithUUID() func(c *pgxpool.Config)
Constants ¶
const (
ErrCodeUniqueViolation = "23505"
)
Variables ¶
var ErrDBPoolNotFound = errors.New("foundations/sqldb: failed to retrieve db pool from context.")
Functions ¶
func FromContext ¶
FromContext returns the pool associated with the given context.
func FromRequest ¶
FromRequest returns the pool associated with the given http request.
func IsNotFoundError ¶
IsNotFoundError returns true if the error is a pgx no rows error.
func IsPoolClosed ¶
IsPoolClosed returns true if the error is a pgx closed pool error.
func IsUniqueViolationError ¶
IsUniqueViolationError returns true if the error is a unique violation error.
func Middleware ¶
func Middleware(db *pgxpool.Pool) httpmiddleware.MiddlewareFunc
Middleware returns a middleware that injects the given pool into the request context.
func NewPool ¶
func NewPool(ctx context.Context, connString string, cfgs ...func(*pgxpool.Config)) (pool *pgxpool.Pool, err error)
NewPool creates a new connection pool using the provided connection string.
Optional cfgs like WithUUID or WithTracer can be provided.
func WithContext ¶
WithContext returns a new context with the given pool.
func WithTracer ¶
WithTracer sets the query tracer for the database pool.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
pgxuuid
This module is ripped off completely from https://github.com/jackc/pgx-gofrs-uuid and adapted to use github.com/google/uuid instead of github.com/gofrs/uuid.
|
This module is ripped off completely from https://github.com/jackc/pgx-gofrs-uuid and adapted to use github.com/google/uuid instead of github.com/gofrs/uuid. |
Package sqldbtest provides utilities for testing database-related code.
|
Package sqldbtest provides utilities for testing database-related code. |