handle variables in where constraints
This commit is contained in:
@@ -56,10 +56,6 @@ export default class PostgresQuery {
|
||||
return _.find(this.target.groupBy, (g: any) => g.type === 'time');
|
||||
}
|
||||
|
||||
hasFill() {
|
||||
return _.find(this.target.groupBy, (g: any) => g.type === 'fill');
|
||||
}
|
||||
|
||||
addGroupBy(value) {
|
||||
var stringParts = value.match(/^(\w+)(\((.*)\))?$/);
|
||||
var typePart = stringParts[1];
|
||||
@@ -130,19 +126,19 @@ export default class PostgresQuery {
|
||||
this.updatePersistedParts();
|
||||
}
|
||||
|
||||
private renderWhereConstraint(tag, index, interpolate) {
|
||||
private renderWhereConstraint(constraint, index, interpolate) {
|
||||
var str = '';
|
||||
var operator = tag.operator;
|
||||
var value = tag.value;
|
||||
var operator = constraint.operator;
|
||||
var value = constraint.value;
|
||||
if (index > 0) {
|
||||
str = (tag.condition || 'AND') + ' ';
|
||||
str = (constraint.condition || 'AND') + ' ';
|
||||
}
|
||||
|
||||
if (interpolate) {
|
||||
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) {
|
||||
@@ -207,7 +203,7 @@ export default class PostgresQuery {
|
||||
|
||||
query += ' FROM ' + this.quoteIdentifier(target.schema) + '.' + this.quoteIdentifier(target.table) + ' WHERE ';
|
||||
var conditions = _.map(target.where, (tag, index) => {
|
||||
return this.renderWhereConstraint(tag, index, interpolate);
|
||||
return this.renderWhereConstraint(tag, index, false);
|
||||
});
|
||||
|
||||
if (conditions.length > 0) {
|
||||
|
||||
@@ -353,7 +353,6 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
rebuildTargetWhereConditions() {
|
||||
var where = [];
|
||||
var tagIndex = 0;
|
||||
var tagOperator = '';
|
||||
|
||||
_.each(this.whereSegments, (segment2, index) => {
|
||||
if (segment2.type === 'key') {
|
||||
@@ -362,11 +361,8 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
where[tagIndex].key = segment2.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;
|
||||
} else if (segment2.type === 'condition') {
|
||||
where.push({ condition: segment2.value });
|
||||
|
||||
Reference in New Issue
Block a user