Skip to content

Commit

Permalink
feat: lock modes in cockroachdb (#8250)
Browse files Browse the repository at this point in the history
closes #8249
  • Loading branch information
wodka committed Nov 18, 2021
1 parent 4e7d32f commit d494fcc
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 108 deletions.
1 change: 1 addition & 0 deletions docs/find-options.md
Expand Up @@ -239,6 +239,7 @@ Support of lock modes, and SQL statements they translate to, are listed in the t
| Oracle | FOR UPDATE | FOR UPDATE | (nothing) | | | |
| SQL Server | WITH (HOLDLOCK, ROWLOCK) | WITH (UPDLOCK, ROWLOCK) | WITH (NOLOCK) | | | |
| AuroraDataApi | LOCK IN SHARE MODE | FOR UPDATE | (nothing) | | | |
| CockroachDB | | FOR UPDATE | (nothing) | | FOR UPDATE NOWAIT | FOR NO KEY UPDATE |
```

Expand Down
8 changes: 4 additions & 4 deletions src/query-builder/SelectQueryBuilder.ts
Expand Up @@ -1702,7 +1702,7 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
let lockTablesClause = "";

if (this.expressionMap.lockTables) {
if (!(driver instanceof PostgresDriver)) {
if (!(driver instanceof PostgresDriver || driver instanceof CockroachDriver)) {
throw new TypeORMError("Lock tables not supported in selected driver");
}
if (this.expressionMap.lockTables.length < 1) {
Expand Down Expand Up @@ -1733,7 +1733,7 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
return " FOR UPDATE";

}
else if (driver instanceof PostgresDriver ) {
else if (driver instanceof PostgresDriver || driver instanceof CockroachDriver) {
return " FOR UPDATE" + lockTablesClause;

} else if (driver instanceof SqlServerDriver) {
Expand All @@ -1753,7 +1753,7 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
throw new LockNotSupportedOnGivenDriverError();
}
case "pessimistic_write_or_fail":
if (driver instanceof PostgresDriver) {
if (driver instanceof PostgresDriver || driver instanceof CockroachDriver) {
return " FOR UPDATE" + lockTablesClause + " NOWAIT";

} else if (driver instanceof MysqlDriver) {
Expand All @@ -1764,7 +1764,7 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
}

case "for_no_key_update":
if (driver instanceof PostgresDriver) {
if (driver instanceof PostgresDriver || driver instanceof CockroachDriver) {
return " FOR NO KEY UPDATE" + lockTablesClause;
} else {
throw new LockNotSupportedOnGivenDriverError();
Expand Down

0 comments on commit d494fcc

Please sign in to comment.