Forráskód Böngészése

Refactor metric column sql generation

Sven Klemm 7 éve
szülő
commit
9ba42f63f1
1 módosított fájl, 12 hozzáadás és 6 törlés
  1. 12 6
      public/app/plugins/datasource/postgres/postgres_query.ts

+ 12 - 6
public/app/plugins/datasource/postgres/postgres_query.ts

@@ -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;
   }
 }