Skip to content

Commit bfa041b

Browse files
author
Di Wu
committed
pass string flag to subquery
1 parent 9ad593c commit bfa041b

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

lib/dialect/postgres.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ Postgres.prototype.getQuery = function(queryNode) {
7777

7878
Postgres.prototype.getString = function(queryNode) {
7979
// switch off parameter placeholders
80+
var previousFlagStatus = this._disableParameterPlaceholders;
8081
this._disableParameterPlaceholders = true;
8182
var query;
8283
try {
8384
// use the same code path for query building
8485
query = this.getQuery(queryNode);
8586
} finally {
86-
// always toggle parameter placeholders on afterwards
87-
this._disableParameterPlaceholders = false;
87+
// always restore the flag afterwards
88+
this._disableParameterPlaceholders = previousFlagStatus;
8889
}
8990
return query.text;
9091
};
@@ -390,9 +391,22 @@ Postgres.prototype.visitQuery = function(queryNode) {
390391
};
391392

392393
Postgres.prototype.visitSubquery = function(queryNode) {
394+
// create another query builder of the current class to build the subquery
393395
var subQuery = new this._myClass();
396+
397+
// let the subquery modify this instance's params array
394398
subQuery.params = this.params;
395-
subQuery.visitQuery(queryNode);
399+
400+
// pass on the disable parameter placeholder flag
401+
var previousFlagStatus = subQuery._disableParameterPlaceholders;
402+
subQuery._disableParameterPlaceholders = this._disableParameterPlaceholders;
403+
try {
404+
subQuery.visitQuery(queryNode);
405+
} finally {
406+
// restore the flag
407+
subQuery._disableParameterPlaceholders = previousFlagStatus;
408+
}
409+
396410
var alias = queryNode.alias;
397411
return '(' + subQuery.output.join(' ') + ')' + (alias ? ' ' + alias : '');
398412
};

0 commit comments

Comments
 (0)