postgres

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 9 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 postgres starts PostgreSQL containers with dockermanage.

Index

Constants

View Source
const (
	// DefaultImage is the default PostgreSQL image.
	DefaultImage = "postgres:18-alpine"

	// DefaultDatabase is the default PostgreSQL database name.
	DefaultDatabase = "testdb"

	// DefaultUser is the default PostgreSQL user.
	DefaultUser = "postgres"

	// DefaultPassword is the default PostgreSQL password.
	DefaultPassword = "password1"

	// ContainerPort is the PostgreSQL port inside the container.
	ContainerPort = 5432
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

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

Instance is a running PostgreSQL container. Use Instance.URL to connect, and Instance.Container to stop or remove the container, or to run commands in it.

func Start

func Start(ctx context.Context, manager *dockermanage.Manager, options ...StartOption) (_ *Instance, retErr error)

Start starts a PostgreSQL container and waits until it accepts connections. It waits until the ctx deadline, or for 30s after the container starts if ctx has no deadline; the ctx deadline also covers the image pull. If Start fails after it creates the container, it removes the container.

func (*Instance) Container

func (i *Instance) Container() *dockermanage.Container

Container returns the PostgreSQL container.

func (*Instance) Database

func (i *Instance) Database() string

Database returns the database name.

func (*Instance) Password

func (i *Instance) Password() string

Password returns the database user password.

func (*Instance) URL

func (i *Instance) URL() string

URL returns a connection URL, for example postgres://postgres:password1@127.0.0.1:54321/testdb?sslmode=disable. Go drivers (pgx, lib/pq), psql, and tools that read DATABASE_URL accept it. Special characters in values are escaped.

func (*Instance) User

func (i *Instance) User() string

User returns the database user.

type StartOption

type StartOption interface {
	// contains filtered or unexported methods
}

StartOption configures Start.

func WithDatabase

func WithDatabase(database string) StartOption

WithDatabase sets the database name.

func WithHostIP

func WithHostIP(hostIP string) StartOption

WithHostIP sets the host IP address that the PostgreSQL port is bound to. Defaults to dockermanage.DefaultHostIP. For a remote Docker daemon, use "0.0.0.0".

func WithHostPort

func WithHostPort(port int) StartOption

WithHostPort sets a fixed host port. If unset, Docker picks one.

func WithImage

func WithImage(image string) StartOption

WithImage sets the PostgreSQL image.

func WithLabel

func WithLabel(key, value string) StartOption

WithLabel sets one container label. Use it once for each label.

func WithPassword

func WithPassword(password string) StartOption

WithPassword sets the database user password.

func WithReadiness

func WithReadiness(readiness dockermanage.ReadinessFunc) StartOption

WithReadiness replaces the check that Start uses to wait until PostgreSQL is ready. By default, Start runs pg_isready inside the container. Use it for an image that does not include pg_isready, for example with a check that connects with your driver.

func WithUser

func WithUser(user string) StartOption

WithUser sets the database user.

Jump to

Keyboard shortcuts

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