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 ¶
- func Connect(ctx context.Context, dsn string, maxConns, minConns int) (*pgxpool.Pool, error)
- func IsForeignKeyViolation(err error) bool
- func IsUniqueViolation(err error) bool
- func Migrate(dsn string, logger zerolog.Logger) error
- func WithTx(ctx context.Context, pool *pgxpool.Pool, fn func(tx pgx.Tx) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect creates a pgxpool.Pool from the given DSN with the specified connection limits.
func IsForeignKeyViolation ¶
IsForeignKeyViolation reports whether err represents a PostgreSQL foreign key constraint violation (SQLSTATE 23503).
func IsUniqueViolation ¶
IsUniqueViolation reports whether err represents a PostgreSQL unique constraint violation (SQLSTATE 23505).
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. |