stdpgxfx

package
v0.0.58 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package stdpgxfx provides postgres pgx package as fx dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPoolConfig

func NewPoolConfig(cfg Config, logs *zap.Logger) (*pgxpool.Config, error)

NewPoolConfig inits a pool configuration from the package config.

func Provide

func Provide(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, derivedPoolNames ...string) fx.Option

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

Types

type AfterMigrateRole added in v0.0.58

type AfterMigrateRole struct {
	User     string
	Password string
}

AfterMigrateRole can be optionally provided to further customize the role used to connect to the database that was just migrated. This is useful if the eventual role being used from the application is different from the migration (superuser) role and the testrole.

type Config

type Config struct {
	// RWDatabaseURL configures the database connection string for the read-write connection.
	RWDatabaseURL string `env:"RW_DATABASE_URL"`
	// PoolConnectionTimeout configures how long the pgx pool connect logic waits for the connection to establish
	PoolConnectionTimeout time.Duration `env:"POOL_CONNECTION_TIMEOUT" envDefault:"5s"`
	// PoolCloseTimeout is the time we'll allow to to close the connection pool. Only effective if shorter than
	// the fx shutdown timeout
	PoolCloseTimeout time.Duration `env:"POOL_CLOSE_TIMEOUT" envDefault:"5s"`
}

Config configures the components.

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
	fx.Lifecycle
	Logs          *zap.Logger
	Config        Config
	PgxPoolConfig *pgxpool.Config
}

Params define the dependencies of the main component(s).

type PgtestdbTestMigratorParams added in v0.0.58

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

type Result

type Result struct {
	fx.Out
	RW *pgxpool.Pool `name:"rw"`
}

Result declare the main components produced by this package.

func New

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

New build the main components of this 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