Procházet zdrojové kódy

remove dead code from sql_part
fix where clause query generation

Sven Klemm před 7 roky
rodič
revize
7d30ca04de

+ 8 - 25
public/app/core/components/sql_part/sql_part.ts

@@ -21,14 +21,14 @@ export class SqlPartDef {
       this.label = this.type[0].toUpperCase() + this.type.substring(1) + ':';
     }
     this.style = options.style;
-    if (this.style === "function") {
-      this.wrapOpen = "(";
-      this.wrapClose = ")";
-      this.separator = ", ";
+    if (this.style === 'function') {
+      this.wrapOpen = '(';
+      this.wrapClose = ')';
+      this.separator = ', ';
     } else {
-      this.wrapOpen = " ";
-      this.wrapClose = " ";
-      this.separator = " ";
+      this.wrapOpen = ' ';
+      this.wrapClose = ' ';
+      this.separator = ' ';
     }
     this.params = options.params;
     this.defaultParams = options.defaultParams;
@@ -60,25 +60,9 @@ export class SqlPart {
     return this.def.renderer(this, innerExpr);
   }
 
-  hasMultipleParamsInString(strValue, index) {
-    if (strValue.indexOf(',') === -1) {
-      return false;
-    }
-
-    return this.def.params[index + 1] && this.def.params[index + 1].optional;
-  }
-
   updateParam(strValue, index) {
-    // handle optional parameters
-    // if string contains ',' and next param is optional, split and update both
-    if (this.hasMultipleParamsInString(strValue, index)) {
-      _.each(strValue.split(','), (partVal, idx) => {
-        this.updateParam(partVal.trim(), idx);
-      });
-      return;
-    }
-
     if (strValue === '' && this.def.params[index].optional) {
+      // XXX check if this is still required
       this.params.splice(index, 1);
     } else {
       this.params[index] = strValue;
@@ -132,4 +116,3 @@ export function suffixRenderer(part, innerExpr) {
 export function identityRenderer(part, innerExpr) {
   return part.params[0];
 }
-

+ 4 - 1
public/app/plugins/datasource/postgres/postgres_query.ts

@@ -56,6 +56,9 @@ export default class PostgresQuery {
     this.target.where = _.map(this.whereParts, function(part: any) {
       return { type: part.def.type, params: part.params };
     });
+    this.target.groupBy = _.map(this.groupByParts, function(part: any) {
+      return { type: part.def.type, params: part.params };
+    });
   }
 
   hasGroupByTime() {
@@ -197,7 +200,7 @@ export default class PostgresQuery {
     });
 
     if (conditions.length > 0) {
-      query += '(' + conditions.join(' ') + ') AND ';
+      query += '(' + conditions.join(' AND ') + ') AND ';
     }
 
     query += '$__timeFilter(' + this.quoteIdentifier(target.timeColumn) + ')';