@devmoods/postgres
v0.7.0
Published
PostgreSQL utilities for Node.js applications
Readme
@devmoods/postgres
PostgreSQL utilities for Node.js applications.
Advisory locks
postgres.advisoryLock() uses PostgreSQL session-level advisory locks.
- it acquires the lock on a dedicated connection
- it holds the lock for the duration of the callback
- it releases the lock when the callback completes or throws
- if releasing the lock fails, the connection is closed and PostgreSQL releases the session lock
This helper is not transaction-scoped.
If advisoryLock() is called inside postgres.transaction(...), the advisory lock is still acquired on a separate session and is released when the advisory lock callback finishes, not when the surrounding transaction commits or rolls back.
Use advisoryLock() to serialize access to a callback across processes or workers. Do not assume it protects the full lifetime of an outer transaction.
