db

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMigrations

func RunMigrations(databaseURL string) error

RunMigrations runs all pending database migrations using goose.

func TestLockAndReset

func TestLockAndReset(databaseURL string) (release func(), err error)

TestLockAndReset acquires a PostgreSQL session-level advisory lock, resets the public schema, and runs migrations. The lock is held until release() is called. Use this in TestMain to serialize test packages that share a database:

func TestMain(m *testing.M) {
    url := os.Getenv("DATABASE_URL")
    if url == "" { os.Exit(m.Run()) }
    release, err := db.TestLockAndReset(url)
    if err != nil { log.Fatal(err) }
    code := m.Run()
    release()
    os.Exit(code)
}

Types

type DB

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

DB wraps a pgxpool.Pool.

func New

func New(ctx context.Context, databaseURL string) *DB

New creates a new DB, connecting to the given database URL.

func (*DB) Close

func (d *DB) Close()

Close closes the connection pool.

func (*DB) Pool

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

Pool returns the underlying pool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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