{"id":"b5aef86baddbd813","repo":"typeorm/typeorm","slug":"locking-not-supported-on-given-driver","errorCode":null,"errorMessage":"Locking not supported on given driver.","messagePattern":"Locking not supported on given driver\\.","errorType":"exception","errorClass":"LockNotSupportedOnGivenDriverError","httpStatus":null,"severity":"error","filePath":"src/query-builder/SelectQueryBuilder.ts","lineNumber":2828,"sourceCode":"                            \" FOR SHARE\" + lockTablesClause + onLockExpression\n                        )\n                    } else {\n                        return \" LOCK IN SHARE MODE\"\n                    }\n                } else if (driver.options.type === \"mariadb\") {\n                    return \" LOCK IN SHARE MODE\"\n                } else if (DriverUtils.isPostgresFamily(driver)) {\n                    return \" FOR SHARE\" + lockTablesClause + onLockExpression\n                } else if (driver.options.type === \"sap\") {\n                    return (\n                        \" FOR SHARE LOCK\" + lockTablesClause + onLockExpression\n                    )\n                } else if (driver.options.type === \"oracle\") {\n                    return \" FOR UPDATE\"\n                } else if (driver.options.type === \"mssql\") {\n                    return \"\"\n                } else {\n                    throw new LockNotSupportedOnGivenDriverError()\n                }\n            case \"pessimistic_write\":\n                if (\n                    DriverUtils.isMySQLFamily(driver) ||\n                    driver.options.type === \"aurora-mysql\" ||\n                    driver.options.type === \"oracle\"\n                ) {\n                    return \" FOR UPDATE\" + onLockExpression\n                } else if (\n                    DriverUtils.isPostgresFamily(driver) ||\n                    driver.options.type === \"sap\"\n                ) {\n                    return \" FOR UPDATE\" + lockTablesClause + onLockExpression\n                } else if (driver.options.type === \"mssql\") {\n                    return \"\"\n                } else {\n                    throw new LockNotSupportedOnGivenDriverError()\n                }","sourceCodeStart":2810,"sourceCodeEnd":2846,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/query-builder/SelectQueryBuilder.ts#L2810-L2846","documentation":"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.","triggerScenarios":"Calling .setLock(\"pessimistic_read\") (or lock: { mode: 'pessimistic_read' }) on a driver such as sqlite, better-sqlite3, sql.js, or spanner.","commonSituations":"Running tests against sqlite while production uses postgres; switching DataSource type without auditing lock usage; enabling pessimistic_read globally in a base repository.","solutions":["Use pessimistic_write (FOR UPDATE) if your driver supports it.","Route read-shared locking to a postgres or mysql8+ DataSource.","Gate the lock mode on the driver: only request pessimistic_read on supported drivers."],"exampleFix":"// before (sqlite)\nqb.setLock(\"pessimistic_read\")\n\n// after\nif (DriverUtils.isPostgresFamily(dataSource.driver)) qb.setLock(\"pessimistic_read\")\nelse qb.setLock(\"pessimistic_write\")","handlingStrategy":"type-guard","validationCode":"import { DriverUtils } from 'typeorm'\nfunction supportsPessimisticRead(driver): boolean {\n  return ['mysql', 'aurora-mysql', 'mariadb', 'sap', 'oracle'].includes(driver.options.type) || DriverUtils.isPostgresFamily(driver)\n}","typeGuard":"function canPessimisticRead(driver): boolean {\n  return supportsPessimisticRead(driver)\n}","tryCatchPattern":null,"preventionTips":["Branch lock mode on driver capabilities.","Run integration tests against the production driver, not only sqlite.","Document which drivers support each lock mode in your service."],"tags":["locking","pessimistic-lock","dialect","driver-support"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}