postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package postgres provides PostgreSQL container management for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Container

func Container(ctx context.Context, opts ...Option) (*postgres.PostgresContainer, error)

Container exposes the underlying testcontainers PostgreSQL module for advanced use.

func MustNew

func MustNew(ctx context.Context) (*sql.DB, func())

MustNew starts a PostgreSQL container and panics on error. Use for tests where you want quick setup.

func MustNewWithOptions

func MustNewWithOptions(ctx context.Context, opts ...Option) (*sql.DB, func())

MustNewWithOptions starts a PostgreSQL container with options and panics on error.

func New

func New(ctx context.Context) (*sql.DB, func(), error)

New starts a new PostgreSQL container and returns a connected *sql.DB. Call the returned cleanup function to stop and remove the container.

Example:

ctx := context.Background()
db, cleanup, err := postgres.New(ctx)
if err != nil {
    panic(err)
}
defer cleanup()

func NewWithConfig

func NewWithConfig(ctx context.Context, cfg *config.PostgresConfig) (*sql.DB, func(), error)

NewWithConfig starts a PostgreSQL container with custom configuration.

func NewWithOptions

func NewWithOptions(ctx context.Context, opts ...Option) (*sql.DB, func(), error)

NewWithOptions starts a PostgreSQL container with functional options.

Types

type Option

type Option func(*config.PostgresConfig)

Option configures PostgreSQL container options.

func WithDatabase

func WithDatabase(database string) Option

WithDatabase sets the PostgreSQL database name.

func WithHealthCheckInterval

func WithHealthCheckInterval(interval time.Duration) Option

WithHealthCheckInterval configures the interval between health check retries.

func WithHealthCheckRetry

func WithHealthCheckRetry(retries int) Option

WithHealthCheckRetry configures health check retry attempts.

func WithHealthCheckTimeout

func WithHealthCheckTimeout(timeout time.Duration) Option

WithHealthCheckTimeout sets the health check timeout duration.

func WithImage

func WithImage(image string) Option

WithImage sets the Docker image for PostgreSQL.

func WithPassword

func WithPassword(password string) Option

WithPassword sets the PostgreSQL password.

func WithPoolSettings

func WithPoolSettings(maxOpen, maxIdle int, maxLifetime time.Duration) Option

WithPoolSettings configures the connection pool.

func WithUsername

func WithUsername(username string) Option

WithUsername sets the PostgreSQL username.

Jump to

Keyboard shortcuts

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