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
- type Callback
- 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) Ping(ctx context.Context) error
- func (db *DB) Pool() *pgxpool.Pool
- 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
Constants ¶
This section is empty.
Variables ¶
var ErrRollbackOnly = errors.New("database: transaction marked rollback-only")
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.
Types ¶
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) 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