Refactor where clause generation

This commit is contained in:
Sven Klemm 2018-07-11 11:50:02 +02:00
parent 5dd236bf05
commit b9edc3c611

View File

@ -222,18 +222,8 @@ export default class PostgresQuery {
return query; return query;
} }
buildQuery(target) { buildWhereClause(target) {
var query = 'SELECT '; let query = '';
query += this.buildTimeColumn(target);
if (this.target.metricColumn !== 'None') {
query += ',' + this.target.metricColumn + ' AS metric';
}
query += this.buildValueColumns(target);
query += ' FROM ' + target.schema + '.' + target.table;
var conditions = _.map(target.where, (tag, index) => { var conditions = _.map(target.where, (tag, index) => {
switch (tag.type) { switch (tag.type) {
case 'macro': case 'macro':
@ -246,9 +236,27 @@ export default class PostgresQuery {
}); });
if (conditions.length > 0) { if (conditions.length > 0) {
query += ' WHERE ' + conditions.join(' AND '); query = ' WHERE ' + conditions.join(' AND ');
} }
return query;
}
buildQuery(target) {
var query = 'SELECT ';
query += this.buildTimeColumn(target);
if (this.target.metricColumn !== 'None') {
query += ',' + this.target.metricColumn + ' AS metric';
}
query += this.buildValueColumns(target);
query += ' FROM ' + target.schema + '.' + target.table;
query += this.buildWhereClause(target);
var groupBySection = ''; var groupBySection = '';
for (let i = 0; i < this.groupByParts.length; i++) { for (let i = 0; i < this.groupByParts.length; i++) {
var part = this.groupByParts[i]; var part = this.groupByParts[i];