Skip to content

Commit

Permalink
Add support for client side variable interpolation (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd authored Jun 21, 2023
1 parent 05f8e19 commit 2a1a2d2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataSourceInstanceSettings, CoreApp } from '@grafana/data';
import { DataSourceWithBackend } from '@grafana/runtime';
import { CoreApp, DataSourceInstanceSettings, ScopedVars } from '@grafana/data';
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';

import { SnellerQuery, SnellerDataSourceOptions, DEFAULT_QUERY } from './types';
import { DEFAULT_QUERY, SnellerDataSourceOptions, SnellerQuery } from './types';
import { SnellerVariableSupport } from "./variables";

export class DataSource extends DataSourceWithBackend<SnellerQuery, SnellerDataSourceOptions> {
Expand All @@ -13,4 +13,12 @@ export class DataSource extends DataSourceWithBackend<SnellerQuery, SnellerDataS
getDefaultQuery(_: CoreApp): Partial<SnellerQuery> {
return DEFAULT_QUERY
}

applyTemplateVariables(query: SnellerQuery, scopedVars: ScopedVars): Record<string, any> {
console.log(query.sql)
return {
...query,
sql: getTemplateSrv().replace(query.sql, scopedVars),
};
}
}

0 comments on commit 2a1a2d2

Please sign in to comment.