remove dead code from sql_part

fix where clause query generation
This commit is contained in:
Sven Klemm 2018-07-04 15:37:06 +02:00
parent 3b632510fb
commit 7d30ca04de
2 changed files with 12 additions and 26 deletions

View File

@ -21,14 +21,14 @@ export class SqlPartDef {
this.label = this.type[0].toUpperCase() + this.type.substring(1) + ':';
}
this.style = options.style;
if (this.style === "function") {
this.wrapOpen = "(";
this.wrapClose = ")";
this.separator = ", ";
if (this.style === 'function') {
this.wrapOpen = '(';
this.wrapClose = ')';
this.separator = ', ';
} else {
this.wrapOpen = " ";
this.wrapClose = " ";
this.separator = " ";
this.wrapOpen = ' ';
this.wrapClose = ' ';
this.separator = ' ';
}
this.params = options.params;
this.defaultParams = options.defaultParams;
@ -60,25 +60,9 @@ export class SqlPart {
return this.def.renderer(this, innerExpr);
}
hasMultipleParamsInString(strValue, index) {
if (strValue.indexOf(',') === -1) {
return false;
}
return this.def.params[index + 1] && this.def.params[index + 1].optional;
}
updateParam(strValue, index) {
// handle optional parameters
// if string contains ',' and next param is optional, split and update both
if (this.hasMultipleParamsInString(strValue, index)) {
_.each(strValue.split(','), (partVal, idx) => {
this.updateParam(partVal.trim(), idx);
});
return;
}
if (strValue === '' && this.def.params[index].optional) {
// XXX check if this is still required
this.params.splice(index, 1);
} else {
this.params[index] = strValue;
@ -132,4 +116,3 @@ export function suffixRenderer(part, innerExpr) {
export function identityRenderer(part, innerExpr) {
return part.params[0];
}

View File

@ -56,6 +56,9 @@ export default class PostgresQuery {
this.target.where = _.map(this.whereParts, function(part: any) {
return { type: part.def.type, params: part.params };
});
this.target.groupBy = _.map(this.groupByParts, function(part: any) {
return { type: part.def.type, params: part.params };
});
}
hasGroupByTime() {
@ -197,7 +200,7 @@ export default class PostgresQuery {
});
if (conditions.length > 0) {
query += '(' + conditions.join(' ') + ') AND ';
query += '(' + conditions.join(' AND ') + ') AND ';
}
query += '$__timeFilter(' + this.quoteIdentifier(target.timeColumn) + ')';