Documentation ¶
Index ¶
- Constants
- type Config
- type Pool
- type PostExecFunc
- type TxFunc
- type WConn
- func (c *WConn) PostExec(fn PostExecFunc) error
- func (c *WConn) WCopyFrom(ctx context.Context, name string, tableName pgx.Identifier, ...) (n int64, err error)
- func (c *WConn) WExec(ctx context.Context, name string, unprepared string, args ...interface{}) (cmd pgconn.CommandTag, err error)
- func (c *WConn) WQuery(ctx context.Context, name string, unprepared string, args ...interface{}) (r pgx.Rows, err error)
- func (c *WConn) WQueryRow(ctx context.Context, name string, unprepared string, args ...interface{}) pgx.Row
- type WGConn
- type WTx
- func (t *WTx) Commit(ctx context.Context) error
- func (t *WTx) PostExec(f PostExecFunc) error
- func (t *WTx) Rollback(ctx context.Context) error
- func (t *WTx) WCopyFrom(ctx context.Context, name string, tableName pgx.Identifier, ...) (n int64, err error)
- func (t *WTx) WExec(ctx context.Context, name string, unprepared string, args ...interface{}) (cmd pgconn.CommandTag, err error)
- func (t *WTx) WQuery(ctx context.Context, name string, unprepared string, args ...interface{}) (rows pgx.Rows, err error)
- func (t *WTx) WQueryRow(ctx context.Context, name string, unprepared string, args ...interface{}) pgx.Row
Constants ¶
const ( HighQPSMaxOpenConns = 100 DefaultEnvPrefix = "postgres" AppNameLengthMax = 32 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Username string `default:"postgres"` Password string `default:"my-secret"` Host string `default:"localhost"` Port int `default:"5432"` DBName string `default:"wpgx_test_db"` MaxConns int32 `default:"100"` MinConns int32 `default:"0"` MaxConnLifetime time.Duration `default:"6h"` MaxConnIdleTime time.Duration `default:"1m"` EnablePrometheus bool `default:"true"` EnableTracing bool `default:"true"` AppName string `required:"true"` }
func ConfigFromEnv ¶
func ConfigFromEnv() *Config
func ConfigFromEnvPrefix ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is the wrapped pgx pool that registers Prometheus.
func (*Pool) Transact ¶
func (p *Pool) Transact(ctx context.Context, txOptions pgx.TxOptions, fn TxFunc) (resp interface{}, err error)
Transact is a wrapper of pgx.Transaction It acquires a connection from the Pool and starts a transaction with pgx.TxOptions determining the transaction mode. The context will be used when executing the transaction control statements (BEGIN, ROLLBACK, and COMMIT), and when if tracing is enabled, the context with transaction span will be passed down to @p fn.
type PostExecFunc ¶
type PostExecFunc = func() error
PostExecFunc is the function that must be ran after a successful CRUD. NOTE: context should have been captured into the function.
type TxFunc ¶
TxFunc is the body of a transaction. ctx must be used to generate proper tracing spans. If not, you might see incorrect parallel spans.
type WConn ¶
type WConn struct {
// contains filtered or unexported fields
}
func (*WConn) PostExec ¶
func (c *WConn) PostExec(fn PostExecFunc) error
type WGConn ¶
type WGConn interface { WQuery( ctx context.Context, name string, unprepared string, args ...interface{}) (pgx.Rows, error) WQueryRow( ctx context.Context, name string, unprepared string, args ...interface{}) pgx.Row WExec( ctx context.Context, name string, unprepared string, args ...interface{}) (pgconn.CommandTag, error) WCopyFrom( ctx context.Context, name string, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error) PostExec(f PostExecFunc) error }
WGConn is the abstraction over wrapped connections and transactions.
type WTx ¶
type WTx struct {
// contains filtered or unexported fields
}
WTx is a wrapped pgx.Tx. The main reason is to overwrite the PostExec method that run all of them until the transaction is successfully committed.
func (*WTx) PostExec ¶
func (t *WTx) PostExec(f PostExecFunc) error