From 8f17a84f315341ee0d36d1f3800c7b9e019d8434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sun, 23 Apr 2017 14:22:47 +0200 Subject: [PATCH] mysql: added basic templating support --- public/app/plugins/datasource/mysql/datasource.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/mysql/datasource.ts b/public/app/plugins/datasource/mysql/datasource.ts index 70799048319..b25e183198a 100644 --- a/public/app/plugins/datasource/mysql/datasource.ts +++ b/public/app/plugins/datasource/mysql/datasource.ts @@ -7,11 +7,22 @@ export class MysqlDatasource { name: any; /** @ngInject */ - constructor(instanceSettings, private backendSrv, private $q) { + constructor(instanceSettings, private backendSrv, private $q, private templateSrv) { this.name = instanceSettings.name; this.id = instanceSettings.id; } + interpolateVariable(value) { + if (typeof value === 'string') { + return '\"' + value + '\"'; + } + + var quotedValues = _.map(value, function(val) { + return '\"' + val + '\"'; + }); + return quotedValues.join(','); + } + query(options) { var queries = _.filter(options.targets, item => { return item.hide !== true; @@ -21,7 +32,7 @@ export class MysqlDatasource { intervalMs: options.intervalMs, maxDataPoints: options.maxDataPoints, datasourceId: this.id, - rawSql: item.rawSql, + rawSql: this.templateSrv.replace(item.rawSql, options.scopedVars, this.interpolateVariable), format: item.format, }; });