qb includes a few methods to help you lock certain rows when executing select
statements.
Note: For locks to work properly, they must be nested inside a transaction
. qb does not handle any of the transaction lifecycle for you.
A shared lock prevents the selected rows from being modified until your transaction is committed.
Name | Type | Required | Default | Description |
---|---|---|---|---|
A lock for update lock prevents the selected rows from being modified or selected with another shared lock until your transaction is committed.
The main difference between a sharedLock
and lockForUpdate
is that a lockForUpdate
prevents other reads or selects as well as updates.
When using the skipLocked
flag, the query will skip over locked records and only return and lock available records.
noLock
will instruct your grammar to ignore any shared locks when executing the query.
Currently this only makes a difference in SQL Server grammars.
The lock
method will allow you to add a custom lock directive to your query. Think of it as the raw
method for lock directives.
These lock directives vary from grammar to grammar.
Clears any lock directive on the query.
Name
Type
Required
Default
Description
No arguments
skipLocked
Boolean
false
false
Name
Type
Required
Default
Description
No arguments
Name
Type
Required
Default
Description
value
string
true
The custom lock directive to add to the query.
Name
Type
Required
Default
Description
No arguments