refactor function handling in query builder

This commit is contained in:
Sven Klemm
2018-07-29 13:30:21 +02:00
parent 5327580939
commit 412bb6acab
4 changed files with 81 additions and 19 deletions

View File

@ -134,14 +134,21 @@ export default class PostgresQuery {
let columnName = _.find(column, (g: any) => g.type === 'column');
query = columnName.params[0];
let aggregate = _.find(column, (g: any) => g.type === 'aggregate');
let aggregate = _.find(column, (g: any) => g.type === 'aggregate' || g.type === 'percentile');
let special = _.find(column, (g: any) => g.type === 'window');
if (aggregate) {
if (special) {
query = aggregate.params[0] + '(' + query + ' ORDER BY ' + this.target.timeColumn + ')';
} else {
query = aggregate.params[0] + '(' + query + ')';
switch (aggregate.type) {
case 'aggregate':
if (special) {
query = aggregate.params[0] + '(' + query + ' ORDER BY ' + this.target.timeColumn + ')';
} else {
query = aggregate.params[0] + '(' + query + ')';
}
break;
case 'percentile':
query = aggregate.params[0] + '(' + aggregate.params[1] + ') WITHIN GROUP (ORDER BY ' + query + ')';
break;
}
}