pg

package module
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SSLDisable SSLMode = "disable"
	SSLRequire SSLMode = "require"
	SSLVerify  SSLMode = "verify-full"

	DEFAULT_MAX_CONNS            = 1
	DEFAULT_MIN_CONNS            = 1
	DEFAULT_MAX_IDLE_TIME        = 30 * time.Minute
	DEFAULT_MAX_LIFE_TIME        = 60 * time.Minute
	DEFAULT_MAX_LIFE_TIME_JITTER = 0
	DEFAULT_HEALTH_CHECK         = 1 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	User    string
	Pass    string
	Host    string
	Port    int
	DbName  string
	SslMode SSLMode
	// MaxConnCount is the maximum size of the pool.
	MaxConnCount int32

	// MinConnCount is the minimum size of the pool.
	// After connection closes, the pool might dip below
	// MinConns. A low number of MinConns might mean the
	// pool is empty after MaxConnLifetime until the
	// health check has a chance to create new connections.
	MinConnCount int32

	MaxConnIdleTime time.Duration

	// MaxConnLifeTime is the duration since creation after which a connection will be automatically closed.
	MaxConnLifeTime time.Duration

	MaxConnLifeTimeJitter time.Duration

	// HealthCheckPeriod is the duration between checks of the health of idle connections.
	HealthCheckPeriod time.Duration
}

func DefatulConf

func DefatulConf() *Config

func (*Config) Build

func (c *Config) Build() Config

func (Config) GetConnStr

func (c Config) GetConnStr() string

GetConnStr parses the Config data to create a connection string

func (*Config) WithDb

func (c *Config) WithDb(name string) *Config

func (*Config) WithHealthCheckPeriod

func (c *Config) WithHealthCheckPeriod(duration time.Duration) *Config

func (*Config) WithHost

func (c *Config) WithHost(hostname string) *Config

func (*Config) WithMaxConnIdleTime

func (c *Config) WithMaxConnIdleTime(duration time.Duration) *Config

func (*Config) WithMaxConnLifeTime

func (c *Config) WithMaxConnLifeTime(duration time.Duration) *Config

func (*Config) WithMaxConnLifeTimeJitter

func (c *Config) WithMaxConnLifeTimeJitter(duration time.Duration) *Config

func (*Config) WithMaxConns

func (c *Config) WithMaxConns(count int32) *Config

func (*Config) WithMinConns

func (c *Config) WithMinConns(count int32) *Config

func (*Config) WithPass

func (c *Config) WithPass(pass string) *Config

func (*Config) WithPort

func (c *Config) WithPort(port int) *Config

func (*Config) WithSslMode

func (c *Config) WithSslMode(mode SSLMode) *Config

func (*Config) WithUser

func (c *Config) WithUser(name string) *Config

type PgClient

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

func New

func New(conf Config) *PgClient

func (*PgClient) Close

func (d *PgClient) Close()

Close closes all connections in the pool and rejects future Acquire calls. Blocks until all connections are returned to pool and closed.

func (*PgClient) Connect

func (d *PgClient) Connect(ctx context.Context) error

Connect creates a postgres connection pool with specified Config and assigns it to PgClient's driver Use PgClient.Ping to make sure postgres connection is alive.

func (*PgClient) GetConn

func (d *PgClient) GetConn() *pgxpool.Pool

func (*PgClient) Ping

func (d *PgClient) Ping(ctx context.Context) error

func (*PgClient) Stats

func (d *PgClient) Stats() *pgxpool.Stat

type SSLMode

type SSLMode string

Jump to

Keyboard shortcuts

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