Help us shape the future of Go! Take the 2026 Go Developer Survey

postgres

package
v0.0.0-...-dee9785 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package postgres manages PostgreSQL connectivity, migrations, and transaction helpers. Connect creates a pgxpool connection pool with configurable minimum and maximum connections. Migrate runs embedded goose migrations on startup. WithTx executes a function within a database transaction and handles commit or rollback. IsUniqueViolation detects PostgreSQL unique constraint violations by error code 23505.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, dsn string, maxConns, minConns int) (*pgxpool.Pool, error)

Connect creates a pgxpool.Pool from the given DSN with the specified connection limits.

func IsForeignKeyViolation

func IsForeignKeyViolation(err error) bool

IsForeignKeyViolation reports whether err represents a PostgreSQL foreign key constraint violation (SQLSTATE 23503).

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation reports whether err represents a PostgreSQL unique constraint violation (SQLSTATE 23505).

func Migrate

func Migrate(dsn string, logger zerolog.Logger) error

Migrate runs all pending goose migrations using the embedded SQL files.

func WithTx

func WithTx(ctx context.Context, pool *pgxpool.Pool, fn func(tx pgx.Tx) error) error

WithTx runs fn inside a database transaction. If fn returns an error, the transaction is rolled back. Otherwise, the transaction is committed. The deferred rollback after a successful commit is a safe no-op.

Types

This section is empty.

Directories

Path Synopsis
Package migrations embeds the SQL migration files used by goose.
Package migrations embeds the SQL migration files used by goose.

Jump to

Keyboard shortcuts

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