database

package
v0.0.0-...-9358009 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package database provides the cross-cutting Postgres connection pool shared by every domain: Connect builds a pgx-backed pool and hands back a *bun.DB for domains to query through.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, dsn string) (*bun.DB, error)

Connect builds a pgxpool.Pool for dsn and returns it as a *bun.DB, still backed by pgxpool underneath so Postgres-aware pooling behavior applies.

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation reports whether err is Postgres' unique_violation (SQLSTATE 23505).

func ProvideDB

func ProvideDB(ctx context.Context, dsn string) (*bun.DB, func(), error)

ProvideDB wraps Connect for wire, pairing the *bun.DB with a cleanup closure that closes it, for wire's generated cleanup chain.

func RequireOneRow

func RequireOneRow(res sql.Result, notFound error) error

RequireOneRow turns an update/delete that matched nothing into notFound, so a caller can tell "no such row" from "row left unchanged".

Types

type BunTransactor

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

BunTransactor is the production Transactor, backed by a real top-level *bun.DB transaction.

func NewBunTransactor

func NewBunTransactor(db *bun.DB) *BunTransactor

NewBunTransactor constructs a BunTransactor backed by db.

func (*BunTransactor) RunInTx

func (t *BunTransactor) RunInTx(ctx context.Context, opts *sql.TxOptions, fn func(context.Context, bun.Tx) error) error

RunInTx runs fn inside a real transaction opened on t's underlying *bun.DB.

type Transactor

type Transactor interface {
	RunInTx(ctx context.Context, opts *sql.TxOptions, fn func(context.Context, bun.Tx) error) error
}

Transactor runs fn inside a database transaction, committing if fn returns nil and rolling back otherwise.

Directories

Path Synopsis
Package dbtest exercises Bun-backed repositories and services against a real Postgres database, rolling back every test's outer transaction so nothing is left behind.
Package dbtest exercises Bun-backed repositories and services against a real Postgres database, rolling back every test's outer transaction so nothing is left behind.

Jump to

Keyboard shortcuts

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