postgres

package module
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package postgres opens the one PostgreSQL pool of a site with a database/sql view of it, and runs its migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAddress

func CheckAddress(address string) error

CheckAddress returns the error for an empty PostgreSQL address or one pgx 5.10 and 5.11 read apart with no PG* set.

func Classify

func Classify(err error) error

Classify returns err wrapped in its dbkit error class, or err unchanged when it has none or already carries it.

func Migrate

func Migrate(ctx context.Context, db *sql.DB, m Migrations) error

Migrate applies every pending migration of m to db under goose's advisory lock, creating an absent schema of Table.

Types

type Handle

type Handle struct {
	// Pool owns every connection of the handle.
	Pool *pgxpool.Pool
	// DB is the database/sql view of Pool, with no idle connection of its own.
	DB *sql.DB
}

Handle is the one PostgreSQL pool of a site and a database/sql view that draws from it.

func Open

func Open(address string, opts Options) (*Handle, error)

Open returns a handle on the PostgreSQL database of address, capped at opts.MaxConns, and connects to nothing.

func (*Handle) Close

func (h *Handle) Close() error

Close closes the view, then the pool.

type Migrations

type Migrations struct {
	// Table is the version table, table or schema.table, lowercase parts of up to 63 bytes, none reserved, no pg_ schema.
	Table string
	// FS holds the owner's SQL migration files at its root, and nil means none.
	FS fs.FS
	// Go are the owner's Go migrations, each built with goose.NewGoMigration.
	Go []*goose.Migration
}

Migrations are the migrations of one owner.

type Options

type Options struct {
	// MaxConns caps the connections the pool and its database/sql view hold together, from 2 to 2147483647.
	MaxConns int
}

Options configures one PostgreSQL pool. MaxConns is required.

Directories

Path Synopsis
Package pgtest gives each test a fresh PostgreSQL database cut from a migrated template, and sweeps stale ones.
Package pgtest gives each test a fresh PostgreSQL database cut from a migrated template, and sweeps stale ones.

Jump to

Keyboard shortcuts

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