Documentation
¶
Overview ¶
Package pqx provides helpers for use with github.com/lib/pq (Postgres driver for the database/sql package).
It also registers own driver for the database/sql package named "pqx". This driver is a thin wrapper around github.com/lib/pq driver used to make it easier to control connections opened by github.com/lib/pq. By default it'll just enable TCP keepalives, but you can set Dial to your own hook and have full control over opened connections.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Dial = KeepAliveDial(time.Minute)
Dial is a hook which should be set before connecting to PostgreSQL server using "pqx" driver.
Functions ¶
func EnsureTempDB ¶ added in v0.5.0
EnsureTempDB will drop/create new temporary db with suffix in db name and return opened temporary db together with cleanup func which will close and drop temporary db. It will use dbCfg to connect to existing database first, and then reuse same dbCfg with modified DBName to connect to temporary db.
It'll also create schema with name set to dbCfg.User in temporary db.
Recommended value for suffix is your package's import path.
func IsSerializationFailure ¶ added in v0.5.0
IsSerializationFailure returns a boolean indicating whether the error is 40001 (serialization_failure).
It tries to unwrap err using github.com/pkg/errors.Cause() or errors.As().
func Serialize ¶ added in v0.5.0
Serialize executes given func, which is supposed to run single transaction and return (possibly wrapped) error if transaction fail.
It will re-execute given func for up to 10 times in case it fails with 40001 (serialization_failure) error.
Returns value returned by last doTx call.
Types ¶
type Config ¶
type Config struct { DBName string User string Pass string Host string Port int FallbackApplicationName string ConnectTimeout time.Duration // Round to seconds. SSLMode SSLMode SSLCert string // PEM file path. SSLKey string // PEM file path. SSLRootCert string // PEM file path. SearchPath string // Specifies the order in which schemas are searched. DefaultTransactionIsolation sql.IsolationLevel // One of: LevelDefault, LevelReadUncommitted, LevelReadCommitted, LevelRepeatableRead, LevelSerializable. StatementTimeout time.Duration // Round to milliseconds. LockTimeout time.Duration // Round to milliseconds. IdleInTransactionSessionTimeout time.Duration // Round to milliseconds. Other map[string]string // Any other parameters from https://www.postgresql.org/docs/current/runtime-config-client.html. }
Config described connection parameters for github.com/lib/pq.
type DialFunc ¶ added in v0.4.0
DialFunc used to open new connections to PostgreSQL server.
func KeepAliveDial ¶ added in v0.4.0
KeepAliveDial returns hook which adds TCP keepalives.
type Logger ¶ added in v0.5.0
type Logger interface {
Print(...interface{})
}
Logger interface consumed by this package.
type SSLMode ¶
type SSLMode string
SSLMode determines whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server..
const ( SSLDisable SSLMode = "disable" // Only try a non-SSL connection. SSLRequire SSLMode = "require" // Only try an SSL connection. If a root CA file is present, verify the certificate in the same way as if verify-ca was specified. SSLVerifyCA SSLMode = "verify-ca" // Only try an SSL connection, and verify that the server certificate is issued by a trusted certificate authority (CA). SSLVerifyFull SSLMode = "verify-full" // Only try an SSL connection, verify that the server certificate is issued by a trusted CA and that the requested server host name matches that in the certificate. )
SSL modes.