mysql

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 mysql provides MySQL container management for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Container

func Container(ctx context.Context) (*mysql.MySQLContainer, error)

Container exposes the underlying testcontainers MySQL module for advanced use.

func MustNew

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

MustNew starts a new MySQL container and panics on error. Use for quick setup in tests.

func MustNewWithOptions

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

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

func New

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

New starts a new MySQL 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 := mysql.New(ctx)
if err != nil {
    panic(err)
}
defer cleanup()

func NewWithConfig

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

NewWithConfig starts a MySQL container with custom configuration.

func NewWithOptions

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

NewWithOptions starts a MySQL container with functional options. This is the preferred way to create a customized MySQL container.

Example:

ctx := context.Background()
db, cleanup, err := mysql.NewWithOptions(ctx,
    mysql.WithImage("mysql:8.0"),
    mysql.WithUsername("myuser"),
    mysql.WithPassword("mypass"),
    mysql.WithDatabase("mydb"),
)
if err != nil {
    panic(err)
}
defer cleanup()

func NewWithOptionsContainer

func NewWithOptionsContainer(ctx context.Context, opts ...Option) (*mysql.MySQLContainer, error)

NewWithOptionsContainer starts a MySQL container with functional options and returns the raw container.

Types

type Option

type Option func(*config.MySQLConfig)

Option is a functional option for MySQL configuration.

func WithDatabase

func WithDatabase(database string) Option

WithDatabase sets the MySQL 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 timeout for container health checks.

func WithImage

func WithImage(image string) Option

WithImage sets the Docker image for MySQL.

func WithPassword

func WithPassword(password string) Option

WithPassword sets the MySQL password.

func WithPoolSettings

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

WithPoolSettings configures connection pool settings.

func WithUsername

func WithUsername(username string) Option

WithUsername sets the MySQL username.

Jump to

Keyboard shortcuts

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