Skip to content

feat(sap): support locking in select - #11996

Merged
alumni merged 1 commit into
typeorm:masterfrom
alumni:feat/sap-hana-locking
Feb 17, 2026
Merged

alumni merged 1 commit into
typeorm:masterfrom
alumni:feat/sap-hana-locking

Conversation

@alumni

@alumni alumni commented Feb 16, 2026

Copy link
Copy Markdown
Collaborator

Description of change

Add locking support in SELECT for SAP HANA.

Fixes #11985.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

@alumni
alumni requested a review from naorpeled February 16, 2026 16:03
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

User description

Description of change

Add locking support in SELECT for SAP HANA.

Fixes #11985.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

PR Type

Enhancement, Tests


Description

  • Add SAP HANA locking support in SELECT queries with appropriate SQL syntax

  • Implement SAP-specific lock modes: FOR SHARE LOCK, FOR UPDATE, and IGNORE LOCKED

  • Update test suite to validate SAP HANA locking behavior across all lock modes

  • Update documentation with SAP HANA lock mode support matrix and examples


Diagram Walkthrough

flowchart LR
  A["SelectQueryBuilder"] -->|"Add SAP HANA support"| B["createLockExpression"]
  B -->|"pessimistic_read"| C["FOR SHARE LOCK"]
  B -->|"pessimistic_write"| D["FOR UPDATE"]
  B -->|"skip_locked"| E["IGNORE LOCKED"]
  B -->|"nowait"| F["NOWAIT"]
  G["Tests"] -->|"Validate SAP syntax"| H["Lock mode assertions"]
  I["Documentation"] -->|"Update matrix"| J["SAP HANA row"]
Loading

File Walkthrough

Relevant files
Enhancement
SelectQueryBuilder.ts
Implement SAP HANA-specific lock expression syntax             

src/query-builder/SelectQueryBuilder.ts

  • Replace cockroachdb driver check with sap in lock table validation
    logic
  • Add SAP-specific IGNORE LOCKED syntax for skip_locked mode instead of
    SKIP LOCKED
  • Implement FOR SHARE LOCK syntax for SAP in pessimistic_read lock mode
  • Add FOR UPDATE IGNORE LOCKED syntax for SAP in
    pessimistic_partial_write mode
  • Replace cockroachdb with sap in pessimistic_write_or_fail mode
  • Remove SAP from for_no_key_update case (PostgreSQL-only feature)
  • Update JSDoc comment for createLockExpression method
+16/-9   
Tests
query-builder-locking.test.ts
Update locking tests to support SAP HANA                                 

test/functional/query-builder/locking/query-builder-locking.test.ts

  • Remove SAP HANA from unsupported driver checks in multiple test cases
  • Add SAP-specific assertions for FOR SHARE LOCK in pessimistic_read
    tests
  • Add SAP-specific assertions for IGNORE LOCKED in skip_locked tests
  • Add SAP-specific assertions for NOWAIT in nowait tests
  • Refactor test structure to remove unnecessary Promise.all wrappers for
    synchronous SQL generation tests
  • Update for_no_key_update tests to use DriverUtils.isPostgresFamily()
    instead of explicit driver checks
  • Simplify test conditions by removing SAP from unsupported driver lists
+284/-323
find-options-locking.test.ts
Update repository find options locking tests for SAP         

test/functional/repository/find-options-locking/find-options-locking.test.ts

  • Remove SAP HANA from unsupported driver checks in multiple test cases
  • Add SAP-specific assertions for FOR SHARE LOCK in pessimistic_read
    tests
  • Add SAP-specific assertions for IGNORE LOCKED in skip_locked tests
  • Update driver checks to use DriverUtils.isPostgresFamily() for
    consistency
  • Simplify test conditions by removing SAP from unsupported driver lists
  • Fix async/await patterns in transaction callbacks
+56/-68 
Documentation
1-select-query-builder.md
Document SAP HANA lock mode support in matrix                       

docs/docs/query-builder/1-select-query-builder.md

  • Add SAP HANA row to lock modes support matrix with specific SQL syntax
  • Update MySQL/MariaDB and Postgres/CrDB labels for clarity
  • Remove CockroachDB from separate matrix row (merged into Postgres)
  • Add SAP HANA to setOnLocked database support documentation
  • Document SAP support for pessimistic_read and pessimistic_write modes
+5/-4     
3-find-options.md
Add lock options example to find options docs                       

docs/docs/working-with-entity-manager/3-find-options.md

  • Add lock options example to find options documentation
  • Include pessimistic_write with nowait in complete example
  • Improve documentation structure with "Example" section header
+7/-1     

@alumni
alumni requested review from G0maa, gioboa and mguida22 February 16, 2026 16:04
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Feb 16, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to 99f2745

CategorySuggestion                                                                                                                                    Impact
Possible issue
Avoid exiting tests prematurely

In test files, replace return with continue inside for...of loops that iterate
over connections. This will prevent tests from exiting prematurely and ensure
all relevant database connections are tested.

test/functional/query-builder/locking/query-builder-locking.test.ts [289-326]

 it("should attach pessimistic read lock statement on query if locking enabled", () => {
     for (const connection of connections) {
         if (
             DriverUtils.isSQLiteFamily(connection.driver) ||
             connection.driver.options.type === "spanner"
         ) {
-            return
+            continue
         }
 
         const sql = connection
             .createQueryBuilder(PostWithVersion, "post")
             .setLock("pessimistic_read")
             .where("post.id = :id", { id: 1 })
             .getSql()
 
         if (DriverUtils.isMySQLFamily(connection.driver)) {
             if (
                 connection.driver.options.type === "mysql" &&
                 DriverUtils.isReleaseVersionOrGreater(
                     connection.driver,
                     "8.0",
                 )
             ) {
                 expect(sql).to.contain("FOR SHARE")
             } else {
                 expect(sql).to.contain("LOCK IN SHARE MODE")
             }
         } else if (DriverUtils.isPostgresFamily(connection.driver)) {
             expect(sql).to.contain("FOR SHARE")
         } else if (connection.driver.options.type === "sap") {
             expect(sql).to.contain("FOR SHARE LOCK")
         } else if (connection.driver.options.type === "oracle") {
             expect(sql).to.contain("FOR UPDATE")
         } else if (connection.driver.options.type === "mssql") {
             expect(sql).to.contain("WITH (HOLDLOCK, ROWLOCK)")
         }
     }
 })
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: This suggestion correctly identifies a critical bug in the refactored tests where return is used instead of continue, causing tests to exit prematurely and potentially miss failures for some database drivers.

High
Ensure MSSQL assertions run

In the 'should attach dirty read lock statement' test, replace return with
continue to ensure the test logic runs for all applicable connections instead of
exiting on the first non-applicable one.

test/functional/query-builder/locking/query-builder-locking.test.ts [328-342]

 it("should attach dirty read lock statement on query if locking enabled", () => {
     for (const connection of connections) {
-        if (!(connection.driver.options.type === "mssql")) {
-            return
+        if (connection.driver.options.type !== "mssql") {
+            continue
         }
 
         const sql = connection
             .createQueryBuilder(PostWithVersion, "post")
             .setLock("dirty_read")
             .where("post.id = :id", { id: 1 })
             .getSql()
 
         expect(sql).to.contain("WITH (NOLOCK)")
     }
 })
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: This suggestion correctly identifies a critical bug in a test where return is used instead of continue, which would cause the test to skip assertions for the intended database driver (mssql).

High
  • More

Previous suggestions

Suggestions up to commit 8baeee2
CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix premature test exits

Replace return with continue inside test loops to ensure all database
connections are properly tested instead of exiting the test prematurely.

test/functional/query-builder/locking/query-builder-locking.test.ts [328-342]

 it("should attach dirty read lock statement on query if locking enabled", () => {
     for (const connection of connections) {
-        if (!(connection.driver.options.type === "mssql")) {
-            return
+        if (connection.driver.options.type !== "mssql") {
+            continue
         }
 
         const sql = connection
             .createQueryBuilder(PostWithVersion, "post")
             .setLock("dirty_read")
             .where("post.id = :id", { id: 1 })
             .getSql()
 
         expect(sql).to.contain("WITH (NOLOCK)")
     }
 })
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a bug in the new tests where return is used instead of continue, causing tests to exit prematurely and not run against all intended database connections.

Medium
Ensure tests actually execute

Fix unhandled assertions in tests by replacing connections.map with a for...of
loop or by wrapping it with Promise.all.

test/functional/query-builder/locking/query-builder-locking.test.ts [929-944]

-it("pessimistic_partial_write and skip_locked works", () =>
-    connections.map((connection) => {
+it("pessimistic_partial_write and skip_locked works", () => {
+    for (const connection of connections) {
         if (
             DriverUtils.isMySQLFamily(connection.driver) ||
             DriverUtils.isPostgresFamily(connection.driver)
         ) {
             const sql = connection
                 .createQueryBuilder(PostWithVersion, "post")
                 .setLock("pessimistic_partial_write")
                 .setOnLocked("skip_locked")
                 .where("post.id = :id", { id: 1 })
                 .getSql()
 
             expect(sql.endsWith("FOR UPDATE SKIP LOCKED")).to.be.true
         }
-    }))
+    }
+})
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that new tests using connections.map without Promise.all will not handle assertions correctly, potentially leading to silently passing tests.

Medium
Suggestions up to commit 8174ff2
CategorySuggestion                                                                                                                                    Impact
Possible issue
Avoid prematurely exiting tests

Replace return with continue in test loops to prevent premature exit and ensure
all database connections are tested.

test/functional/query-builder/locking/query-builder-locking.test.ts [289-326]

 it("should attach pessimistic read lock statement on query if locking enabled", () => {
     for (const connection of connections) {
         if (
             DriverUtils.isSQLiteFamily(connection.driver) ||
             connection.driver.options.type === "spanner"
         ) {
-            return
+            continue
         }
 
         const sql = connection
             .createQueryBuilder(PostWithVersion, "post")
             .setLock("pessimistic_read")
             .where("post.id = :id", { id: 1 })
             .getSql()
 
         if (DriverUtils.isMySQLFamily(connection.driver)) {
             if (
                 connection.driver.options.type === "mysql" &&
                 DriverUtils.isReleaseVersionOrGreater(
                     connection.driver,
                     "8.0",
                 )
             ) {
                 expect(sql).to.contain("FOR SHARE")
             } else {
                 expect(sql).to.contain("LOCK IN SHARE MODE")
             }
         } else if (DriverUtils.isPostgresFamily(connection.driver)) {
             expect(sql).to.contain("FOR SHARE")
         } else if (connection.driver.options.type === "sap") {
             expect(sql).to.contain("FOR SHARE LOCK")
         } else if (connection.driver.options.type === "oracle") {
             expect(sql).to.contain("FOR UPDATE")
         } else if (connection.driver.options.type === "mssql") {
             expect(sql).to.contain("WITH (HOLDLOCK, ROWLOCK)")
         }
     }
 })
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical bug in the refactored tests where using return instead of continue would cause tests to exit prematurely, leading to tests passing without running assertions on all intended database drivers.

High
Ensure driver-specific tests run

Fix the test by using continue to iterate through all connections and add a flag
to assert that the MSSQL-specific test logic has been executed.

test/functional/query-builder/locking/query-builder-locking.test.ts [328-342]

 it("should attach dirty read lock statement on query if locking enabled", () => {
+    let tested = false
+
     for (const connection of connections) {
-        if (!(connection.driver.options.type === "mssql")) {
-            return
+        if (connection.driver.options.type !== "mssql") {
+            continue
         }
+        tested = true
 
         const sql = connection
             .createQueryBuilder(PostWithVersion, "post")
             .setLock("dirty_read")
             .where("post.id = :id", { id: 1 })
             .getSql()
 
         expect(sql).to.contain("WITH (NOLOCK)")
     }
+
+    expect(tested).to.be.true
 })
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical bug in a test and provides a robust fix, not only by replacing return with continue but also by adding an assertion to ensure the test logic is executed, preventing false positives.

High
Suggestions up to commit a8e7fda
CategorySuggestion                                                                                                                                    Impact
Possible issue
Make tests properly awaited

Refactor test cases to correctly handle asynchronous operations by using
Promise.all or a synchronous loop, ensuring the test runner awaits all
assertions.

test/functional/query-builder/locking/query-builder-locking.test.ts [34-51]

-it("should not attach pessimistic read lock statement on query if locking is not used", () =>
-    connections.map((connection) => {
+it("should not attach pessimistic read lock statement on query if locking is not used", () => {
+    for (const connection of connections) {
         if (
             DriverUtils.isSQLiteFamily(connection.driver) ||
             connection.driver.options.type === "spanner"
         ) {
-            return
+            continue
         }
 
         const sql = connection
             .createQueryBuilder(PostWithVersion, "post")
             .where("post.id = :id", { id: 1 })
             .getSql()
 
         expect(sql).not.to.contain("LOCK IN SHARE MODE")
         expect(sql).not.to.contain("FOR SHARE")
         expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
-    }))
+    }
+})
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical issue in the test suite where asynchronous tests are not properly awaited, potentially leading to missed failures and an unreliable CI process.

High
Restore CockroachDB lock support

Restore CockroachDB support for pessimistic_write and for_no_key_update lock
modes to prevent a functional regression.

src/query-builder/SelectQueryBuilder.ts [2872-2921]

 case "pessimistic_write":
     if (
         DriverUtils.isMySQLFamily(driver) ||
         driver.options.type === "aurora-mysql" ||
         driver.options.type === "oracle"
     ) {
         return " FOR UPDATE" + onLockExpression
     } else if (
         DriverUtils.isPostgresFamily(driver) ||
+        driver.options.type === "cockroachdb" ||
         driver.options.type === "sap"
     ) {
         return " FOR UPDATE" + lockTablesClause + onLockExpression
     } else if (driver.options.type === "mssql") {
         return ""
     } else {
         throw new LockNotSupportedOnGivenDriverError()
     }
 ...
 case "for_no_key_update":
-    if (DriverUtils.isPostgresFamily(driver)) {
+    if (
+        DriverUtils.isPostgresFamily(driver) ||
+        driver.options.type === "cockroachdb"
+    ) {
         return (
             " FOR NO KEY UPDATE" +
             lockTablesClause +
             onLockExpression
         )
     }
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a significant regression where CockroachDB support for several pessimistic lock modes was unintentionally removed, which would break existing functionality for that database.

High
Prevent invalid lock table SQL

Prevent generating invalid SQL by restricting the lockTables option to only
drivers that support the OF ... clause, and explicitly disallow it for SAP HANA.

src/query-builder/SelectQueryBuilder.ts [2815-2830]

 if (this.expressionMap.lockTables) {
-    if (
-        !(
-            DriverUtils.isPostgresFamily(driver) ||
-            driver.options.type === "sap"
-        )
-    ) {
+    const supportsLockTables =
+        DriverUtils.isPostgresFamily(driver) ||
+        driver.options.type === "cockroachdb"
+
+    if (!supportsLockTables) {
         throw new TypeORMError(
             "Lock tables not supported in selected driver",
         )
     }
     if (this.expressionMap.lockTables.length < 1) {
         throw new TypeORMError("lockTables cannot be an empty array")
     }
     lockTablesClause = " OF " + this.expressionMap.lockTables.join(", ")
 }
Suggestion importance[1-10]: 8

__

Why: This suggestion correctly points out that adding sap to the list of drivers supporting lockTables could generate invalid SQL, as SAP HANA may not support the OF ... clause. This prevents a potential runtime bug.

Medium
Suggestions up to commit f47549e
CategorySuggestion                                                                                                                                    Impact
General
Validate onLocked compatibility

Add a check in setOnLocked to ensure the current lock mode supports onLocked
options, throwing an error if it is incompatible.

src/query-builder/SelectQueryBuilder.ts [1678-1681]

 setOnLocked(onLocked: "nowait" | "skip_locked"): this {
+  const mode = this.expressionMap.lockMode
+  const supported = ["pessimistic_read","pessimistic_write","pessimistic_partial_write","pessimistic_write_or_fail","for_no_key_update","for_key_share"]
+  if (!supported.includes(mode!)) {
+    throw new LockNotSupportedOnGivenDriverError(`Lock mode "${mode}" does not support onLocked`)
+  }
   this.expressionMap.onLocked = onLocked
   return this
 }
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that setOnLocked can be called with an incompatible lock mode, leading to late-stage errors. Adding a guard improves robustness and provides clearer, earlier feedback to the user.

Medium
Use forEach in sync tests

In test files, replace .map() with .forEach() for iterating over connections
when the loop is synchronous and does not produce a new array.

test/functional/query-builder/locking/query-builder-locking.test.ts [360-396]

 it("should attach pessimistic read lock statement on query if locking enabled", () =>
-  connections.map((connection) => {
+  connections.forEach((connection) => {
     if (
       DriverUtils.isSQLiteFamily(connection.driver) ||
       connection.driver.options.type === "cockroachdb" ||
       connection.driver.options.type === "spanner"
     )
       return
     const sql = connection
       .createQueryBuilder(PostWithVersion, "post")
       .setLock("pessimistic_read")
       .where("post.id = :id", { id: 1 })
       .getSql()
     ...
   }))
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly points out that using .map for side effects in tests is not ideal. Replacing it with .forEach improves code clarity and semantic correctness, as no new array is expected.

Low

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Feb 16, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Grey Divider

Previous review results

Review updated until commit 99f2745

Results up to commit 8baeee2


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review Grey Divider Grey Divider
Results up to commit 8174ff2


🐞 Bugs (8) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider
Action required
1. Early return skips connections 📘 Rule violation ⛯ Reliability ⭐ New
Description
Several locking tests now use return inside a for (const connection of connections) loop, which
exits the entire test on the first unsupported driver instead of skipping just that driver. This can
hide failures on later connections and is inconsistent/bug-prone test control flow.
Code

test/functional/query-builder/locking/query-builder-locking.test.ts[R34-40]

+        for (const connection of connections) {
+            if (
+                DriverUtils.isSQLiteFamily(connection.driver) ||
+                connection.driver.options.type === "spanner"
+            ) {
+                return
+            }
Evidence
PR Compliance ID 4 requires avoiding AI-generated noise and inconsistent style; replacing
per-connection skipping logic with an early return inside a loop is a suspicious refactor that
changes behavior by prematurely terminating the test, leaving subsequent connections unvalidated.

Rule 4: Remove AI-generated noise
test/functional/query-builder/locking/query-builder-locking.test.ts[34-40]
test/functional/query-builder/locking/query-builder-locking.test.ts[329-333]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Several tests iterate over `connections` using `for (const connection of connections)` but use `return` to skip unsupported drivers. In a loop, `return` exits the entire test function, so subsequent connections are never validated.

## Issue Context
This refactor changes test behavior compared to the prior `connections.map(...)` approach where `return` only exited the callback for a single connection. This is likely unintentional and can mask failures.

## Fix Focus Areas
- test/functional/query-builder/locking/query-builder-locking.test.ts[33-51]
- test/functional/query-builder/locking/query-builder-locking.test.ts[328-342]
- test/functional/query-builder/locking/query-builder-locking.test.ts[344-420]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Double-escaped lockTables 🐞 Bug ✓ Correctness ⭐ New
Description
createLockExpression() now escapes lockTables, but the FindOptions path already stores escaped
alias names, resulting in double-quoted identifiers (e.g., OF ""post"") and invalid SQL for
Postgres/Cockroach when FindOptions.lock.tables is used.
Code

src/query-builder/SelectQueryBuilder.ts[R2815-2828]

        if (this.expressionMap.lockTables) {
-            if (
-                !(
-                    DriverUtils.isPostgresFamily(driver) ||
-                    driver.options.type === "cockroachdb"
-                )
-            ) {
+            if (!DriverUtils.isPostgresFamily(driver)) {
                throw new TypeORMError(
                    "Lock tables not supported in selected driver",
                )
            }
            if (this.expressionMap.lockTables.length < 1) {
                throw new TypeORMError("lockTables cannot be an empty array")
            }
-            lockTablesClause = " OF " + this.expressionMap.lockTables.join(", ")
+            lockTablesClause =
+                " OF " +
+                this.expressionMap.lockTables
+                    .map((lockTable) => driver.escape(lockTable))
+                    .join(", ")
Evidence
applyFindOptions() converts FindOptions.lock.tables into escaped alias names via
this.escape(tableAlias.name) and then calls setLock(..., tableNames). After this PR,
createLockExpression() applies driver.escape() again to every expressionMap.lockTables entry.
Since Postgres/Cockroach driver.escape() wraps in double-quotes, an already-escaped name like
"post" becomes ""post"", yielding invalid SQL in FOR UPDATE OF clauses. CockroachDB is
included in DriverUtils.isPostgresFamily, so it is affected as well.

src/query-builder/SelectQueryBuilder.ts[2815-2829]
src/query-builder/SelectQueryBuilder.ts[3457-3495]
src/query-builder/QueryBuilder.ts[566-581]
src/driver/postgres/PostgresDriver.ts[1026-1031]
src/driver/DriverUtils.ts[36-44]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`FindOptions.lock.tables` currently stores escaped alias names into `expressionMap.lockTables`, but `createLockExpression()` now escapes `lockTables` again. This produces invalid SQL (double quotes) for Postgres-family drivers when `tables` are provided.

### Issue Context
- `applyFindOptions()` maps `lock.tables` to `this.escape(tableAlias.name)`.
- `createLockExpression()` now maps `expressionMap.lockTables` through `driver.escape()`.
- On Postgres/Cockroach, `escape()` adds double quotes, so an already-escaped value becomes double-escaped.

### Fix Focus Areas
- src/query-builder/SelectQueryBuilder.ts[3457-3495]
- src/query-builder/SelectQueryBuilder.ts[2815-2829]

### Expected change
- In `applyFindOptions()`, pass raw alias names (e.g., `tableAlias.name`) to `setLock(...)` (do not pre-escape).
- Keep escaping in `createLockExpression()` (or use `this.escape(...)` to respect `disableEscaping`) so values are escaped exactly once.
- Add/adjust tests that exercise `FindOptions.lock.tables` to ensure the produced SQL uses a single escaping layer (e.g., `FOR UPDATE OF &quot;post&quot;`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
3. Broken deprecation notice 🐞 Bug ✓ Correctness
Description
The new deprecation notice in the lock-modes section has an unmatched opening parenthesis, which can
render incorrectly in Markdown and confuse readers.
Code

docs/docs/query-builder/1-select-query-builder.md[908]

+> **Deprecation notice:** `pessimistic_partial_write` and `pessimistic_write_or_fail` are deprecated in favor of [onLocked](#setonlocked) (`skip_locked` and `nowait` respectively.
Evidence
The documentation line introduces an opening parenthesis before the inline code list but does not
close it, leaving the sentence grammatically/format-wise incomplete.

docs/docs/query-builder/1-select-query-builder.md[900-909]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The lock-modes documentation contains a deprecation notice with an unmatched opening parenthesis, which can break Markdown rendering.
### Issue Context
This is in the QueryBuilder locking documentation.
### Fix Focus Areas
- docs/docs/query-builder/1-select-query-builder.md[900-909]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Docs: Cockroach duplicated 🐞 Bug ✓ Correctness
Description
setOnLocked docs now simultaneously claim Cockroach supports multiple lock modes and also that it
only supports pessimistic_write (nowait only), which is contradictory and will mislead users.
Code

docs/docs/query-builder/1-select-query-builder.md[R996-1002]

Database support for `setOnLocked` based on [lock mode](#lock-modes):

-- Postgres: `pessimistic_read`, `pessimistic_write`, `for_no_key_update`, `for_key_share`
+- Postgres/Cockroach: `pessimistic_read`, `pessimistic_write`, `for_no_key_update`, `for_key_share`
+- SAP: `pessimistic_read`, `pessimistic_write`
- MySQL 8+: `pessimistic_read`, `pessimistic_write`
- MySQL < 8, Maria DB: `pessimistic_write`
- Cockroach: `pessimistic_write` (`nowait` only)
Evidence
The setOnLocked support list includes CockroachDB in the combined Postgres/Cockroach bullet, but
then also includes a separate Cockroach-only limitation bullet, creating conflicting guidance in the
same section.

docs/docs/query-builder/1-select-query-builder.md[996-1003]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The `setOnLocked` docs list CockroachDB twice with conflicting supported modes, which can cause users to rely on unsupported behavior.
### Issue Context
The PR updated the first bullet to `Postgres/Cockroach: ...` but retained the older separate `Cockroach: pessimistic_write (nowait only)` bullet.
### Fix Focus Areas
- docs/docs/query-builder/1-select-query-builder.md[996-1003]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Docs: Cockroach duplicated 🐞 Bug ✓ Correctness
Description
setOnLocked docs now simultaneously claim Cockroach supports multiple lock modes and also that it
only supports pessimistic_write (nowait only), which is contradictory and will mislead users.
Code

docs/docs/query-builder/1-select-query-builder.md[R996-1002]

Database support for `setOnLocked` based on [lock mode](#lock-modes):
-- Postgres: `pessimistic_read`, `pessimistic_write`, `for_no_key_update`, `for_key_share`
+- Postgres/Cockroach: `pessimistic_read`, `pessimistic_write`, `for_no_key_update`, `for_key_share`
+- SAP: `pessimistic_read`, `pessimistic_write`
- MySQL 8+: `pessimistic_read`, `pessimistic_write`
- MySQL < 8, Maria DB: `pessimistic_write`
- Cockroach: `pessimistic_write` (`nowait` only)
Evidence
The setOnLocked support list includes CockroachDB in the combined Postgres/Cockroach bullet, but
then also includes a separate Cockroach-only limitation bullet, creating conflicting guidance in the
same section.

docs/docs/query-builder/1-select-query-builder.md[996-1003]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The `setOnLocked` docs list CockroachDB twice with conflicting supported modes, which can cause users to rely on unsupported behavior.
### Issue Context
The PR updated the first bullet to `Postgres/Cockroach: ...` but retained the older separate `Cockroach: pessimistic_write (nowait only)` bullet.
### Fix Focus Areas
- docs/docs/query-builder/1-select-query-builder.md[996-1003]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (2)
6. SAP lockTables untested 🐞 Bug ✓ Correctness
Description
lockTables is now permitted for the SAP driver and will emit an  OF  clause, but existing
docs/tests describe and validate this behavior only in terms of the Postgres-style FOR UPDATE OF
clause, leaving SAP’s SQL shape unverified.
Code

src/query-builder/SelectQueryBuilder.ts[R2816-2822]

           if (
               !(
                   DriverUtils.isPostgresFamily(driver) ||
-                    driver.options.type === "cockroachdb"
+                    driver.options.type === "sap"
               )
           ) {
               throw new TypeORMError(
Evidence
The query builder now allows lockTables for SAP and formats it as  OF ..., and also appends it
for SAP locking expressions. However, the documentation describes lockTables specifically in terms
of the FOR UPDATE OF clause and the functional tests only exercise this feature for
Postgres-family drivers, so there’s no in-repo validation that SAP accepts/needs this syntax.

src/query-builder/SelectQueryBuilder.ts[2815-2830]
src/query-builder/SelectQueryBuilder.ts[2859-2864]
docs/docs/query-builder/1-select-query-builder.md[954-968]
test/functional/query-builder/locking/query-builder-locking.test.ts[838-859]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`lockTables` is now allowed for the SAP driver and will generate ` OF ...` in the lock clause, but there is no documentation or test coverage in the repo confirming this SQL is correct/accepted for SAP.
### Issue Context
Docs describe `lockTables` in terms of the `FOR UPDATE OF` clause and tests only assert the behavior for Postgres-family connections. The PR expands the allowlist to include SAP and appends the same ` OF ...` formatting.
### Fix Focus Areas
- src/query-builder/SelectQueryBuilder.ts[2815-2830]
- src/query-builder/SelectQueryBuilder.ts[2859-2864]
- docs/docs/query-builder/1-select-query-builder.md[954-968]
- test/functional/query-builder/locking/query-builder-locking.test.ts[838-859]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. SAP lockTables untested 🐞 Bug ✓ Correctness
Description
lockTables is now permitted for the SAP driver and will emit an  OF  clause, but existing
docs/tests describe and validate this behavior only in terms of the Postgres-style FOR UPDATE OF
clause, leaving SAP’s SQL shape unverified.
Code

src/query-builder/SelectQueryBuilder.ts[R2816-2822]

          if (
              !(
                  DriverUtils.isPostgresFamily(driver) ||
-                    driver.options.type === "cockroachdb"
+                    driver.options.type === "sap"
              )
          ) {
              throw new TypeORMError(
Evidence
The query builder now allows lockTables for SAP and formats it as  OF ..., and also appends it
for SAP locking expressions. However, the documentation describes lockTables specifically in terms
of the FOR UPDATE OF clause and the functional tests only exercise this feature for
Postgres-family drivers, so there’s no in-repo validation that SAP accepts/needs this syntax.

src/query-builder/SelectQueryBuilder.ts[2815-2830]
src/query-builder/SelectQueryBuilder.ts[2859-2864]
docs/docs/query-builder/1-select-query-builder.md[954-968]
test/functional/query-builder/locking/query-builder-locking.test.ts[838-859]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`lockTables` is now allowed for the SAP driver and will generate ` OF ...` in the lock clause, but there is no documentation or test coverage in the repo confirming this SQL is correct/accepted for SAP.
### Issue Context
Docs describe `lockTables` in terms of the `FOR UPDATE OF` clause and tests only assert the behavior for Postgres-family connections. The PR expands the allowlist to include SAP and appends the same ` OF ...` formatting.
### Fix Focus Areas
- src/query-builder/SelectQueryBuilder.ts[2815-2830]
- src/query-builder/SelectQueryBuilder.ts[2859-2864]
- docs/docs/query-builder/1-select-query-builder.md[954-968]
- test/functional/query-builder/locking/query-builder-locking.test.ts[838-859]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments
8. Tests return map arrays 🐞 Bug ⛯ Reliability
Description
Several tests were refactored to return connections.map(...) arrays instead of using forEach
(sync) or Promise.all (async), which is easy to accidentally break if any async work is later
introduced inside the callback.
Code

test/functional/query-builder/locking/query-builder-locking.test.ts[R34-51]

   it("should not attach pessimistic read lock statement on query if locking is not used", () =>
-        Promise.all(
-            connections.map(async (connection) => {
-                if (
-                    DriverUtils.isSQLiteFamily(connection.driver) ||
-                    connection.driver.options.type === "sap" ||
-                    connection.driver.options.type === "spanner"
-                ) {
-                    return
-                }
+        connections.map((connection) => {
+            if (
+                DriverUtils.isSQLiteFamily(connection.driver) ||
+                connection.driver.options.type === "spanner"
+            ) {
+                return
+            }

-                const sql = connection
-                    .createQueryBuilder(PostWithVersion, "post")
-                    .where("post.id = :id", { id: 1 })
-                    .getSql()
+            const sql = connection
+                .createQueryBuilder(PostWithVersion, "post")
+                .where("post.id = :id", { id: 1 })
+                .getSql()

-                expect(sql).not.to.contain("LOCK IN SHARE MODE")
-                expect(sql).not.to.contain("FOR SHARE")
-                expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
-            }),
-        ))
+            expect(sql).not.to.contain("LOCK IN SHARE MODE")
+            expect(sql).not.to.contain("FOR SHARE")
+            expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
+        }))
Evidence
Mocha only waits on returned Promises; returning an array from map() provides no async
coordination and is an unusual pattern even for synchronous assertions. The refactored tests are
currently synchronous (getSql()), but the structure increases the chance of future silent test
bugs if async operations are added.

test/functional/query-builder/locking/query-builder-locking.test.ts[34-51]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Tests returning `connections.map(...)` are relying on synchronous execution and return an array that Mocha does not treat specially. This pattern is brittle if async code is introduced later.
### Issue Context
These test bodies currently call `getSql()` (sync), but the refactor removed `Promise.all` in multiple places.
### Fix Focus Areas
- test/functional/query-builder/locking/query-builder-locking.test.ts[34-51]
- test/functional/query-builder/locking/query-builder-locking.test.ts[360-410]
- test/functional/query-builder/locking/query-builder-locking.test.ts[459-586]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Tests return map arrays 🐞 Bug ⛯ Reliability
Description
Several tests were refactored to return connections.map(...) arrays instead of using forEach
(sync) or Promise.all (async), which is easy to accidentally break if any async work is later
introduced inside the callback.
Code

test/functional/query-builder/locking/query-builder-locking.test.ts[R34-51]

  it("should not attach pessimistic read lock statement on query if locking is not used", () =>
-        Promise.all(
-            connections.map(async (connection) => {
-                if (
-                    DriverUtils.isSQLiteFamily(connection.driver) ||
-                    connection.driver.options.type === "sap" ||
-                    connection.driver.options.type === "spanner"
-                ) {
-                    return
-                }
+        connections.map((connection) => {
+            if (
+                DriverUtils.isSQLiteFamily(connection.driver) ||
+                connection.driver.options.type === "spanner"
+            ) {
+                return
+            }
-                const sql = connection
-                    .createQueryBuilder(PostWithVersion, "post")
-                    .where("post.id = :id", { id: 1 })
-                    .getSql()
+            const sql = connection
+                .createQueryBuilder(PostWithVersion, "post")
+                .where("post.id = :id", { id: 1 })
+                .getSql()
-                expect(sql).not.to.contain("LOCK IN SHARE MODE")
-                expect(sql).not.to.contain("FOR SHARE")
-                expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
-            }),
-        ))
+            expect(sql).not.to.contain("LOCK IN SHARE MODE")
+            expect(sql).not.to.contain("FOR SHARE")
+            expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
+        }))
Evidence
Mocha only waits on returned Promises; returning an array from map() provides no async
coordination and is an unusual pattern even for synchronous assertions. The refactored tests are
currently synchronous (getSql()), but the structure increases the chance of future silent test
bugs if async operations are added.

test/functional/query-builder/locking/query-builder-locking.test.ts[34-51]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Tests returning `connections.map(...)` are relying on synchronous execution and return an array that Mocha does not treat specially. This pattern is brittle if async code is introduced later.
### Issue Context
These test bodies currently call `getSql()` (sync), but the refactor removed `Promise.all` in multiple places.
### Fix Focus Areas
- test/functional/query-builder/locking/query-builder-locking.test.ts[34-51]
- test/functional/query-builder/locking/query-builder-locking.test.ts[360-410]
- test/functional/query-builder/locking/query-builder-locking.test.ts[459-586]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider Grey Divider
Results up to commit a8e7fda


🐞 Bugs (4) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider
Remediation recommended
1. Broken deprecation notice 🐞 Bug ✧ Quality ⭐ New
Description
The new deprecation notice in the lock-modes section has an unmatched opening parenthesis, which can
render incorrectly in Markdown and confuse readers.
Code

docs/docs/query-builder/1-select-query-builder.md[908]

+> **Deprecation notice:** `pessimistic_partial_write` and `pessimistic_write_or_fail` are deprecated in favor of [onLocked](#setonlocked) (`skip_locked` and `nowait` respectively.
Evidence
The documentation line introduces an opening parenthesis before the inline code list but does not
close it, leaving the sentence grammatically/format-wise incomplete.

docs/docs/query-builder/1-select-query-builder.md[900-909]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The lock-modes documentation contains a deprecation notice with an unmatched opening parenthesis, which can break Markdown rendering.

### Issue Context
This is in the QueryBuilder locking documentation.

### Fix Focus Areas
- docs/docs/query-builder/1-select-query-builder.md[900-909]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Docs: Cockroach duplicated 🐞 Bug ✓ Correctness
Description
setOnLocked docs now simultaneously claim Cockroach supports multiple lock modes and also that it
only supports pessimistic_write (nowait only), which is contradictory and will mislead users.
Code

docs/docs/query-builder/1-select-query-builder.md[R996-1002]

Database support for `setOnLocked` based on [lock mode](#lock-modes):

-- Postgres: `pessimistic_read`, `pessimistic_write`, `for_no_key_update`, `for_key_share`
+- Postgres/Cockroach: `pessimistic_read`, `pessimistic_write`, `for_no_key_update`, `for_key_share`
+- SAP: `pessimistic_read`, `pessimistic_write`
- MySQL 8+: `pessimistic_read`, `pessimistic_write`
- MySQL < 8, Maria DB: `pessimistic_write`
- Cockroach: `pessimistic_write` (`nowait` only)
Evidence
The setOnLocked support list includes CockroachDB in the combined Postgres/Cockroach bullet, but
then also includes a separate Cockroach-only limitation bullet, creating conflicting guidance in the
same section.

docs/docs/query-builder/1-select-query-builder.md[996-1003]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The `setOnLocked` docs list CockroachDB twice with conflicting supported modes, which can cause users to rely on unsupported behavior.
### Issue Context
The PR updated the first bullet to `Postgres/Cockroach: ...` but retained the older separate `Cockroach: pessimistic_write (nowait only)` bullet.
### Fix Focus Areas
- docs/docs/query-builder/1-select-query-builder.md[996-1003]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. SAP lockTables untested 🐞 Bug ✓ Correctness
Description
lockTables is now permitted for the SAP driver and will emit an  OF  clause, but existing
docs/tests describe and validate this behavior only in terms of the Postgres-style FOR UPDATE OF
clause, leaving SAP’s SQL shape unverified.
Code

src/query-builder/SelectQueryBuilder.ts[R2816-2822]

           if (
               !(
                   DriverUtils.isPostgresFamily(driver) ||
-                    driver.options.type === "cockroachdb"
+                    driver.options.type === "sap"
               )
           ) {
               throw new TypeORMError(
Evidence
The query builder now allows lockTables for SAP and formats it as  OF ..., and also appends it
for SAP locking expressions. However, the documentation describes lockTables specifically in terms
of the FOR UPDATE OF clause and the functional tests only exercise this feature for
Postgres-family drivers, so there’s no in-repo validation that SAP accepts/needs this syntax.

src/query-builder/SelectQueryBuilder.ts[2815-2830]
src/query-builder/SelectQueryBuilder.ts[2859-2864]
docs/docs/query-builder/1-select-query-builder.md[954-968]
test/functional/query-builder/locking/query-builder-locking.test.ts[838-859]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`lockTables` is now allowed for the SAP driver and will generate ` OF ...` in the lock clause, but there is no documentation or test coverage in the repo confirming this SQL is correct/accepted for SAP.
### Issue Context
Docs describe `lockTables` in terms of the `FOR UPDATE OF` clause and tests only assert the behavior for Postgres-family connections. The PR expands the allowlist to include SAP and appends the same ` OF ...` formatting.
### Fix Focus Areas
- src/query-builder/SelectQueryBuilder.ts[2815-2830]
- src/query-builder/SelectQueryBuilder.ts[2859-2864]
- docs/docs/query-builder/1-select-query-builder.md[954-968]
- test/functional/query-builder/locking/query-builder-locking.test.ts[838-859]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments
4. Tests return map arrays 🐞 Bug ⛯ Reliability
Description
Several tests were refactored to return connections.map(...) arrays instead of using forEach
(sync) or Promise.all (async), which is easy to accidentally break if any async work is later
introduced inside the callback.
Code

test/functional/query-builder/locking/query-builder-locking.test.ts[R34-51]

   it("should not attach pessimistic read lock statement on query if locking is not used", () =>
-        Promise.all(
-            connections.map(async (connection) => {
-                if (
-                    DriverUtils.isSQLiteFamily(connection.driver) ||
-                    connection.driver.options.type === "sap" ||
-                    connection.driver.options.type === "spanner"
-                ) {
-                    return
-                }
+        connections.map((connection) => {
+            if (
+                DriverUtils.isSQLiteFamily(connection.driver) ||
+                connection.driver.options.type === "spanner"
+            ) {
+                return
+            }

-                const sql = connection
-                    .createQueryBuilder(PostWithVersion, "post")
-                    .where("post.id = :id", { id: 1 })
-                    .getSql()
+            const sql = connection
+                .createQueryBuilder(PostWithVersion, "post")
+                .where("post.id = :id", { id: 1 })
+                .getSql()

-                expect(sql).not.to.contain("LOCK IN SHARE MODE")
-                expect(sql).not.to.contain("FOR SHARE")
-                expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
-            }),
-        ))
+            expect(sql).not.to.contain("LOCK IN SHARE MODE")
+            expect(sql).not.to.contain("FOR SHARE")
+            expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
+        }))
Evidence
Mocha only waits on returned Promises; returning an array from map() provides no async
coordination and is an unusual pattern even for synchronous assertions. The refactored tests are
currently synchronous (getSql()), but the structure increases the chance of future silent test
bugs if async operations are added.

test/functional/query-builder/locking/query-builder-locking.test.ts[34-51]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Tests returning `connections.map(...)` are relying on synchronous execution and return an array that Mocha does not treat specially. This pattern is brittle if async code is introduced later.
### Issue Context
These test bodies currently call `getSql()` (sync), but the refactor removed `Promise.all` in multiple places.
### Fix Focus Areas
- test/functional/query-builder/locking/query-builder-locking.test.ts[34-51]
- test/functional/query-builder/locking/query-builder-locking.test.ts[360-410]
- test/functional/query-builder/locking/query-builder-locking.test.ts[459-586]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider Grey Divider
Results up to commit f47549e


🐞 Bugs (3) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider
Remediation recommended
1. Docs: Cockroach duplicated 🐞 Bug ✓ Correctness
Description
setOnLocked docs now simultaneously claim Cockroach supports multiple lock modes and also that it
only supports pessimistic_write (nowait only), which is contradictory and will mislead users.
Code

docs/docs/query-builder/1-select-query-builder.md[R996-1002]

Database support for `setOnLocked` based on [lock mode](#lock-modes):

-- Postgres: `pessimistic_read`, `pessimistic_write`, `for_no_key_update`, `for_key_share`
+- Postgres/Cockroach: `pessimistic_read`, `pessimistic_write`, `for_no_key_update`, `for_key_share`
+- SAP: `pessimistic_read`, `pessimistic_write`
- MySQL 8+: `pessimistic_read`, `pessimistic_write`
- MySQL < 8, Maria DB: `pessimistic_write`
- Cockroach: `pessimistic_write` (`nowait` only)
Evidence
The setOnLocked support list includes CockroachDB in the combined Postgres/Cockroach bullet, but
then also includes a separate Cockroach-only limitation bullet, creating conflicting guidance in the
same section.

docs/docs/query-builder/1-select-query-builder.md[996-1003]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The `setOnLocked` docs list CockroachDB twice with conflicting supported modes, which can cause users to rely on unsupported behavior.

### Issue Context
The PR updated the first bullet to `Postgres/Cockroach: ...` but retained the older separate `Cockroach: pessimistic_write (nowait only)` bullet.

### Fix Focus Areas
- docs/docs/query-builder/1-select-query-builder.md[996-1003]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. SAP lockTables untested 🐞 Bug ✓ Correctness
Description
lockTables is now permitted for the SAP driver and will emit an  OF <tables> clause, but
existing docs/tests describe and validate this behavior only in terms of the Postgres-style `FOR
UPDATE OF` clause, leaving SAP’s SQL shape unverified.
Code

src/query-builder/SelectQueryBuilder.ts[R2816-2822]

            if (
                !(
                    DriverUtils.isPostgresFamily(driver) ||
-                    driver.options.type === "cockroachdb"
+                    driver.options.type === "sap"
                )
            ) {
                throw new TypeORMError(
Evidence
The query builder now allows lockTables for SAP and formats it as  OF ..., and also appends it
for SAP locking expressions. However, the documentation describes lockTables specifically in terms
of the FOR UPDATE OF clause and the functional tests only exercise this feature for
Postgres-family drivers, so there’s no in-repo validation that SAP accepts/needs this syntax.

src/query-builder/SelectQueryBuilder.ts[2815-2830]
src/query-builder/SelectQueryBuilder.ts[2859-2864]
docs/docs/query-builder/1-select-query-builder.md[954-968]
test/functional/query-builder/locking/query-builder-locking.test.ts[838-859]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`lockTables` is now allowed for the SAP driver and will generate ` OF ...` in the lock clause, but there is no documentation or test coverage in the repo confirming this SQL is correct/accepted for SAP.

### Issue Context
Docs describe `lockTables` in terms of the `FOR UPDATE OF` clause and tests only assert the behavior for Postgres-family connections. The PR expands the allowlist to include SAP and appends the same ` OF ...` formatting.

### Fix Focus Areas
- src/query-builder/SelectQueryBuilder.ts[2815-2830]
- src/query-builder/SelectQueryBuilder.ts[2859-2864]
- docs/docs/query-builder/1-select-query-builder.md[954-968]
- test/functional/query-builder/locking/query-builder-locking.test.ts[838-859]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments
3. Tests return map arrays 🐞 Bug ⛯ Reliability
Description
Several tests were refactored to return connections.map(...) arrays instead of using forEach
(sync) or Promise.all (async), which is easy to accidentally break if any async work is later
introduced inside the callback.
Code

test/functional/query-builder/locking/query-builder-locking.test.ts[R34-51]

    it("should not attach pessimistic read lock statement on query if locking is not used", () =>
-        Promise.all(
-            connections.map(async (connection) => {
-                if (
-                    DriverUtils.isSQLiteFamily(connection.driver) ||
-                    connection.driver.options.type === "sap" ||
-                    connection.driver.options.type === "spanner"
-                ) {
-                    return
-                }
+        connections.map((connection) => {
+            if (
+                DriverUtils.isSQLiteFamily(connection.driver) ||
+                connection.driver.options.type === "spanner"
+            ) {
+                return
+            }

-                const sql = connection
-                    .createQueryBuilder(PostWithVersion, "post")
-                    .where("post.id = :id", { id: 1 })
-                    .getSql()
+            const sql = connection
+                .createQueryBuilder(PostWithVersion, "post")
+                .where("post.id = :id", { id: 1 })
+                .getSql()

-                expect(sql).not.to.contain("LOCK IN SHARE MODE")
-                expect(sql).not.to.contain("FOR SHARE")
-                expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
-            }),
-        ))
+            expect(sql).not.to.contain("LOCK IN SHARE MODE")
+            expect(sql).not.to.contain("FOR SHARE")
+            expect(sql).not.to.contain("WITH (HOLDLOCK, ROWLOCK)")
+        }))
Evidence
Mocha only waits on returned Promises; returning an array from map() provides no async
coordination and is an unusual pattern even for synchronous assertions. The refactored tests are
currently synchronous (getSql()), but the structure increases the chance of future silent test
bugs if async operations are added.

test/functional/query-builder/locking/query-builder-locking.test.ts[34-51]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Tests returning `connections.map(...)` are relying on synchronous execution and return an array that Mocha does not treat specially. This pattern is brittle if async code is introduced later.

### Issue Context
These test bodies currently call `getSql()` (sync), but the refactor removed `Promise.all` in multiple places.

### Fix Focus Areas
- test/functional/query-builder/locking/query-builder-locking.test.ts[34-51]
- test/functional/query-builder/locking/query-builder-locking.test.ts[360-410]
- test/functional/query-builder/locking/query-builder-locking.test.ts[459-586]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider Grey Divider
Qodo Logo

@coveralls

coveralls commented Feb 16, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 81.161% (+0.02%) from 81.143%
when pulling 99f2745 on alumni:feat/sap-hana-locking
into fe6c072 on typeorm:master.

@pkg-pr-new

pkg-pr-new Bot commented Feb 16, 2026 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm/typeorm@11996
    

commit: 99f2745

@alumni
alumni force-pushed the feat/sap-hana-locking branch from f47549e to a8e7fda Compare February 16, 2026 17:38
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit a8e7fda

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great to me 👏 thanks

@alumni
alumni force-pushed the feat/sap-hana-locking branch from a8e7fda to 8174ff2 Compare February 16, 2026 23:14
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit 8174ff2

Comment on lines +34 to +40
for (const connection of connections) {
if (
DriverUtils.isSQLiteFamily(connection.driver) ||
connection.driver.options.type === "spanner"
) {
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Early return skips connections 📘 Rule violation ⛯ Reliability

Several locking tests now use return inside a for (const connection of connections) loop, which
exits the entire test on the first unsupported driver instead of skipping just that driver. This can
hide failures on later connections and is inconsistent/bug-prone test control flow.
Agent Prompt
## Issue description
Several tests iterate over `connections` using `for (const connection of connections)` but use `return` to skip unsupported drivers. In a loop, `return` exits the entire test function, so subsequent connections are never validated.

## Issue Context
This refactor changes test behavior compared to the prior `connections.map(...)` approach where `return` only exited the callback for a single connection. This is likely unintentional and can mask failures.

## Fix Focus Areas
- test/functional/query-builder/locking/query-builder-locking.test.ts[33-51]
- test/functional/query-builder/locking/query-builder-locking.test.ts[328-342]
- test/functional/query-builder/locking/query-builder-locking.test.ts[344-420]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/query-builder/SelectQueryBuilder.ts Outdated
Comment on lines +2815 to +2828
if (this.expressionMap.lockTables) {
if (
!(
DriverUtils.isPostgresFamily(driver) ||
driver.options.type === "cockroachdb"
)
) {
if (!DriverUtils.isPostgresFamily(driver)) {
throw new TypeORMError(
"Lock tables not supported in selected driver",
)
}
if (this.expressionMap.lockTables.length < 1) {
throw new TypeORMError("lockTables cannot be an empty array")
}
lockTablesClause = " OF " + this.expressionMap.lockTables.join(", ")
lockTablesClause =
" OF " +
this.expressionMap.lockTables
.map((lockTable) => driver.escape(lockTable))
.join(", ")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Double-escaped locktables 🐞 Bug ✓ Correctness

createLockExpression() now escapes lockTables, but the FindOptions path already stores escaped
alias names, resulting in double-quoted identifiers (e.g., OF ""post"") and invalid SQL for
Postgres/Cockroach when FindOptions.lock.tables is used.
Agent Prompt
### Issue description
`FindOptions.lock.tables` currently stores escaped alias names into `expressionMap.lockTables`, but `createLockExpression()` now escapes `lockTables` again. This produces invalid SQL (double quotes) for Postgres-family drivers when `tables` are provided.

### Issue Context
- `applyFindOptions()` maps `lock.tables` to `this.escape(tableAlias.name)`.
- `createLockExpression()` now maps `expressionMap.lockTables` through `driver.escape()`.
- On Postgres/Cockroach, `escape()` adds double quotes, so an already-escaped value becomes double-escaped.

### Fix Focus Areas
- src/query-builder/SelectQueryBuilder.ts[3457-3495]
- src/query-builder/SelectQueryBuilder.ts[2815-2829]

### Expected change
- In `applyFindOptions()`, pass raw alias names (e.g., `tableAlias.name`) to `setLock(...)` (do not pre-escape).
- Keep escaping in `createLockExpression()` (or use `this.escape(...)` to respect `disableEscaping`) so values are escaped exactly once.
- Add/adjust tests that exercise `FindOptions.lock.tables` to ensure the produced SQL uses a single escaping layer (e.g., `FOR UPDATE OF "post"`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@alumni
alumni force-pushed the feat/sap-hana-locking branch from 8174ff2 to 8baeee2 Compare February 16, 2026 23:25
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit 8baeee2

@alumni
alumni force-pushed the feat/sap-hana-locking branch from 8baeee2 to 99f2745 Compare February 17, 2026 00:09
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit 99f2745

@alumni
alumni merged commit 960a59f into typeorm:master Feb 17, 2026
38 checks passed
@pkuczynski pkuczynski added this to the 1.0 milestone Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support select locks in SAP HANA

5 participants