database

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPoolSettings

func ApplyPoolSettings(poolCfg *pgxpool.Config, cfg Config)

ApplyPoolSettings maps Config pool fields onto a parsed pgxpool.Config.

func ConnectWithBackoff

func ConnectWithBackoff(ctx context.Context, logger *zap.Logger, cfg Config) (*pgxpool.Pool, error)

ConnectWithBackoff establishes a connection pool to PostgreSQL with exponential backoff retry.

func RunMigrations

func RunMigrations(ctx context.Context, logger *zap.Logger, pool *pgxpool.Pool) error

RunMigrations runs all embedded migrations against the database.

Types

type Config

type Config struct {
	DSN             string        `json:"dsn" yaml:"dsn"`
	ReadDSN         string        `json:"read_dsn" yaml:"read_dsn"`
	MaxOpenConns    int32         `json:"max_open_conns" yaml:"max_open_conns"`
	MaxIdleConns    int32         `json:"max_idle_conns" yaml:"max_idle_conns"`
	MaxConnLifetime time.Duration `json:"max_conn_lifetime" yaml:"max_conn_lifetime"`
	MaxConnIdleTime time.Duration `json:"max_conn_idle_time" yaml:"max_conn_idle_time"`
	MaxRetries      int           `json:"max_retries" yaml:"max_retries"`
	RetryDelay      time.Duration `json:"retry_delay" yaml:"retry_delay"`
}

Config holds the database configuration options.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default database configuration.

type DBPool

type DBPool struct {
	WritePool *pgxpool.Pool
	ReadPool  *pgxpool.Pool
}

DBPool holds primary write pool and optional read-replica pool.

func (*DBPool) GetReadPool

func (p *DBPool) GetReadPool() *pgxpool.Pool

GetReadPool returns ReadPool if configured, otherwise falls back to WritePool.

Jump to

Keyboard shortcuts

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