Documentation
¶
Overview ¶
Package database owns Soro's PostgreSQL pool, Bun bridge, and transactions.
Index ¶
- Variables
- func CreateDatabase(ctx context.Context, databaseURL string) error
- func DropDatabase(ctx context.Context, databaseURL string) error
- func IsCommitted(err error) bool
- func IsRollbackFailure(err error) bool
- type Callback
- type CommittedError
- type DB
- func (db *DB) AfterCommit(ctx context.Context, callback Callback) error
- func (db *DB) AfterRollback(ctx context.Context, callback Callback) error
- func (db *DB) Bun() *bun.DB
- func (db *DB) Close() error
- func (db *DB) Hooks() *lifecycle.Registry
- func (db *DB) IDB(ctx context.Context) bun.IDB
- func (db *DB) InTransaction(ctx context.Context) bool
- func (db *DB) IndependentRequestTransaction(ctx context.Context, initialize RequestTransactionInitializer, ...) error
- func (db *DB) Ping(ctx context.Context) error
- func (db *DB) Pool() *pgxpool.Pool
- func (db *DB) RequestTransaction(ctx context.Context, initialize RequestTransactionInitializer, ...) error
- func (db *DB) SQL() *sql.DB
- func (db *DB) SQLTx(ctx context.Context) (*sql.Tx, bool)
- func (db *DB) Transaction(ctx context.Context, fn func(context.Context) error) error
- func (db *DB) Validator() *validation.Engine
- type LocalSettings
- type RequestTransactionInitializer
- type RollbackFailure
Constants ¶
This section is empty.
Variables ¶
var ErrRollbackOnly = errors.New("database: transaction marked rollback-only")
var ErrTransactionCallbackPanic = errors.New("database: transaction callback panicked")
Functions ¶
func CreateDatabase ¶
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 ¶
DropDatabase physically removes the database named by databaseURL. Callers are expected to require an explicit confirmation before invoking it.
func IsCommitted ¶
func IsRollbackFailure ¶
Types ¶
type CommittedError ¶
type CommittedError struct{ Err error }
CommittedError reports a failure in an after-commit callback. Database work is already durable and must not be retried as though it rolled back.
func (*CommittedError) Error ¶
func (err *CommittedError) Error() string
func (*CommittedError) Unwrap ¶
func (err *CommittedError) Unwrap() 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 Wrap ¶
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) AfterRollback ¶
func (*DB) IndependentRequestTransaction ¶
func (db *DB) IndependentRequestTransaction(ctx context.Context, initialize RequestTransactionInitializer, fn func(context.Context) error) error
IndependentRequestTransaction starts a new request transaction even when ctx already carries one for the same DB. This is an explicit durability boundary for append-only journals and progressive execution records that must become visible before the surrounding HTTP transaction completes.
The new transaction uses another pooled connection and inherits cancellation and all non-transaction context values. Callers must avoid touching rows locked by the surrounding transaction.
func (*DB) RequestTransaction ¶
func (db *DB) RequestTransaction(ctx context.Context, initialize RequestTransactionInitializer, fn func(context.Context) error) error
RequestTransaction runs fn in a transaction initialized before any request work. Nested Repository.Transaction calls join this transaction and preserve the existing rollback-only behavior.
func (*DB) SQL ¶
SQL exposes the shared database/sql facade used by Bun. Integrations must not close it independently of DB.
func (*DB) Transaction ¶
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
type LocalSettings ¶
LocalSettings exposes the only database operation needed to initialize request-local PostgreSQL context. Values are always applied with set_config(..., true), so they cannot survive the transaction or leak through a pooled connection.
type RequestTransactionInitializer ¶
RequestTransactionInitializer configures application-owned database context immediately after a request transaction begins and may enrich the context passed to handlers.
type RollbackFailure ¶
RollbackFailure reports that transaction work failed and rollback or an after-rollback callback also failed.
func (*RollbackFailure) Error ¶
func (err *RollbackFailure) Error() string
func (*RollbackFailure) Unwrap ¶
func (err *RollbackFailure) Unwrap() []error