Skip to content

Commit

Permalink
change time macros names (#39)
Browse files Browse the repository at this point in the history
* change name

* update read me
  • Loading branch information
Scott Lepper authored Jan 14, 2022
1 parent d23eabb commit faeeccf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.6

Bug - Change time template variable names.

## 0.9.5

Bug - Fix global template variables.
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ FROM test_data
WHERE $__timeFilter(date_time)
```

| Macro example | Description |
| ------------------------ | ---------------------------------------------------------------------------------- |
| *$__timeFilter(dataRow)* | Will be replaced by a time range filter using the specified name. |
| *$__from* | Will be replaced by the start of the currently active time range filter selection. |
| *$__to* | Will be replaced by the end of the currently active time range filter selection. |
| *$__table* | Will be replaced by the table in use. |
| *$__column* | Will be replaced by the column in use. |
| Macro example | Description |
| -- | --|
| *$__timeFilter(dataRow)* | Will be replaced by a time range filter using the specified name. |
| *$__fromTime* | Replaced by the start of time range in ms wrapped by toDateTime function. Example: toDateTime(intDiv(1415792726371,1000)) |
| *$__toTime* | Replaced by the end of time range in ms wrapped by toDateTime function. Example: toDateTime(intDiv(1415792726371,1000)) |
| *$__table* | Will be replaced by the table in use. |
| *$__column* | Will be replaced by the column in use. |

The plugin also supports notation using braces {}. Use this notation when queries are needed inside parameters.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clickhouse-datasource",
"version": "0.9.5",
"version": "0.9.6",
"description": "Clickhouse Datasource",
"scripts": {
"build": "grafana-toolkit plugin:build",
Expand Down
3 changes: 2 additions & 1 deletion pkg/macros/macros_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestMacroFromTimeFilter(t *testing.T) {
From: from,
To: to,
},
RawSQL: "select foo from foo where bar > $__from",
RawSQL: "select foo from foo where bar > $__fromTime",
}
tests := []struct {
want string
Expand Down Expand Up @@ -50,6 +50,7 @@ func TestMacroToTimeFilter(t *testing.T) {
From: from,
To: to,
},
RawSQL: "select foo from foo where bar > $__toTime",
}
tests := []struct {
want string
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (h *Clickhouse) Converters() []sqlutil.Converter {
// Macros returns list of macro functions convert the macros of raw query
func (h *Clickhouse) Macros() sqlds.Macros {
return map[string]sqlds.MacroFunc{
"from": macros.FromTimeFilter,
"to": macros.ToTimeFilter,
"fromTime": macros.FromTimeFilter,
"toTime": macros.ToTimeFilter,
"timeFilter": macros.TimeFilter,
"table": macros.Table,
"column": macros.Column,
Expand Down

0 comments on commit faeeccf

Please sign in to comment.