gpostgres

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host            string             `json:"host"               yaml:"host"               validate:"required"`
	Port            string             `json:"port"               yaml:"port"               validate:"required"`
	DB              string             `json:"db"                 yaml:"db"                 validate:"required"`
	User            string             `json:"user"               yaml:"user"               validate:"required"`
	Password        string             `json:"password"           yaml:"password"           validate:"required"`
	AppName         string             `json:"app-name"           yaml:"app-name"`
	MaxOpenConn     int32              `json:"max-open-conn"      yaml:"max-open-conn"`
	MaxConnLifetime gduration.Duration `json:"max-conn-life-time" yaml:"max-conn-life-time"`
	MaxConnIdleTime gduration.Duration `json:"max-conn-idle-time" yaml:"max-conn-idle-time"`
	Options         string             `json:"options"            yaml:"options"`
	SSLMode         string             `json:"sslmode"            yaml:"sslmode"`         // disable | require | verify-ca | verify-full
	ConnectTimeout  gduration.Duration `json:"connect-timeout"    yaml:"connect-timeout"` // per-connection timeout
	MinConns        int32              `json:"min-conns"          yaml:"min-conns"`
}

func (*Config) PgConfig

func (c *Config) PgConfig() string

PgConfig renders the configuration as a libpq-style connection string. Every value is single-quoted and escaped so passwords or options containing spaces, quotes or backslashes do not corrupt the string.

type DB

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

DB is a connection handle that owns a pgx pool and a database/sql view of it. Use Pool for pgx-native access and SQL for database/sql access (migrations, tools). The handle owns both: call Close once to release everything. Do not close the values returned by Pool or SQL directly.

func New

func New(ctx context.Context, config *Config) (*DB, error)

New opens a pgx connection pool from config, applies the pool tuning options, verifies connectivity with a ping, and returns an owning DB handle.

func (*DB) Close

func (d *DB) Close() error

Close releases the pool and the database/sql handle. It is safe to call more than once; subsequent calls are no-ops.

func (*DB) Pool

func (d *DB) Pool() *pgxpool.Pool

Pool returns the underlying pgx connection pool.

func (*DB) SQL

func (d *DB) SQL() *sql.DB

SQL returns a database/sql handle backed by the same pool.

Jump to

Keyboard shortcuts

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