Skip to content

Commit

Permalink
add lock method to SelectQueryBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdave committed Nov 19, 2019
1 parent d2c9b03 commit fba8743
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/query-builder/QueryExpressionMap.ts
Expand Up @@ -152,6 +152,12 @@ export class QueryExpressionMap {
*/
lockVersion?: number|Date;

/**
* Locking clause.
*
*/
lockClause?: string;

/**
* Parameters used to be escaped in final query.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/query-builder/SelectQueryBuilder.ts
Expand Up @@ -999,6 +999,16 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
return this;
}

/**
* Set a lock clause, passed directly into the query.
* e.g. `FOR UPDATE NOWAIT`.
* If set, will override `lockMode`.
*/
lock(clause: string): this {
this.expressionMap.lockClause = clause;
return this;
}

/**
* Gets first raw result returned by execution of generated query builder sql.
*/
Expand Down Expand Up @@ -1634,6 +1644,11 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
*/
protected createLockExpression(): string {
const driver = this.connection.driver;

if (this.expressionMap.lockClause) {
return ` ${this.expressionMap.lockClause}`;
}

switch (this.expressionMap.lockMode) {
case "pessimistic_read":
if (driver instanceof MysqlDriver || driver instanceof AuroraDataApiDriver) {
Expand Down

0 comments on commit fba8743

Please sign in to comment.