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 authored and pamdesilva committed Nov 18, 2020
1 parent d60305e commit a2f76b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/query-builder/QueryExpressionMap.ts
Expand Up @@ -162,6 +162,12 @@ export class QueryExpressionMap {
* By default the soft-deleted rows are not included.
*/
withDeleted: boolean = false;

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

/**
* Parameters used to be escaped in final query.
Expand Down
15 changes: 14 additions & 1 deletion src/query-builder/SelectQueryBuilder.ts
Expand Up @@ -1012,13 +1012,21 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
}

/**
* Disables the global condition of "non-deleted" for the entity with delete date columns.
*/
withDeleted(): this {
this.expressionMap.withDeleted = true;
return this;
}

/**
* Set a lock clause, passed directly into the query.
* 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 @@ -1690,6 +1698,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 a2f76b3

Please sign in to comment.