db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package db wraps the Postgres pool, per-request user scoping and migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, ownerURL string) error

Migrate applies all embedded migrations in name order, one transaction each.

func MigrateTo

func MigrateTo(ctx context.Context, ownerURL, last string) error

MigrateTo applies migrations up to and including the file named last ("" = all).

Types

type DB

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

DB is the application pool; it connects as braid_app (no BYPASSRLS).

func Open

func Open(ctx context.Context, appURL string) (*DB, error)

Open connects as braid_app.

func (*DB) Close

func (d *DB) Close()

Close closes the pool.

func (*DB) Listen

func (d *DB) Listen(ctx context.Context, channel string, ready func(), onNotify func(payload string)) error

Listen runs LISTEN on a dedicated connection and calls onNotify per notification; it reconnects with backoff (1 s..30 s) and returns nil once ctx is done. ready (may be nil) is called after every successful LISTEN.

func (*DB) Ping

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

Ping checks connectivity.

func (*DB) WithSystem

func (d *DB) WithSystem(ctx context.Context, fn func(pgx.Tx) error) error

WithSystem runs fn in a transaction with no user; only definer functions return data.

func (*DB) WithUser

func (d *DB) WithUser(ctx context.Context, userID string, fn func(pgx.Tx) error) error

WithUser runs fn in a transaction scoped (via RLS) to userID.

Jump to

Keyboard shortcuts

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