mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00
add regex operators
This commit is contained in:
@ -47,4 +47,12 @@ export class PostgresQueryBuilder {
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildDatatypeQuery(column: string) {
|
||||||
|
var query = "SELECT data_type FROM information_schema.columns WHERE ";
|
||||||
|
query += " table_schema = " + this.queryModel.quoteLiteral(this.target.schema);
|
||||||
|
query += " AND table_name = " + this.queryModel.quoteLiteral(this.target.table);
|
||||||
|
query += " AND column_name = " + this.queryModel.quoteLiteral(column);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -266,14 +266,28 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getWhereSegments(segment, index) {
|
getWhereSegments(segment, index) {
|
||||||
|
var query, addTemplateVars;
|
||||||
|
|
||||||
if (segment.type === 'condition') {
|
if (segment.type === 'condition') {
|
||||||
return this.$q.when([this.uiSegmentSrv.newSegment('AND'), this.uiSegmentSrv.newSegment('OR')]);
|
return this.$q.when([this.uiSegmentSrv.newSegment('AND'), this.uiSegmentSrv.newSegment('OR')]);
|
||||||
}
|
}
|
||||||
if (segment.type === 'operator') {
|
if (segment.type === 'operator') {
|
||||||
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '<>', '<', '>']));
|
var columnName = this.whereSegments[index - 1].value;
|
||||||
|
query = this.queryBuilder.buildDatatypeQuery(columnName);
|
||||||
|
return this.datasource.metricFindQuery(query)
|
||||||
|
.then(results => {
|
||||||
|
var datatype = results[0].text;
|
||||||
|
switch (datatype) {
|
||||||
|
case "text":
|
||||||
|
case "character varying":
|
||||||
|
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '~', '~*','!~','!~*','IN']));
|
||||||
|
default:
|
||||||
|
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '<', '<=', '>', '>=']));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(this.handleQueryError.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
var query, addTemplateVars;
|
|
||||||
if (segment.type === 'key' || segment.type === 'plus-button') {
|
if (segment.type === 'key' || segment.type === 'plus-button') {
|
||||||
query = this.queryBuilder.buildColumnQuery();
|
query = this.queryBuilder.buildColumnQuery();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user