db

package
v2.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StmtBuilder = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
	Select      = StmtBuilder.Select
	Update      = StmtBuilder.Update
	Insert      = StmtBuilder.Insert
	Delete      = StmtBuilder.Delete
)
View Source
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 CheckQuota

func CheckQuota(pool PgxIface, r *http.Request, resource string) error

func DeleteIfStatus added in v2.5.4

func DeleteIfStatus(table string, id any, fromStatus any) (string, []any)

DeleteIfStatus builds a DELETE that removes the row only while it holds fromStatus (typically PENDING_DELETE).

func GetTracer

func GetTracer() *tracelog.TraceLog

func IsLockTimeout added in v2.5.4

func IsLockTimeout(err error) bool

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

func LogLockBlockers(ctx context.Context, pool PgxIface, relation string)

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

func NotifyEndpoint(pool PgxIface, host string, id strfmt.UUID)

NotifyEndpoint sends a NOTIFY to the endpoint channel for the specified host and endpoint ID.

func NotifyService

func NotifyService(pool PgxIface, host string)

NotifyService sends a NOTIFY to the service channel for the specified host.

func UpdateStatusGuarded added in v2.5.4

func UpdateStatusGuarded(table string, id any, fromStatus, toStatus any) (string, []any)

UpdateStatusGuarded builds an UPDATE that sets status/updated_at only while the row still holds fromStatus.

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 (p *Pagination) GetLinks(modelList any) []*models.Link

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)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL