Documentation
¶
Index ¶
- Variables
- func BeginWithLockTimeout(ctx context.Context, pool PgxIface, timeout time.Duration) (pgx.Tx, error)
- func CheckQuota(pool PgxIface, r *http.Request, resource string) error
- func DeleteIfStatus(table string, id any, fromStatus any) (string, []any)
- func GetTracer() *tracelog.TraceLog
- func IsLockTimeout(err error) bool
- func LogLockBlockers(ctx context.Context, pool PgxIface, relation string)
- func NotifyEndpoint(pool PgxIface, host string, id strfmt.UUID)
- func NotifyService(pool PgxIface, host string)
- func UpdateStatusGuarded(table string, id any, fromStatus, toStatus any) (string, []any)
- type Pagination
- type PgxIface
Constants ¶
This section is empty.
Variables ¶
var ( StmtBuilder = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar) Select = StmtBuilder.Select Update = StmtBuilder.Update Insert = StmtBuilder.Insert Delete = StmtBuilder.Delete )
var (
ErrInvalidMarker = errors.New("invalid marker")
)
Functions ¶
func BeginWithLockTimeout ¶ added in v2.5.4
func BeginWithLockTimeout(ctx context.Context, pool PgxIface, timeout time.Duration) (pgx.Tx, error)
BeginWithLockTimeout starts a transaction and bounds how long any statement in it will wait for a row/table lock via `SET LOCAL lock_timeout`. Once the timeout elapses the blocked statement fails immediately with SQLSTATE 55P03 (lock_not_available) instead of hanging until the request context deadline.
lock_timeout should be chosen well below the HTTP request deadline so a contended FOR UPDATE surfaces as a clean, retryable error rather than an opaque context cancellation. SET LOCAL is scoped to the transaction and is reset automatically on commit or rollback.
func DeleteIfStatus ¶ added in v2.5.4
DeleteIfStatus builds a DELETE that removes the row only while it holds fromStatus (typically PENDING_DELETE).
func IsLockTimeout ¶ added in v2.5.4
IsLockTimeout reports whether err is a Postgres lock_not_available (55P03) error, i.e. a lock wait that exceeded lock_timeout.
func LogLockBlockers ¶ added in v2.5.4
LogLockBlockers dumps the sessions currently holding locks on the given relation to the log at error level. It is meant to be called from a handler's lock-timeout branch to capture *who* was blocking — the tuple/relation in the Postgres server log only identifies the blocked row, never the holder.
It runs on a fresh pool connection (the transaction that hit the lock timeout is left in an aborted state and cannot be reused). Because every archer process sets a distinct application_name (archer-api, archer-f5-agent, archer-ni-agent), the dump names the culprit process and its running query directly. This is best-effort diagnostics: any failure is logged and swallowed so it never masks the original lock error.
func NotifyEndpoint ¶
NotifyEndpoint sends a NOTIFY to the endpoint channel for the specified host and endpoint ID.
func NotifyService ¶
NotifyService sends a NOTIFY to the service channel for the specified host.
Types ¶
type Pagination ¶
type Pagination struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
// Filters contains exact-match column/value filters supplied by the handler.
Filters map[string]any
/*Sets the page size.
In: query
*/
Limit *int64
/*Pagination ID of the last item in the previous list.
In: query
*/
Marker *strfmt.UUID
/*Filter for resources not having tags, multiple not-tags are considered as logical AND.
Should be provided in a comma separated list.
In: query
*/
NotTags []string
/*Filter for resources not having tags, multiple tags are considered as logical OR.
Should be provided in a comma separated list.
In: query
*/
NotTagsAny []string
/*Sets the page direction.
In: query
*/
PageReverse *bool
/*Comma-separated list of sort keys, optionally prefix with - to reverse sort order.
In: query
*/
Sort *string
/*Filter for tags, multiple tags are considered as logical AND.
Should be provided in a comma separated list.
In: query
*/
Tags []string
/*Filter for tags, multiple tags are considered as logical OR.
Should be provided in a comma separated list.
In: query
*/
TagsAny []string
}
func NewPagination ¶ added in v2.7.0
func NewPagination(params any) *Pagination
func (*Pagination) Query ¶
func (p *Pagination) Query(db pgxscan.Querier, q sq.SelectBuilder) (string, []any, error)
func (*Pagination) WithFilter ¶ added in v2.7.0
func (p *Pagination) WithFilter(column string, value any) *Pagination
type PgxIface ¶
type PgxIface interface {
Begin(context.Context) (pgx.Tx, error)
BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
Query(context.Context, string, ...any) (pgx.Rows, error)
QueryRow(context.Context, string, ...any) pgx.Row
Config() *pgxpool.Config
Stat() *pgxpool.Stat
Acquire(ctx context.Context) (*pgxpool.Conn, error)
}