mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
add regex operators
This commit is contained in:
parent
046ee8efd8
commit
b7c7030a46
@ -47,4 +47,12 @@ export class PostgresQueryBuilder {
|
||||
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) {
|
||||
var query, addTemplateVars;
|
||||
|
||||
if (segment.type === 'condition') {
|
||||
return this.$q.when([this.uiSegmentSrv.newSegment('AND'), this.uiSegmentSrv.newSegment('OR')]);
|
||||
}
|
||||
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') {
|
||||
query = this.queryBuilder.buildColumnQuery();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user