Help us shape the future of Go! Take the 2026 Go Developer Survey

pgdb

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package pgdb gives an application its own schema in a PostgreSQL database: a pool whose connections use it and goose migrations applied to it, so several applications can share one database without their tables meeting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool, m Migrations) (err error)

Migrate creates the pool's schema and applies the application's migrations. It is safe to call from several replicas at once.

The lock is held on a dedicated connection outside the pool, so replicas waiting on it never starve the migration itself of pool connections.

func Open

func Open(ctx context.Context, url, schema string) (*pgxpool.Pool, error)

Open creates a connection pool whose connections use schema as their search_path, and verifies connectivity. TLS to the database is negotiated by crypto/tls, which uses the FIPS 140-3 module.

func Schema

func Schema(pool *pgxpool.Pool) string

Schema is the schema of a pool from Open.

func ValidSchema

func ValidSchema(name string) bool

ValidSchema reports whether name is usable as a schema: lowercase letters, digits and underscores, not starting with a digit, at most 63 bytes.

Types

type Migrations

type Migrations struct {
	// FS holds the migration files at its root.
	FS fs.FS
	// LockKey is the pg_advisory_lock key held while migrating, so that one
	// replica migrates at a time. Zero derives one from the schema.
	LockKey int64
	// Logger defaults to slog.Default().
	Logger *slog.Logger
}

Migrations are an application's goose migrations.

Directories

Path Synopsis
Package pgdbtest gives integration tests an isolated schema in a test database.
Package pgdbtest gives integration tests an isolated schema in a test database.

Jump to

Keyboard shortcuts

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