typeorm/typeorm · error · LockNotSupportedOnGivenDriverError

Locking not supported on given driver.

Error message

Locking not supported on given driver.

What it means

LockNotSupportedOnGivenDriverError is thrown in the pessimistic_read branch of createLockExpression when the driver is not mysql/aurora-mysql/mariadb/postgres/sap/oracle/mssql. It is the catch-all else branch: shared (read) locks are only implemented for those families.

Source

Thrown at src/query-builder/SelectQueryBuilder.ts:2828

                            " FOR SHARE" + lockTablesClause + onLockExpression
                        )
                    } else {
                        return " LOCK IN SHARE MODE"
                    }
                } else if (driver.options.type === "mariadb") {
                    return " LOCK IN SHARE MODE"
                } else if (DriverUtils.isPostgresFamily(driver)) {
                    return " FOR SHARE" + lockTablesClause + onLockExpression
                } else if (driver.options.type === "sap") {
                    return (
                        " FOR SHARE LOCK" + lockTablesClause + onLockExpression
                    )
                } else if (driver.options.type === "oracle") {
                    return " FOR UPDATE"
                } else if (driver.options.type === "mssql") {
                    return ""
                } else {
                    throw new LockNotSupportedOnGivenDriverError()
                }
            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 === "sap"
                ) {
                    return " FOR UPDATE" + lockTablesClause + onLockExpression
                } else if (driver.options.type === "mssql") {
                    return ""
                } else {
                    throw new LockNotSupportedOnGivenDriverError()
                }

View on GitHub (pinned to 04ff4daedc)

Solutions

  1. Use pessimistic_write (FOR UPDATE) if your driver supports it.
  2. Route read-shared locking to a postgres or mysql8+ DataSource.
  3. Gate the lock mode on the driver: only request pessimistic_read on supported drivers.

Example fix

// before (sqlite)
qb.setLock("pessimistic_read")

// after
if (DriverUtils.isPostgresFamily(dataSource.driver)) qb.setLock("pessimistic_read")
else qb.setLock("pessimistic_write")
Defensive patterns

Strategy: type-guard

Validate before calling

import { DriverUtils } from 'typeorm'
function supportsPessimisticRead(driver): boolean {
  return ['mysql', 'aurora-mysql', 'mariadb', 'sap', 'oracle'].includes(driver.options.type) || DriverUtils.isPostgresFamily(driver)
}

Type guard

function canPessimisticRead(driver): boolean {
  return supportsPessimisticRead(driver)
}

Prevention

When it happens

Trigger: Calling .setLock("pessimistic_read") (or lock: { mode: 'pessimistic_read' }) on a driver such as sqlite, better-sqlite3, sql.js, or spanner.

Common situations: Running tests against sqlite while production uses postgres; switching DataSource type without auditing lock usage; enabling pessimistic_read globally in a base repository.

Related errors


AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03). Data as JSON: /data/errors/b5aef86baddbd813.json. Report an issue: GitHub.