db

package
v1.0.1390 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAdvisoryLockTimeout = errors.New("timed out waiting for the advisory lock")

ErrAdvisoryLockTimeout is returned by WithAdvisoryLock when the lock couldn't be taken within its retries.

Functions

func ErrorDetails

func ErrorDetails(err error) error

func IsDBError added in v1.0.731

func IsDBError(err error) bool

func IsDeadlockError

func IsDeadlockError(err error) bool

func IsForeignKeyError

func IsForeignKeyError(err error) bool

func NewOopsPlugin added in v1.0.731

func NewOopsPlugin() gorm.Plugin

func PGMajorVersion added in v1.0.914

func PGMajorVersion(db *gorm.DB) (int, error)

PGMajorVersion retrieves the PostgreSQL major version

func ReadTable added in v1.0.983

func ReadTable(db *gorm.DB, tableName string, clauses ...clause.Expression) ([]map[string]any, error)

ReadTable reads a postgres table when the table model isn't known.

func ScanRows added in v1.0.1114

func ScanRows[T ~map[string]any](rows *sql.Rows) ([]T, error)

func WithAdvisoryLock added in v1.0.1389

func WithAdvisoryLock(db *gorm.DB, lock AdvisoryLock, fn func(tx *gorm.DB) error) error

WithAdvisoryLock runs fn holding the lock exclusively, in a savepoint of db's transaction (or a new transaction). Each attempt waits for the lock at most lock.Timeout, then backs off and retries, lock.Retries times, so a busy lock doesn't stall writers queued behind the exclusive request. The lock is released when the transaction ends.

Types

type AdvisoryLock added in v1.0.1389

type AdvisoryLock struct {
	// Key names the lock. It is hashed with hashtext, so every holder must use the same key.
	Key string

	// Timeout is how long each attempt waits for the lock before backing off.
	Timeout time.Duration

	// Retries is how many times to retry after Timeout.
	Retries int

	// Backoff is the wait before the first retry. It doubles after each one.
	Backoff time.Duration
}

AdvisoryLock is a transaction-scoped Postgres advisory lock, taken exclusively, with a bounded wait.

Jump to

Keyboard shortcuts

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