database

package
v0.0.0-...-d364ca2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package database owns Soro's PostgreSQL pool, Bun bridge, and transactions.

Index

Constants

This section is empty.

Variables

View Source
var ErrRollbackOnly = errors.New("database: transaction marked rollback-only")

Functions

func CreateDatabase

func CreateDatabase(ctx context.Context, databaseURL string) error

CreateDatabase creates the database named by databaseURL by connecting to PostgreSQL's maintenance database. The database name is parsed by pgx and quoted as an identifier rather than accepted as SQL.

func DropDatabase

func DropDatabase(ctx context.Context, databaseURL string) error

DropDatabase physically removes the database named by databaseURL. Callers are expected to require an explicit confirmation before invoking it.

Types

type Callback

type Callback func(context.Context) error

type DB

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

DB owns one pgx pool and the database/sql facade used by Bun.

func Open

func Open(ctx context.Context, settings config.DatabaseConfig) (*DB, error)

func Wrap

func Wrap(bunDB *bun.DB) (*DB, error)

Wrap creates a Soro database around an existing Bun database. The wrapper owns the Bun database but has no directly exposed pgx pool.

func (*DB) AfterCommit

func (db *DB) AfterCommit(ctx context.Context, callback Callback) error

func (*DB) AfterRollback

func (db *DB) AfterRollback(ctx context.Context, callback Callback) error

func (*DB) Bun

func (db *DB) Bun() *bun.DB

func (*DB) Close

func (db *DB) Close() error

func (*DB) Hooks

func (db *DB) Hooks() *lifecycle.Registry

func (*DB) IDB

func (db *DB) IDB(ctx context.Context) bun.IDB

func (*DB) InTransaction

func (db *DB) InTransaction(ctx context.Context) bool

func (*DB) Ping

func (db *DB) Ping(ctx context.Context) error

func (*DB) Pool

func (db *DB) Pool() *pgxpool.Pool

Pool exposes the shared pool intended for pgx-native integrations such as River.

func (*DB) SQL

func (db *DB) SQL() *sql.DB

SQL exposes the shared database/sql facade used by Bun. Integrations must not close it independently of DB.

func (*DB) SQLTx

func (db *DB) SQLTx(ctx context.Context) (*sql.Tx, bool)

SQLTx returns the active database/sql transaction carried by ctx.

func (*DB) Transaction

func (db *DB) Transaction(ctx context.Context, fn func(context.Context) error) error

Transaction runs fn in a transaction. Nested calls join the current transaction and mark it rollback-only if they return an error.

func (*DB) Validator

func (db *DB) Validator() *validation.Engine

Jump to

Keyboard shortcuts

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