postgres

package
v0.0.0-...-343eb44 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: BSD-3-Clause Imports: 8 Imported by: 4

Documentation

Overview

Package postgres provides a wrapper to connect to PostgreSQL. It also implements Unit of Work interface. See uow package for more info about Unit of Work.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is a sentinel error for not found error.
	ErrNotFound = pgx.ErrNoRows
	// ErrUniqueViolation is a sentinel error for unique violation error.
	ErrUniqueViolation = &pgconn.PgError{Code: postgresUniqueViolationCode}
)

Functions

func IsUniqueViolationError

func IsUniqueViolationError(err error) bool

IsUniqueViolationError checks if the error is a unique violation error.

func NewPgxPool

func NewPgxPool(cfg Config) (*pgxpool.Pool, error)

NewPgxPool creates a new pgx pool.

Types

type Config

type Config struct {
	Host     string `env:"POSTGRES_HOST,default=localhost"`
	User     string `env:"POSTGRES_USER,required"`
	Password string `env:"POSTGRES_PASSWORD,required"`
	Name     string `env:"POSTGRES_NAME,required"`
	SSLMode  string `env:"POSTGRES_SSL_MODE,default=disable"`
	Port     int    `env:"POSTGRES_PORT,default=5432"`
}

Config holds configuration for PostgreSQL.

type TxDB

type TxDB struct {
	// contains filtered or unexported fields
}

TxDB is a transaction version of DB interface generated by sqlc.

func NewTxDB

func NewTxDB(db uow.Tr, txGetter uow.TxGetter) *TxDB

NewTxDB creates an instance of TxDB.

func (*TxDB) Exec

func (d *TxDB) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)

Exec runs Exec with transaction if needed.

func (*TxDB) Query

func (d *TxDB) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

Query runs Query with transaction if needed.

func (*TxDB) QueryRow

func (d *TxDB) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

QueryRow runs QueryRow with transaction if needed.

Jump to

Keyboard shortcuts

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