postgres

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DEFAULT_DIAL_TIMEOUT      = 10 * 1000 // 10 seconds in milliseconds
	DEFAULT_READ_TIMEOUT      = 30 * 1000 // 30 seconds in milliseconds
	DEFAULT_WRITE_TIMEOUT     = 20 * 1000 // 20 seconds in milliseconds
	DEFAULT_STATEMENT_TIMEOUT = 30 * 1000 // 30 seconds in milliseconds
)

Variables

This section is empty.

Functions

func ConnectToDatabase

func ConnectToDatabase(cfg *ConnectionConfig) (*relational.DB, error)

ConnectToDatabase - Creates a new connection to a PSQL database with the given configuration.

func CreateDatabase

func CreateDatabase(cfg ConnectionConfig) error

CreateDatabase - Creates a new database with the given configuration

func DeleteDatabase

func DeleteDatabase(cfg ConnectionConfig) error

DeleteDatabase - Deletes an existing database with the given configuration

Types

type ConnectionConfig

type ConnectionConfig struct {
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
	Host     string `mapstructure:"host"`
	Database string `mapstructure:"database"`
	// SSL enables TLS with sslmode=require: traffic is encrypted but the server
	// certificate is not verified. Ignored when SSLMode is set.
	SSL bool `mapstructure:"ssl"`
	// SSLMode overrides SSL when set. Allowed: "disable", "require", "verify-ca"
	// and "verify-full". Leave empty to keep the SSL behavior.
	SSLMode string `mapstructure:"sslMode"`
	// SSLRootCert is the path to the CA PEM used to verify the server
	// certificate. Only used by verify-ca and verify-full; when empty they
	// verify against the system CA pool.
	SSLRootCert      string `mapstructure:"sslRootCert"`
	Verbose          bool   `mapstructure:"verbose"`
	DialTimeout      int    `mapstructure:"dialTimeout"`
	ReadTimeout      int    `mapstructure:"readTimeout"`
	WriteTimeout     int    `mapstructure:"writeTimeout"`
	StatementTimeout int    `mapstructure:"statementTimeout"`
	// MaxOpenConns caps the connection pool. 0 leaves it unlimited (database/sql default).
	// Set it below the server's max_connections with headroom for other clients.
	MaxOpenConns int `mapstructure:"maxOpenConns"`
	// MaxIdleConns caps idle connections kept in the pool. 0 keeps the database/sql default.
	MaxIdleConns int `mapstructure:"maxIdleConns"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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