Documentation ¶
Index ¶
- Constants
- func GetDSN(opts ...Option) string
- func IsUniqueViolation(err error) bool
- func NewDB(opts ...Option) (*pachsql.DB, error)
- func WaitUntilReady(ctx context.Context, db *pachsql.DB) error
- func WithTx(ctx context.Context, db *pachsql.DB, ...) error
- type Option
- func WithConnMaxIdleTime(d time.Duration) Option
- func WithConnMaxLifetime(d time.Duration) Option
- func WithDBName(DBName string) Option
- func WithHostPort(host string, port int) Option
- func WithMaxIdleConns(n int) Option
- func WithMaxOpenConns(n int) Option
- func WithQueryLog(enable bool, name string) Option
- func WithSSLMode(mode string) Option
- func WithUserPassword(user, password string) Option
- type WithTxOption
Constants ¶
const ( // DefaultMaxOpenConns is the default maximum number of open connections; if you change // this, also consider changing the default from the environment in // serviceenv.GlobalConfiguration. DefaultMaxOpenConns = 10 // DefaultMaxIdleConns is the default number of idle database connections to maintain. (2 // comes from the default in database/sql.go.) DefaultMaxIdleConns = 2 // DefaultConnMaxLifetime is the default maximum amount of time a connection may be reused // for. Defaults to no maximum. DefaultConnMaxLifetime = 0 // DefaultConnMaxIdleTime is the default maximum amount of time a connection may be idle. // Defaults to no maximum. DefaultConnMaxIdleTime = 0 )
const ( SSLModeDisable = "disable" DefaultSSLMode = SSLModeDisable )
Variables ¶
This section is empty.
Functions ¶
func GetDSN ¶
GetDSN returns the string for connecting to the postgres instance with the parameters specified in 'opts'. This is needed because 'listen' operations are not supported in generic SQL libraries and they need to be run in a side session.
func IsUniqueViolation ¶
IsUniqueViolation returns true if the error is a UniqueContraintViolation
func WaitUntilReady ¶
WaitUntilReady attempts to ping the database until the context is cancelled. Progress information is written to log
Types ¶
type Option ¶
type Option func(*dbConfig)
Option configures a DB.
func WithConnMaxIdleTime ¶
WithConnMaxIdleTime sets the maximum time a database connection may be idle for.
func WithConnMaxLifetime ¶
WithConnMaxLifetime sets the maximum time a database connection may be reused for.
func WithHostPort ¶
WithHostPort sets the host and port for the DB.
func WithMaxIdleConns ¶
WithMaxIdleConns sets the maximum number of idle database connections to keep available for future queries.
func WithMaxOpenConns ¶
WithMaxOpenConns sets the maximum number of concurrent database connections to be allocated before blocking new acquisitions.
func WithQueryLog ¶ added in v2.7.0
WithQueryLog enables logging of SQL queries to zap at severity debug; see log.NewPGX.
func WithSSLMode ¶
WithSSLMode sets the SSL mode for connections to the database.
func WithUserPassword ¶
WithUserPassword sets the user and password for the DB.
type WithTxOption ¶
type WithTxOption func(c *withTxConfig)
WithTxOption parameterizes the WithTx function
func WithBackOff ¶
func WithBackOff(bo backoff.BackOff) WithTxOption
TODO: Unused, but probably acceptable to leave in place WithBackOff sets the BackOff used when retrying
func WithIsolationLevel ¶
func WithIsolationLevel(x sql.IsolationLevel) WithTxOption
WithIsolationLevel runs the transaction with the specified isolation level.
func WithReadOnly ¶
func WithReadOnly() WithTxOption
TODO: Unused, but probably acceptable to leave in place WithReadOnly causes WithTx to run the transaction as read only