Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 4b12e14

Browse files
author
Scott Lepper
committed
support query variables
1 parent 5ab9de9 commit 4b12e14

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/SqlProxyDatasource.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class DataSource extends DataSourceApi<SqlQuery, DataSourceJsonData> {
7171
targets: visibleTargets.map(target => {
7272
const query: SqlQuery = {
7373
...target,
74-
sql: this.applyMacros(this.templateSrv.replace(target.sql), options),
74+
sql: this.applyMacros(this.templateSrv.replace(target.sql, options.scopedVars), options),
7575
};
7676
return query;
7777
}),
@@ -115,8 +115,14 @@ export class DataSource extends DataSourceApi<SqlQuery, DataSourceJsonData> {
115115
}
116116

117117
metricFindQuery(query: any) {
118-
console.log('query', query);
119-
return Promise.resolve([]);
118+
const baseUrl = this.instanceSettings.url!;
119+
const route = baseUrl.endsWith('/') ? 'query?' : '/query?';
120+
const url = `${baseUrl}${route}sql=${query}`;
121+
return getBackendSrv()
122+
.datasourceRequest({ url })
123+
.then(res => {
124+
return res.data.map(v => ({text: Object.values(v)}));
125+
});
120126
}
121127

122128
async testDatasource() {

0 commit comments

Comments
 (0)