Skip to content

Commit

Permalink
refactor(postgres): extract lockingClause in pg query complier
Browse files Browse the repository at this point in the history
  • Loading branch information
domkck committed Oct 20, 2021
1 parent ae4d337 commit 2ed68e9
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions lib/dialects/postgres/query/pg-querycompiler.js
Expand Up @@ -147,37 +147,26 @@ class QueryCompiler_PG extends QueryCompiler {
return sql.join(', ');
}

forUpdate() {
_lockingClause(lockMode) {
const tables = this.single.lockTables || [];

return (
'for update' + (tables.length ? ' of ' + this._tableNames(tables) : '')
);
return lockMode + (tables.length ? ' of ' + this._tableNames(tables) : '');
}

forShare() {
const tables = this.single.lockTables || [];
forUpdate() {
return this._lockingClause('for update');
}

return (
'for share' + (tables.length ? ' of ' + this._tableNames(tables) : '')
);
forShare() {
return this._lockingClause('for share');
}

forNoKeyUpdate() {
const tables = this.single.lockTables || [];

return (
'for no key update' +
(tables.length ? ' of ' + this._tableNames(tables) : '')
);
return this._lockingClause('for no key update');
}

forKeyShare() {
const tables = this.single.lockTables || [];

return (
'for key share' + (tables.length ? ' of ' + this._tableNames(tables) : '')
);
return this._lockingClause('for key share');
}

skipLocked() {
Expand Down

0 comments on commit 2ed68e9

Please sign in to comment.