remove hardcoded $__timeFilter, make macros functional in where clause

This commit is contained in:
Sven Klemm
2018-07-06 10:38:52 +02:00
parent 8ed210c8d5
commit 7600c6efcb
3 changed files with 25 additions and 11 deletions

View File

@ -63,7 +63,7 @@ export default class PostgresQuery {
});
});
this.target.where = _.map(this.whereParts, function(part: any) {
return { type: part.def.type, params: part.params };
return { type: part.def.type, name: part.name, params: part.params };
});
this.target.groupBy = _.map(this.groupByParts, function(part: any) {
return { type: part.def.type, params: part.params };
@ -196,15 +196,20 @@ export default class PostgresQuery {
query += ' FROM ' + target.schema + '.' + target.table + ' WHERE ';
var conditions = _.map(target.where, (tag, index) => {
return tag.params.join(' ');
switch (tag.type) {
case 'macro':
return tag.name + '(' + target.timeColumn + ')';
break;
case 'expression':
return tag.params.join(' ');
break;
}
});
if (conditions.length > 0) {
query += '(' + conditions.join(' AND ') + ') AND ';
query += conditions.join(' AND ');
}
query += '$__timeFilter(' + target.timeColumn + ')';
var groupBySection = '';
for (i = 0; i < this.groupByParts.length; i++) {
var part = this.groupByParts[i];