sqldb

package
v0.0.0-...-56d8f82 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrCodeUniqueViolation = "23505"
)

Variables

View Source
var ErrDBPoolNotFound = errors.New("foundations/sqldb: failed to retrieve db pool from context.")

Functions

func FromContext

func FromContext(ctx context.Context) (*pgxpool.Pool, error)

FromContext returns the pool associated with the given context.

func FromRequest

func FromRequest(req *http.Request) (*pgxpool.Pool, error)

FromRequest returns the pool associated with the given http request.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error is a pgx no rows error.

func IsPoolClosed

func IsPoolClosed(err error) bool

IsPoolClosed returns true if the error is a pgx closed pool error.

func IsUniqueViolationError

func IsUniqueViolationError(err error) bool

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 MustPool

func MustPool(ctx context.Context, connString string, cfgs ...func(*pgxpool.Config)) *pgxpool.Pool

MustPool creates a new connection pool and panics on error.

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

func WithContext(ctx context.Context, pool *pgxpool.Pool) context.Context

WithContext returns a new context with the given pool.

func WithTracer

func WithTracer(t pgx.QueryTracer) func(c *pgxpool.Config)

WithTracer sets the query tracer for the database pool.

func WithUUID

func WithUUID() func(c *pgxpool.Config)

WithUUID adds native support for converting between Postgres UUID and google/uuid.

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.

Jump to

Keyboard shortcuts

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