dockerpostgres

package
v3.27.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultImage is the default PostgreSQL image.
	DefaultImage = "postgres:16-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"
)

Variables

This section is empty.

Functions

func TCPReady

func TCPReady(ctx context.Context, c *dockermanage.Container) error

TCPReady checks whether the Postgres TCP port is accepting connections.

Types

type Instance

type Instance struct {
	Container *dockermanage.Container
	Database  string
	User      string
	Password  string
}

Instance represents a running PostgreSQL container.

func Start

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

Start starts a PostgreSQL container and waits for its TCP port to be reachable.

func (*Instance) DSN

func (i *Instance) DSN() string

DSN returns a connection string suitable for PostgreSQL drivers.

type Option

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

Option configures a PostgreSQL container instance.

func WithDatabase

func WithDatabase(database string) Option

WithDatabase sets the database name.

func WithHostPort

func WithHostPort(port int) Option

WithHostPort sets a fixed host port. If unset, Docker auto-assigns one.

func WithImage

func WithImage(image string) Option

WithImage sets the PostgreSQL image.

func WithLabel

func WithLabel(key, value string) Option

WithLabel appends a container label.

func WithLabels

func WithLabels(labels map[string]string) Option

WithLabels merges labels into container labels.

func WithPassword

func WithPassword(password string) Option

WithPassword sets the database user password.

func WithUser

func WithUser(user string) Option

WithUser sets the database user.

Jump to

Keyboard shortcuts

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