Documentation
¶
Index ¶
- Variables
- func ErrorDetails(err error) error
- func IsDBError(err error) bool
- func IsDeadlockError(err error) bool
- func IsForeignKeyError(err error) bool
- func NewOopsPlugin() gorm.Plugin
- func PGMajorVersion(db *gorm.DB) (int, error)
- func ReadTable(db *gorm.DB, tableName string, clauses ...clause.Expression) ([]map[string]any, error)
- func ScanRows[T ~map[string]any](rows *sql.Rows) ([]T, error)
- func WithAdvisoryLock(db *gorm.DB, lock AdvisoryLock, fn func(tx *gorm.DB) error) error
- type AdvisoryLock
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 IsDeadlockError ¶
func IsForeignKeyError ¶
func NewOopsPlugin ¶ added in v1.0.731
func PGMajorVersion ¶ added in v1.0.914
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 WithAdvisoryLock ¶ added in v1.0.1389
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.
Click to show internal directories.
Click to hide internal directories.