Documentation ¶
Overview ¶
db contains database-related utilities for Postgres.
Index ¶
- func Conn() *sqlx.DB
- func InTransaction(ctx context.Context, fn func(*sqlx.Tx) error) error
- func NewListener() *pq.Listener
- func RetriableError(err error) bool
- func SetInParam(str string, params *[]interface{}, param []interface{}) string
- func SetInParamInt(str string, params *[]interface{}, param []int32) string
- func SetParam(query string, params *[]interface{}, param interface{}) string
- type PgError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InTransaction ¶
InTransaction executes the given function within a transaction with serializable isolation. If the function returns an error, the transaction will be rollbacked, otherwise committed. Errors from the function will be propagated upwards unchanged.
func NewListener ¶
NewListener returns a new Postgres notify listener.
func RetriableError ¶
RetriableError checks if the given Postgres error should be retried. Generally, this indicates the user attempted a transaction that conflicted with a concurrent transaction that should be retried.
func SetInParam ¶
SetInParam appends a slice to the parameter list and updates the query string with the correct bindvar. For example, if first three parameters are being set, the string "id IN (%s)" would become "id IN ($1,$2,$3)"
func SetInParamInt ¶
SetInParamInt calls SetInParam, but first converts the int32 param slice.