stdpgxfx

package
v0.0.85 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package stdpgxfx provides sql.DB connection pools usng pgx/v5.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Provide

func Provide(mainPoolName string, derivedPoolNames ...string) fx.Option

Provide components as fx dependencies.

func ProvideDeriver added in v0.0.13

func ProvideDeriver(name string, deriver Deriver) fx.Option

ProvideDeriver is a short-hande function for providing a named deriver function that.

func TestProvide

func TestProvide(tb testing.TB, mig pgtestdb.Migrator, mainPoolName string, derivedPoolNames ...string) fx.Option

TestProvide provides the package's components as an fx module with a setup more useful for testing.

Types

type Config

type Config struct {
	// MainDatabaseURL configures the database connection string for the main connection.
	MainDatabaseURL string `env:"MAIN_DATABASE_URL,required"`

	// IamAuthRegion when set cause the password to be replaced by an IAM token for authentication.
	IamAuthRegion string `env:"IAM_AUTH_REGION"`
}

Config configures the module.

type Deriver added in v0.0.13

type Deriver func(base *pgxpool.Config) *pgxpool.Config

Deriver needs to be provided by the user of this module if derived pools are created.

type Params

type Params struct {
	fx.In
	Config    Config
	AwsConfig aws.Config `optional:"true"`
	Logs      *zap.Logger
}

Params describe the main parameters for providing components.

type PgtestdbTestMigratorParams added in v0.0.58

type PgtestdbTestMigratorParams struct {
	fx.In
	Migrator pgtestdb.Migrator
	Role     *pgtestdb.Role `optional:"true"`
}

type Result

type Result struct {
	fx.Out
	PoolConfig *pgxpool.Config
}

Result describe the main components provided for this module.

func New

func New(params Params) (r Result, err error)

New is the main constructor. In this package it only provides the pool configuration used through out the package.

type TestMigrator added in v0.0.58

type TestMigrator interface {
	Migrate(
		tb testing.TB,
		cfg Config,
		pcfg *pgxpool.Config,
	) (*pgxpool.Config, error)
}

TestMigrator can be implemented and provided to migrate the database for tests.

func NewPgtestdbTestMigrator added in v0.0.58

func NewPgtestdbTestMigrator(params PgtestdbTestMigratorParams) TestMigrator

NewPgtestdbTestMigrator implements the TestMigrator using the pgtestdb library.

type TestMigratorFunc added in v0.0.58

type TestMigratorFunc func(
	tb testing.TB,
	cfg Config,
	pcfg *pgxpool.Config,
) (*pgxpool.Config, error)

TestMigratorFunc makes it easy to implement the migrator.

func (TestMigratorFunc) Migrate added in v0.0.58

func (f TestMigratorFunc) Migrate(
	tb testing.TB, cfg Config, pcfg *pgxpool.Config,
) (*pgxpool.Config, error)

Jump to

Keyboard shortcuts

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