mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Refactor metric column sql generation
This commit is contained in:
parent
a86e77fc68
commit
9ba42f63f1
@ -184,6 +184,7 @@ export default class PostgresQuery {
|
|||||||
if (interpolate) {
|
if (interpolate) {
|
||||||
query = this.templateSrv.replace(query, this.scopedVars, this.interpolateQueryStr);
|
query = this.templateSrv.replace(query, this.scopedVars, this.interpolateQueryStr);
|
||||||
}
|
}
|
||||||
|
this.target.rawSql = query;
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,6 +207,16 @@ export default class PostgresQuery {
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildMetricColumn(target) {
|
||||||
|
let query = '';
|
||||||
|
|
||||||
|
if (this.target.metricColumn !== 'None') {
|
||||||
|
query += ',' + this.target.metricColumn + ' AS metric';
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
buildValueColumns(target) {
|
buildValueColumns(target) {
|
||||||
let query = '';
|
let query = '';
|
||||||
for (let i = 0; i < this.selectModels.length; i++) {
|
for (let i = 0; i < this.selectModels.length; i++) {
|
||||||
@ -271,11 +282,7 @@ export default class PostgresQuery {
|
|||||||
let query = 'SELECT ';
|
let query = 'SELECT ';
|
||||||
|
|
||||||
query += this.buildTimeColumn(target);
|
query += this.buildTimeColumn(target);
|
||||||
|
query += this.buildMetricColumn(target);
|
||||||
if (this.target.metricColumn !== 'None') {
|
|
||||||
query += ',' + this.target.metricColumn + ' AS metric';
|
|
||||||
}
|
|
||||||
|
|
||||||
query += this.buildValueColumns(target);
|
query += this.buildValueColumns(target);
|
||||||
|
|
||||||
query += ' FROM ' + target.schema + '.' + target.table;
|
query += ' FROM ' + target.schema + '.' + target.table;
|
||||||
@ -285,7 +292,6 @@ export default class PostgresQuery {
|
|||||||
|
|
||||||
query += ' ORDER BY 1';
|
query += ' ORDER BY 1';
|
||||||
|
|
||||||
this.target.rawSql = query;
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user