From ec0fd96f08f017a2d3ea694bed35b99437233d7d Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Wed, 17 Oct 2018 12:30:07 +0200 Subject: [PATCH 1/2] Use closure for calling interpolateVariable --- public/app/plugins/datasource/postgres/datasource.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/postgres/datasource.ts b/public/app/plugins/datasource/postgres/datasource.ts index f1db05cabe8..49f4afb4271 100644 --- a/public/app/plugins/datasource/postgres/datasource.ts +++ b/public/app/plugins/datasource/postgres/datasource.ts @@ -50,7 +50,7 @@ export class PostgresDatasource { intervalMs: options.intervalMs, maxDataPoints: options.maxDataPoints, datasourceId: this.id, - rawSql: queryModel.render(this.interpolateVariable), + rawSql: queryModel.render((value, variable) => this.interpolateVariable(value, variable)), format: target.format, }; }); @@ -82,7 +82,9 @@ export class PostgresDatasource { const query = { refId: options.annotation.name, datasourceId: this.id, - rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable), + rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, (value, variable) => + this.interpolateVariable(value, variable) + ), format: 'table', }; @@ -108,7 +110,7 @@ export class PostgresDatasource { const interpolatedQuery = { refId: refId, datasourceId: this.id, - rawSql: this.templateSrv.replace(query, {}, this.interpolateVariable), + rawSql: this.templateSrv.replace(query, {}, (value, variable) => this.interpolateVariable(value, variable)), format: 'table', }; From 7b656097a72396bb351dec391578860918619e33 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 17 Oct 2018 13:30:07 +0200 Subject: [PATCH 2/2] postgres: use arrow function declaration of interpolateVariable --- public/app/plugins/datasource/postgres/datasource.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/public/app/plugins/datasource/postgres/datasource.ts b/public/app/plugins/datasource/postgres/datasource.ts index 49f4afb4271..13948c5d793 100644 --- a/public/app/plugins/datasource/postgres/datasource.ts +++ b/public/app/plugins/datasource/postgres/datasource.ts @@ -20,7 +20,7 @@ export class PostgresDatasource { this.interval = (instanceSettings.jsonData || {}).timeInterval; } - interpolateVariable(value, variable) { + interpolateVariable = (value, variable) => { if (typeof value === 'string') { if (variable.multi || variable.includeAll) { return this.queryModel.quoteLiteral(value); @@ -37,7 +37,7 @@ export class PostgresDatasource { return this.queryModel.quoteLiteral(v); }); return quotedValues.join(','); - } + }; query(options) { const queries = _.filter(options.targets, target => { @@ -50,7 +50,7 @@ export class PostgresDatasource { intervalMs: options.intervalMs, maxDataPoints: options.maxDataPoints, datasourceId: this.id, - rawSql: queryModel.render((value, variable) => this.interpolateVariable(value, variable)), + rawSql: queryModel.render(this.interpolateVariable), format: target.format, }; }); @@ -82,9 +82,7 @@ export class PostgresDatasource { const query = { refId: options.annotation.name, datasourceId: this.id, - rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, (value, variable) => - this.interpolateVariable(value, variable) - ), + rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable), format: 'table', }; @@ -110,7 +108,7 @@ export class PostgresDatasource { const interpolatedQuery = { refId: refId, datasourceId: this.id, - rawSql: this.templateSrv.replace(query, {}, (value, variable) => this.interpolateVariable(value, variable)), + rawSql: this.templateSrv.replace(query, {}, this.interpolateVariable), format: 'table', };