Refactor metric column sql generation

This commit is contained in:
Sven Klemm 2018-07-11 12:33:37 +02:00
parent a86e77fc68
commit 9ba42f63f1

View File

@ -184,6 +184,7 @@ export default class PostgresQuery {
if (interpolate) {
query = this.templateSrv.replace(query, this.scopedVars, this.interpolateQueryStr);
}
this.target.rawSql = query;
return query;
}
@ -206,6 +207,16 @@ export default class PostgresQuery {
return query;
}
buildMetricColumn(target) {
let query = '';
if (this.target.metricColumn !== 'None') {
query += ',' + this.target.metricColumn + ' AS metric';
}
return query;
}
buildValueColumns(target) {
let query = '';
for (let i = 0; i < this.selectModels.length; i++) {
@ -271,11 +282,7 @@ export default class PostgresQuery {
let query = 'SELECT ';
query += this.buildTimeColumn(target);
if (this.target.metricColumn !== 'None') {
query += ',' + this.target.metricColumn + ' AS metric';
}
query += this.buildMetricColumn(target);
query += this.buildValueColumns(target);
query += ' FROM ' + target.schema + '.' + target.table;
@ -285,7 +292,6 @@ export default class PostgresQuery {
query += ' ORDER BY 1';
this.target.rawSql = query;
return query;
}
}