Documentation
¶
Overview ¶
Package lock defines the option vocabulary for row-level and advisory locks used by engine.LockByID, engine.AdvisoryLock, and QuerySet.ForUpdate. Backend semantics live in den/backend (backend.LockMode and its constants); this package layers the option-pattern constructors (SkipLocked, NoWait) and a Resolve helper that turns a slice of options into a single backend.LockMode.
Application code reaches these as den.NoWait, den.SkipLocked, etc. — direct imports of this package are only needed when implementing a helper that itself takes ...lock.Option.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*config)
Option configures a lock acquisition (LockByID, ForUpdate). Apply options via Resolve to derive the effective backend.LockMode.
func NoWait ¶
func NoWait() Option
NoWait makes the lock acquisition return ErrLocked immediately if another transaction already holds the row lock, instead of blocking. Maps to PostgreSQL's FOR UPDATE NOWAIT. Useful when the caller wants to decide between retry, abort, or an alternative code path. On SQLite this option is a no-op.
Passing both SkipLocked and NoWait causes Resolve to return an error — they are mutually exclusive in PostgreSQL.
func SkipLocked ¶
func SkipLocked() Option
SkipLocked makes the lock acquisition return ErrNotFound immediately if another transaction already holds the row lock, instead of blocking. Maps to PostgreSQL's FOR UPDATE SKIP LOCKED. Useful for queue-consumer patterns where each worker should claim a different row without contending. On SQLite this option is a no-op.
Because PostgreSQL returns zero rows for both "locked by another tx" and "row does not exist", the caller cannot distinguish these cases via the error alone.
Passing both SkipLocked and NoWait causes Resolve to return an error — they are mutually exclusive in PostgreSQL.