postgres

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 15 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
	DEFAULT_MIGRATION_LOCK_TIMEOUT = 10 * 1000 // 10 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

func NewDialect added in v1.25.0

func NewDialect() schema.Dialect

NewDialect returns the bun dialect ConnectToDatabase uses: pgdialect.New() with a JSON formatter that stores the text \u0000 correctly on bun v1.3.0 (https://github.com/uptrace/bun/issues/1472). Pass it to bun.NewDB when building a *bun.DB without ConnectToDatabase.

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"`
	// MigrationLockTimeout is the lock_timeout in milliseconds for the migration
	// connection, so a migration blocked by a lock held by another session fails
	// and the next start retries it instead of hanging the boot. 0 or unset
	// means the 10 second default; there is no off. Statement and read timeouts
	// do not apply to migrations. It does not bound the wait for the migration
	// lock another instance holds, which has no timeout.
	MigrationLockTimeout int `mapstructure:"migrationLockTimeout"`
	// MaxOpenConns caps the main pool. 0 leaves it unlimited (database/sql default).
	// Set it below the server's max_connections with headroom for other clients
	// and for the migration pool, which is not capped and holds two or three
	// connections while migrations run, one of them for the migration lock.
	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
Package pgtest is test support for apps that test against a real PostgreSQL: it creates a uniquely named database per test run, empties it between tests, drops it at the end, and sweeps the databases left behind by runs that died.
Package pgtest is test support for apps that test against a real PostgreSQL: it creates a uniquely named database per test run, empties it between tests, drops it at the end, and sweeps the databases left behind by runs that died.

Jump to

Keyboard shortcuts

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