Repository navigation
Description
Commit
Every path and line number in this ticket refers to prisma/orm at main commit 64f6c3e3b701324618419cf2832ae789f3b0f514 (2026-09-30). The reproduction uses the published @prisma/orm-postgres 8.0.0-rc.12-dev.17.
Summary
A select built with the ORM client (db.orm) or with the typed SQL builder (db.sql) cannot end with a row-locking clause. Postgres has four: FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE and FOR KEY SHARE, each optionally followed by OF <table> and by NOWAIT or SKIP LOCKED. Neither builder has a method for any of them, and the select syntax tree has no field that could hold one, so no renderer can print one.
This hurts every application that must serialise two transactions on the same row: read a row, decide from what it holds, then write. Without a lock, two transactions at the default isolation level (read committed) both read the old state and both act on it. The only way to lock a row today is the raw SQL lane (db.raw.sql), which gives up the typed columns, the typed where, and the table names the contract provides. Work queues (FOR UPDATE SKIP LOCKED) are the other common case and have the same problem.
Background
Where we hit it
The Asks application (an internal Prisma repository, pull request #45, file packages/1-domain/contacts/src/move.ts) moves an identity from one contact to another. When the source contact has no identity left, it is absorbed into the target. Two moves out of the same contact, running at the same time at read committed, each counted the other's identity as still there, so neither absorbed the contact. The contact was left with no identity and was never absorbed.
The fix is to lock the source contact's row before counting its identities. The second move then waits for the first to commit and counts what the first left. Neither builder could write the lock, so the application builds a raw plan and runs it in the transaction:
async function identityWithItsContactLocked(tx: Transaction, identityId: string) {
const read = () =>
tx.orm.public.Identity.select('id', 'platform', 'handle', 'contactId')
.where({ id: identityId })
.first();
for (let seen = await read(); seen; ) {
await tx.execute(
rawSql`SELECT "id" FROM "contact" WHERE "id" = ${seen.contactId} FOR NO KEY UPDATE`
.affectedCount()
.build(),
);
const locked = await read();
if (locked?.contactId === seen.contactId) return locked;
seen = locked;
}
throw structuredError('CONTACTS.NOT_FOUND', `There is no identity with id ${identityId}.`);
}rawSql is postgresStatic<Contract>({ contractJson }).raw.sql, exported by the application's database package, because the transaction context tx has sql and orm but no raw (packages/3-extensions/postgres/src/runtime/postgres-members.ts:26-31). The application uses FOR NO KEY UPDATE rather than FOR UPDATE on purpose: every update of an identity takes a key-share lock on its contact for the foreign key check, and FOR UPDATE would conflict with that and deadlock two moves in opposite directions. A test in the application holds the first move's transaction open, checks in pg_stat_activity that the second move is waiting on a lock, then releases the first and asserts that the second absorbs the contact. That test runs against a real Postgres server.
The application wanted to write this instead:
await tx.sql.public.contact
.select('id')
.where((f, fns) => fns.eq(f.id, seen.contactId))
.lock('noKeyUpdate')
.build();
// or, with the ORM client
await tx.orm.public.Contact.select('id').where({ id: seen.contactId }).lock('noKeyUpdate').first();How the typed SQL builder builds a select
db.sql.<namespace>.<table>.select(...) returns a SelectQuery. Its type is packages/2-sql/4-lanes/sql-builder/src/types/select-query.ts:18-81: where, orderBy, groupBy, distinctOn, annotate, plus the mixins WithSelect, WithPagination (limit, offset), WithDistinct, WithAlias (as) and WithBuild (build). The runtime class is in packages/2-sql/4-lanes/sql-builder/src/runtime/query-impl.ts, and the state it carries is in packages/2-sql/4-lanes/sql-builder/src/runtime/builder-base.ts. build() produces a SelectAst.
A Postgres-only clause already exists and is the model to follow: distinctOn is a GatedMethod (packages/2-sql/4-lanes/sql-builder/src/scope.ts:14-16) that is present only when the contract's capabilities include { postgres: { distinctOn: true } } (select-query.ts:66-80, runtime query-impl.ts:67-78). The Postgres adapter declares that capability in packages/3-targets/6-adapters/postgres/src/core/adapter.ts:20-39 and packages/3-targets/6-adapters/postgres/src/core/descriptor-meta.ts:150-165.
How the ORM client builds a select
db.orm.<namespace>.<Model> is a Collection (packages/3-extensions/sql-orm-client/src/collection.ts). where (line 366), select (line 810), orderBy (line 861), distinctOn (line 1090), limit (line 1124) and the others each return a clone with an updated CollectionState (packages/3-extensions/sql-orm-client/src/types.ts:89-110). The read terminals all (line 1182) and first (line 1250) compile that state. buildSelectAst in packages/3-extensions/sql-orm-client/src/query-plan-select.ts:1379-1444 turns the state into a SelectAst, and compileSelect (line 1446) and compileSelectWithIncludes (line 1503) call it. distinctOn is again the Postgres-only precedent: its parameter type is never unless the contract has postgres.distinctOn, and assertDistinctOnCapability (packages/3-extensions/sql-orm-client/src/collection-contract.ts:637-652) throws ORM.CAPABILITY_MISSING at run time.
The shared syntax tree and the renderers
Both builders produce the same SelectAst, defined in packages/2-sql/4-lanes/relational-core/src/ast/types.ts (SelectAstOptions at lines 1583-1596, the class from line 1598, rewrite at line 1758). The Postgres adapter renders it in renderSelect, packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts:204-241. The SQLite adapter renders it in renderSelect, packages/3-targets/6-adapters/sqlite/src/core/adapter.ts:235-271.
What the repository already says about row locks
packages/2-sql/4-lanes/sql-builder/STATUS.md:51lists "FOR UPDATE / FOR SHARE / FOR NO KEY UPDATE / FOR KEY SHARE (row locking)" under "What's missing".docs/architecture docs/adrs/ADR 187 - Transaction-scoped streams use invalidation not buffering.md:58discusses howSELECT FOR UPDATEtakes its locks when a result is read through a cursor. It assumes the statement exists but does not say how to build it.- The Prisma 7 test "high concurrency with SET FOR UPDATE" was not ported, because it uses raw SQL inside a transaction:
projects/port-all-tests/checklists/prisma-functional-0-l.md:991,test/integration/test/ports/prisma/functional/interactive-transactions/interactive-transactions.test.ts:56, andtest/integration/test/ports/prisma/non-ported/functional/interactive-transactions/interactive-transactions.md:58. docs/architecture docs/adrs/ADR 208 - Invariant-aware migration routing.md:104mentions "the row lock" that a migration'sUPDATEtakes. That is the lock every update takes, not a locking clause on a select.docs/has no other mention ofFOR UPDATE,SKIP LOCKED,NOWAITor row locks. The other matches forFOR UPDATEare row-level security policies (CREATE POLICY ... FOR UPDATE). No ADR is about row locks.- The
prisma-8skill (skills/prisma-8/) has no mention of row locks,FOR UPDATEorSKIP LOCKED. Its transactions section,skills/prisma-8/references/queries-postgres.md:421-441, does not say how to lock a row.
Getting the code
git clone https://github.com/prisma/orm.git
cd orm
git checkout 64f6c3e3b701324618419cf2832ae789f3b0f514
corepack enable
pnpm install --frozen-lockfile
pnpm buildNode must satisfy engines.node in package.json (24 or later); CONTRIBUTING.md recommends mise. The tests for the packages this ticket touches:
pnpm --filter @internal/sql-relational-core test
pnpm --filter @internal/sql-builder test
pnpm --filter @internal/sql-orm-client test
pnpm --filter @internal/adapter-postgres test
pnpm --filter @internal/adapter-sqlite test
pnpm --filter integration-tests testBefore a pull request, CONTRIBUTING.md asks for pnpm typecheck && pnpm lint && pnpm test:packages, and pnpm test:integration when the SQL runtime changes.
Reproduction
This is a standalone project against the published package. It needs no database: it shows the type errors, lists the methods each builder has, and renders the statements with the Postgres adapter.
package.json:
{ "name": "orm-row-lock-repro", "private": true, "type": "module" }contract.prisma:
// use prisma-8
model Contact {
id String @id
name String
@@map("contact")
}prisma.config.ts:
import { defineConfig } from '@prisma/orm-postgres/config';
import { definePrismaConfig } from 'prisma/config';
export default definePrismaConfig({
orm: defineConfig({ contract: './contract.prisma' }),
});tsconfig.json:
{
"compilerOptions": {
"target": "es2024",
"module": "nodenext",
"moduleResolution": "nodenext",
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"types": ["node"]
},
"files": ["repro.ts", "render.ts"]
}repro.ts, the lock we want to write, through each builder:
import postgres from '@prisma/orm-postgres/runtime';
import type { Contract } from './contract.d.ts';
import contractJson from './contract.json' with { type: 'json' };
const db = postgres<Contract>({ contractJson });
const id = 'c1';
// 1. The typed SQL builder: `SELECT "id" FROM "contact" WHERE "id" = $1`, then a lock.
const typed = db.sql.public.contact.select('id').where((f, fns) => fns.eq(f.id, id));
typed.forNoKeyUpdate();
// 2. The ORM client: the same read, then a lock.
const orm = db.orm.public.Contact.select('id').where({ id });
orm.lock('noKeyUpdate');render.ts, what each builder offers and renders, and the raw statement we need instead:
import { createPostgresAdapter } from '@prisma/orm-postgres/adapter/adapter';
import postgres from '@prisma/orm-postgres/runtime';
import type { Contract } from './contract.d.ts';
import contractJson from './contract.json' with { type: 'json' };
const db = postgres<Contract>({ contractJson });
const adapter = createPostgresAdapter();
const id = 'c1';
const typed = db.sql.public.contact.select('id').where((f, fns) => fns.eq(f.id, id));
const orm = db.orm.public.Contact.select('id').where({ id });
function lockingMethods(query: object): string[] {
const names = new Set<string>();
for (let p: object | null = query; p && p !== Object.prototype; p = Object.getPrototypeOf(p)) {
for (const name of Object.getOwnPropertyNames(p)) names.add(name);
}
return [...names].filter((name) => /lock|^for[A-Z]|share|skip|nowait/i.test(name));
}
console.log('typed builder, methods about locking:', lockingMethods(typed));
console.log('ORM client, methods about locking:', lockingMethods(orm));
const typedPlan = typed.build();
console.log('typed builder renders:', adapter.lower(typedPlan.ast, { contract: db.contract }).sql);
const rawPlan = db.raw.sql`SELECT "id" FROM "contact" WHERE "id" = ${id} FOR NO KEY UPDATE`
.affectedCount()
.build();
console.log('raw lane renders:', adapter.lower(rawPlan.ast, { contract: db.contract }).sql);Commands (Node 24.16.0, npm 11.13.0):
npm install @prisma/[email protected] [email protected] [email protected] @types/node@24
npx prisma contract emit
npx tsc -p .
node render.tsnpx prisma contract emit writes contract.json and contract.d.ts. npx tsc -p . exits with code 2:
repro.ts(10,7): error TS2339: Property 'forNoKeyUpdate' does not exist on type 'SelectQuery<ContractToQC<Contract, "public", "contact">, DefaultScope<"contact", { columns: { readonly id: { readonly nativeType: "text"; readonly codecId: "pg/text@1"; readonly nullable: false; }; readonly name: { ...; }; }; primaryKey: { ...; }; uniques: readonly []; indexes: readonly []; foreignKeys: readonly [];...'.
repro.ts(14,5): error TS2339: Property 'lock' does not exist on type 'Collection<Contract, "Contact", { id: string; }, WithWhereState<WithNsId<DefaultCollectionTypeState, "public">>>'.
node render.ts prints:
typed builder, methods about locking: []
ORM client, methods about locking: []
typed builder renders: SELECT "id" AS "id" FROM "public"."contact" WHERE "id" = $1
raw lane renders: SELECT "id" FROM "contact" WHERE "id" = $1 FOR NO KEY UPDATE
For reference, the full method lists are: typed builder ctx state distinctOn constructor clone select where orderBy limit offset distinct annotate groupBy as getRowFields buildAst build _gate; ORM client ctx contract modelName tableName namespaceId state registry includeRefinementMode count countBigInt sum sumBigInt avg avgDecimal min max constructor where variant include select orderBy groupBy combine cursor distinct distinctOn limit offset all prepared first aggregate create createAll createAndCount upsert update updateAll updateAndCount delete deleteAll deleteAndCount.
The last line is what the application runs today. It works, but the table and column names are unchecked strings, the result has no typed row, and a rename in the contract does not reach it.
Expected behaviour
Both builders can end a select with a locking clause, on targets that support one. The Postgres forms are:
| Strength | Renders as |
|---|---|
update |
FOR UPDATE |
noKeyUpdate |
FOR NO KEY UPDATE |
share |
FOR SHARE |
keyShare |
FOR KEY SHARE |
Each may name the tables it locks (OF "contact", by table name or alias as written in FROM, without a schema, because Postgres refuses a schema-qualified name there), and may end with NOWAIT (fail at once if a row is locked) or SKIP LOCKED (leave out rows that are locked). Without either, the statement waits. A select may carry more than one locking clause, for different tables. The clause is rendered last, after LIMIT and OFFSET:
SELECT "id" AS "id" FROM "public"."contact" WHERE "id" = $1 FOR NO KEY UPDATE
SELECT "id" AS "id" FROM "public"."job" WHERE "state" = $1 ORDER BY "createdAt" ASC LIMIT $2 FOR UPDATE SKIP LOCKED
SELECT "c"."id" AS "id" FROM "public"."contact" AS "c" INNER JOIN "public"."identity" AS "i" ON ... FOR UPDATE OF "c" NOWAITOn a target without row locks, the method does not exist in the types, and a hand-built syntax tree that carries a lock is refused when it is rendered.
Cause
The clause is missing at every layer.
The syntax tree has no field for it. packages/2-sql/4-lanes/relational-core/src/ast/types.ts:1583-1596:
export interface SelectAstOptions {
readonly from?: AnyFromSource;
readonly joins: ReadonlyArray<JoinAst> | undefined;
readonly projection: ReadonlyArray<ProjectionItem>;
readonly where: AnyExpression | undefined;
readonly orderBy: ReadonlyArray<OrderByItem> | undefined;
readonly distinct: true | undefined;
readonly distinctOn: ReadonlyArray<AnyExpression> | undefined;
readonly groupBy: ReadonlyArray<AnyExpression> | undefined;
readonly having: AnyExpression | undefined;
readonly limit: LimitOffsetValue | undefined;
readonly offset: LimitOffsetValue | undefined;
readonly selectAllIntent: { readonly table?: string } | undefined;
}The Postgres renderer stops at OFFSET. packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts:227-241:
const clauses = [
selectClause,
fromClause,
joinsClause,
whereClause,
groupByClause,
havingClause,
orderClause,
limitClause,
offsetClause,
]
.filter((part) => part.length > 0)
.join(' ');
return clauses.trim();The SQLite renderer has the same list (packages/3-targets/6-adapters/sqlite/src/core/adapter.ts:257-270).
The typed builder's SelectQuery has no locking method (packages/2-sql/4-lanes/sql-builder/src/types/select-query.ts:18-81, quoted in part):
export interface SelectQuery<QC extends QueryContext, AvailableScope extends Scope, RowType extends Record<string, ScopeField>>
extends Subquery<RowType>, WithSelect<QC, AvailableScope, RowType>, WithPagination<QC>, WithDistinct, WithAlias<RowType>, WithBuild<QC, RowType> {
annotate<...>(...): SelectQuery<QC, AvailableScope, RowType>;
where(expr: ExpressionBuilder<AvailableScope, QC>): SelectQuery<QC, AvailableScope, RowType>;
orderBy(...): SelectQuery<QC, AvailableScope, RowType>;
groupBy(...): GroupedQuery<QC, AvailableScope, RowType>;
distinctOn: GatedMethod<QC['capabilities'], { postgres: { distinctOn: true } }, {...}>;
}The ORM client's CollectionState has no locking field (packages/3-extensions/sql-orm-client/src/types.ts:89-110: filters, includes, orderBy, cursor, distinct, distinctOn, selectedFields, limit, offset, variantName, annotations), and buildSelectAst (packages/3-extensions/sql-orm-client/src/query-plan-select.ts:1418-1443) sets only projection, where, orderBy, select-all intent, distinctOn, limit, offset and joins on the tree.
Design questions, with recommendations
1. Where does the clause sit in the typed builder's grammar?
Recommendation: one method, lock(strength, options?), on SelectQuery only, and not on GroupedQuery. Postgres refuses a locking clause together with GROUP BY, HAVING, DISTINCT, aggregate functions, window functions and UNION, INTERSECT or EXCEPT, so groupBy() already leading to GroupedQuery keeps the most common refusal out of the types. lock() returns a SelectQuery so that where, orderBy, limit, offset and build may still follow, in any order, like the other clauses. A select that uses distinct, distinctOn or an aggregate in its projection together with lock() throws a structured error at build(), rather than sending a statement Postgres will refuse. lock() may be called more than once, each with a different of, and each call adds a clause.
A locked select used as a subquery in FROM (.as(...)) is valid Postgres, but it is rare. The first version may refuse it at build() and leave it for later.
2. Does the ORM client expose it, and how?
Recommendation: yes, as Collection.lock(strength, options?), for example .lock('noKeyUpdate'), stored in CollectionState and read by buildSelectAst. The ORM renders OF "<model table or its alias>" always, so that only the model's own rows are locked. Without OF, Postgres tries to lock every table in FROM, and include adds joins and subqueries whose rows the caller did not ask to lock; Postgres also refuses to lock the nullable side of an outer join. lock() together with groupBy, aggregate, distinct or distinctOn throws a structured error when the query is compiled. Only the read terminals (all, first) use the lock; a mutation terminal (update, delete and the others) called on a locked collection throws, because a mutation already locks the rows it changes and silently dropping the requested lock would hide a mistake.
The ORM does not refuse a lock outside a transaction. The lock is then released as soon as the statement ends, which is legal Postgres and sometimes intended (for example NOWAIT to test whether a row is free). The documentation should say that a lock lasts until the transaction ends, so it is only useful inside db.transaction(...).
3. How are NOWAIT and SKIP LOCKED expressed?
Recommendation: as one option, wait, with three values, so the two cannot be combined by mistake:
.lock('update') // waits
.lock('update', { wait: 'nowait' }) // FOR UPDATE NOWAIT
.lock('update', { wait: 'skipLocked' }) // FOR UPDATE SKIP LOCKED
.lock('noKeyUpdate', { of: ['c'] }) // typed builder: FOR NO KEY UPDATE OF "c"In the typed builder, of takes the names of tables or aliases in scope and is checked against the scope in the types, as distinctOn checks its fields. In the ORM, of is not offered, for the reason in question 2. A lock that fails under NOWAIT surfaces as the driver's lock_not_available error (SQLSTATE 55P03); it would help to map it to a structured error code.
4. What happens on a target without row locks?
Recommendation: gate it by capability, exactly as distinctOn is. The Postgres adapter declares postgres: { rowLocking: true } next to distinctOn (adapter.ts:20-39 and descriptor-meta.ts:150-165). In the typed builder, lock is a GatedMethod on that capability, so it does not exist for a SQLite contract. In the ORM, the parameter type is never without the capability, and an assertion like assertDistinctOnCapability throws ORM.CAPABILITY_MISSING at run time. SQLite has no row locks (a writer locks the whole database), so the SQLite renderer throws a structured error if it is handed a SelectAst that carries a lock, rather than dropping it. MongoDB is not affected.
Implementation outline
- Syntax tree (
packages/2-sql/4-lanes/relational-core/src/ast/types.ts): add aLockingClausenode withstrength: 'update' | 'noKeyUpdate' | 'share' | 'keyShare',of: ReadonlyArray<string> | undefinedandwait: 'wait' | 'nowait' | 'skipLocked'. Addlocking: ReadonlyArray<LockingClause> | undefinedtoSelectAstOptionsandSelectAst, and carry it through the constructor,from(),noFrom(),toOptions()andrewrite(). AddwithLocking(...). The constructor refuses a lock combined withdistinct,distinctOn,groupByorhaving. - Postgres renderer (
packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts): render each clause afteroffsetClauseinrenderSelect, withOFnames quoted but not schema-qualified. Declare the capability inadapter.tsanddescriptor-meta.ts. - SQLite renderer (
packages/3-targets/6-adapters/sqlite/src/core/adapter.ts): throw a structured error inrenderSelectwhenast.lockingis set. - Typed builder: add
lockingto the builder state inpackages/2-sql/4-lanes/sql-builder/src/runtime/builder-base.tsand to the tree it builds; add the gatedlocktoquery-impl.tsand toSelectQueryintypes/select-query.ts; refuse a lock with an aggregate projection atbuild(). - ORM client: add
locktoCollectionState(types.ts) andemptyState(); addCollection.lock()incollection.tswith the capability check; inbuildSelectAst(query-plan-select.ts), apply the lock withOFthe model's table; refuse it withgroupBy,aggregate,distinct,distinctOnand mutation terminals. - Update
packages/2-sql/4-lanes/sql-builder/STATUS.md: move row locking from "What's missing" (line 51) to what is supported.
Acceptance criteria
Tests to add:
packages/2-sql/4-lanes/relational-core/test/ast/builders.test.ts: aSelectAstkeeps its locking clauses throughwith...calls andrewrite(), and refuses a lock withdistinct,distinctOn,groupByorhaving.packages/3-targets/6-adapters/postgres/test/adapter.test.ts: each of the four strengths renders;NOWAITandSKIP LOCKEDrender;OFrenders an unqualified quoted name; two clauses render in order; the clause comes afterLIMITandOFFSET.packages/3-targets/6-adapters/sqlite/test/adapter.test.ts: a select carrying a lock is refused with a structured error.packages/2-sql/4-lanes/sql-builder/test/runtime/builders.test.ts:lock()puts the clause on the built tree;build()refuses a lock with an aggregate projection.- A new
packages/2-sql/4-lanes/sql-builder/test/types/lock.types.test-d.ts:lockexists on a PostgresSelectQuery, not onGroupedQuery, not on a contract without the capability;ofaccepts only names in scope;waitaccepts only the three values. - New
packages/3-extensions/sql-orm-client/test/lock-capability.test.tsandlock-capability.test-d.ts, modelled ondistinct-on-capability.test.tsanddistinct-on-capability.test-d.ts: the method exists only with the capability, and throwsORM.CAPABILITY_MISSINGwithout it. packages/3-extensions/sql-orm-client/test/query-plan-select.test.ts:lock()with and withoutincluderendersOFthe model's table; the refusals in design question 2 hold.- A new
test/integration/test/sql-builder/lock.test.tsand a test undertest/integration/test/sql-orm-client/: each variant runs inside a transaction against the embedded Postgres and returns the expected row. The embedded Postgres (PGlite) serves one connection, so these tests check that Postgres accepts the statements, not that a second transaction waits. If the suite gains a real Postgres server, port the Prisma 7 test "high concurrency with SET FOR UPDATE" (listed as non-ported intest/integration/test/ports/prisma/non-ported/functional/interactive-transactions/interactive-transactions.md:58) withlock('update').
Commands that must pass:
pnpm typecheck
pnpm lint
pnpm lint:deps
pnpm test:packages
pnpm test:integrationDocuments and skills to update:
packages/2-sql/4-lanes/sql-builder/STATUS.md(line 51) andpackages/2-sql/4-lanes/sql-builder/README.md.docs/reference/query-patterns.md: a section on locking rows, with the work-queue example (lock('update', { wait: 'skipLocked' })).skills/prisma-8/references/queries-postgres.md: in "Workflow — Transactions" (line 421), showlock()on both builders and say a lock lasts until the transaction ends; in "Common Pitfalls (Postgres)" (line 461), sayFOR NO KEY UPDATEis usually the right strength when other transactions insert or update rows that reference the locked row, becauseFOR UPDATEconflicts with the key-share lock their foreign key checks take.- An upgrade note in
skills/prisma-8/upgrading/for the release that adds it, if new public API is noted there. - Mark the Prisma 7 port "high concurrency with SET FOR UPDATE" as portable in
projects/port-all-tests/checklists/prisma-functional-0-l.md:991once it is ported.
Related
- TML-3347, TML-3348 and TML-3350: earlier gaps in the typed SQL builder found by the same application.
- Row locking support in
find*()queries (viaFOR UPDATE) #17136,SELECT FOR UPDATE#8580 and Add support for row-level locking (viaFOR UPDATE SKIP LOCKED) #5983 in this repository ask for the same feature in the Prisma 6 and 7 client.
Out of scope
- Table-level locks (
LOCK TABLE) and advisory locks (pg_advisory_xact_lock). - Locking clauses on
UPDATEorDELETEstatements, which lock the rows they change already. - Isolation levels and
SET TRANSACTION. - Row locks for MySQL or any target other than Postgres; the capability leaves room for them.
- A raw lane on the transaction context (
tx.raw); the application worked around its absence, and this feature removes the need.
Activity
Design: row locking clauses on a select (FOR UPDATE, SKIP LOCKED) in …
TML-3415: The ORM client locks the rows a collection reads with forUp…
TML-3415: Close out the select row locking project (prisma#30643)