infrapostgres

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionConfig

type ConnectionConfig struct {
	// Database address. "host:port"
	Address string `mapstructure:"address"`

	// Database credentials
	Credentials Credentials `mapstructure:"credentials"`

	// Maximum number of physical connections
	MaxConnections int `mapstructure:"max_connections"`

	// Maximum number of idle connections
	MaxIdleConnections int `mapstructure:"max_idle_connections"`

	// Maximum connection lifetime. Connections that active more than that period will be closed
	MaxConnectionLifetime time.Duration `mapstructure:"max_connection_lifetime"`

	// Connection idle time. Connections that idle more than that period will be closed
	MaxConnectionIdleTime time.Duration `mapstructure:"max_connection_idle_time"`

	// Whether to use simple protocol.
	// Extended protocol uses prepared queries.
	// prepared queries are not compatible with PGBouncer in any modes other than session.
	PreferSimpleProtocol bool `mapstructure:"prefer_simple_protocol"`
}

func (*ConnectionConfig) PGXConnString

func (c *ConnectionConfig) PGXConnString() string

func (*ConnectionConfig) Validate

func (c *ConnectionConfig) Validate() error

type ConnectionsConfig

type ConnectionsConfig map[string]*ConnectionConfig

func (*ConnectionsConfig) Validate

func (c *ConnectionsConfig) Validate() error

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container is a simple container for holding named postgres connections. It's a helper for sharing same connection between several components.

func Init added in v1.11.0

func Init(wg *sync.WaitGroup, cfg ConnectionsConfig) *Container

Init creates a container and connects every connection from the config in background. The caller must wait on the wait group before using the returned container. Connection failures are fatal.

func NewContainer

func NewContainer() *Container

func (*Container) Connect

func (cont *Container) Connect(name string, cfg *ConnectionConfig) error

Connect creates a new named postgres connection

func (*Container) Get

func (cont *Container) Get(name string) *sql.DB

Get gets connection from a container

func (*Container) GetCollector

func (cont *Container) GetCollector(name string) *sqlstats.StatsCollector

GetCollector gets metrics collector from a container

type Credentials

type Credentials struct {
	Database string `mapstructure:"database"`
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
}

func (*Credentials) Validate

func (c *Credentials) Validate() error

Jump to

Keyboard shortcuts

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