Skip to content

Commit

Permalink
Fix issue with multi-value query variables. Close #84
Browse files Browse the repository at this point in the history
  • Loading branch information
devnied committed Sep 18, 2024
1 parent 159543a commit d22d7d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### ⭐ Added
- Add `$__timeTzFilter(column_name)` macro.

### 🐞 Bug Fixes
- Fix issue with multi-value query variables.

### 🔨 Changed
- Upgrade grafana-plugin-sdk-go to version v0.246.0.
- Upgrade gosnowflake to version v1.11.1.
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ For Time series query:

![Query editor](img/query.png)

##### Query Variables

You can use query variable in your query.<br/>
Query variables are used to filter the data displayed in the dashboard.

Sample query variable usage:
```sql
SELECT column FROM table WHERE column in ($variable)
```

##### Layout of a query

*Simple query*
Expand Down
9 changes: 8 additions & 1 deletion src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ export class DataSource extends DataSourceWithBackend<SnowflakeQuery, SnowflakeO
this.annotations = {};
}

private format(value: any) {
if (Array.isArray(value)) {
return `'${value.join("','")}'`;
}
return value;
}

applyTemplateVariables(query: SnowflakeQuery, scopedVars: ScopedVars): SnowflakeQuery {
query.queryText = getTemplateSrv().replace(query.queryText, scopedVars);
query.queryText = getTemplateSrv().replace(query.queryText, scopedVars, this.format);
return query;
}

Expand Down

0 comments on commit d22d7d1

Please sign in to comment.