Browse Source

handle variables in where constraints

Sven Klemm 8 years ago
parent
commit
cb5278d413

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

@@ -56,10 +56,6 @@ export default class PostgresQuery {
     return _.find(this.target.groupBy, (g: any) => g.type === 'time');
     return _.find(this.target.groupBy, (g: any) => g.type === 'time');
   }
   }
 
 
-  hasFill() {
-    return _.find(this.target.groupBy, (g: any) => g.type === 'fill');
-  }
-
   addGroupBy(value) {
   addGroupBy(value) {
     var stringParts = value.match(/^(\w+)(\((.*)\))?$/);
     var stringParts = value.match(/^(\w+)(\((.*)\))?$/);
     var typePart = stringParts[1];
     var typePart = stringParts[1];
@@ -130,19 +126,19 @@ export default class PostgresQuery {
     this.updatePersistedParts();
     this.updatePersistedParts();
   }
   }
 
 
-  private renderWhereConstraint(tag, index, interpolate) {
+  private renderWhereConstraint(constraint, index, interpolate) {
     var str = '';
     var str = '';
-    var operator = tag.operator;
-    var value = tag.value;
+    var operator = constraint.operator;
+    var value = constraint.value;
     if (index > 0) {
     if (index > 0) {
-      str = (tag.condition || 'AND') + ' ';
+      str = (constraint.condition || 'AND') + ' ';
     }
     }
 
 
     if (interpolate) {
     if (interpolate) {
       value = this.templateSrv.replace(value, this.scopedVars);
       value = this.templateSrv.replace(value, this.scopedVars);
     }
     }
 
 
-    return str + this.quoteIdentifier(tag.key) + ' ' + operator + ' ' + this.quoteLiteral(value);
+    return str + this.quoteIdentifier(constraint.key) + ' ' + operator + ' ' + this.quoteLiteral(value);
   }
   }
 
 
   interpolateQueryStr(value, variable, defaultFormatFn) {
   interpolateQueryStr(value, variable, defaultFormatFn) {
@@ -207,7 +203,7 @@ export default class PostgresQuery {
 
 
     query += ' FROM ' + this.quoteIdentifier(target.schema) + '.' + this.quoteIdentifier(target.table) + ' WHERE ';
     query += ' FROM ' + this.quoteIdentifier(target.schema) + '.' + this.quoteIdentifier(target.table) + ' WHERE ';
     var conditions = _.map(target.where, (tag, index) => {
     var conditions = _.map(target.where, (tag, index) => {
-      return this.renderWhereConstraint(tag, index, interpolate);
+      return this.renderWhereConstraint(tag, index, false);
     });
     });
 
 
     if (conditions.length > 0) {
     if (conditions.length > 0) {

+ 2 - 6
public/app/plugins/datasource/postgres/query_ctrl.ts

@@ -353,7 +353,6 @@ export class PostgresQueryCtrl extends QueryCtrl {
   rebuildTargetWhereConditions() {
   rebuildTargetWhereConditions() {
     var where = [];
     var where = [];
     var tagIndex = 0;
     var tagIndex = 0;
-    var tagOperator = '';
 
 
     _.each(this.whereSegments, (segment2, index) => {
     _.each(this.whereSegments, (segment2, index) => {
       if (segment2.type === 'key') {
       if (segment2.type === 'key') {
@@ -362,11 +361,8 @@ export class PostgresQueryCtrl extends QueryCtrl {
         }
         }
         where[tagIndex].key = segment2.value;
         where[tagIndex].key = segment2.value;
       } else if (segment2.type === 'value') {
       } else if (segment2.type === 'value') {
-        tagOperator = this.getTagValueOperator(segment2.value, where[tagIndex].operator);
-        if (tagOperator) {
-          this.whereSegments[index - 1] = this.uiSegmentSrv.newOperator(tagOperator);
-          where[tagIndex].operator = tagOperator;
-        }
+        where[tagIndex].value = segment2.value;
+      } else if (segment2.type === 'template') {
         where[tagIndex].value = segment2.value;
         where[tagIndex].value = segment2.value;
       } else if (segment2.type === 'condition') {
       } else if (segment2.type === 'condition') {
         where.push({ condition: segment2.value });
         where.push({ condition: segment2.value });