Skip to content

Commit

Permalink
Merge pull request #107 from questdb/update-query-builder-settings
Browse files Browse the repository at this point in the history
Enclose variables in quotes
  • Loading branch information
insmac authored Jul 19, 2024
2 parents 002b2be + d09adb7 commit df9f894
Show file tree
Hide file tree
Showing 7 changed files with 584 additions and 440 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ and this project adheres to
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## 0.1.4

## Changed

- Enclose variables and column names in quotes in the generated SQL [#107](https://github.com/questdb/grafana-questdb-datasource/pull/107)
- Add VARCHAR type [#107](https://github.com/questdb/grafana-questdb-datasource/pull/107)
- Update docker-compose yaml to use QuestDB 8.0.3 [#107](https://github.com/questdb/grafana-questdb-datasource/pull/107)

## 0.1.3

## Changed
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- grafana

questdb:
image: 'questdb/questdb:7.3.9'
image: 'questdb/questdb:8.0.3'
container_name: 'grafana-questdb-server'
ports:
- '8812:8812'
Expand All @@ -29,4 +29,4 @@ services:
- grafana

networks:
grafana:
grafana:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "questdb-questdb-datasource",
"version": "0.1.3",
"version": "0.1.4",
"description": "QuestDB Datasource for Grafana",
"engines": {
"node": ">=18"
Expand Down
15 changes: 10 additions & 5 deletions src/components/QueryTypeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useState } from 'react';
import { SelectableValue } from '@grafana/data';
import { SelectableValue, VariableWithMultiSupport } from '@grafana/data';
import { RadioButtonGroup, ConfirmModal } from '@grafana/ui';
import { getQueryOptionsFromSql, getSQLFromQueryOptions } from './queryBuilder/utils';
import { selectors } from './../selectors';
import { QuestDBQuery, QueryType, defaultBuilderQuery, SqlBuilderOptions, QuestDBSQLQuery } from 'types';
import { isString } from 'lodash';
import {Datasource} from "../data/QuestDbDatasource";
import { Datasource } from '../data/QuestDbDatasource';
import { getTemplateSrv } from '@grafana/runtime';

interface QueryTypeSwitcherProps {
query: QuestDBQuery;
Expand All @@ -26,6 +27,8 @@ export const QueryTypeSwitcher = ({ query, onChange, datasource }: QueryTypeSwit
{ label: queryTypeLabels.QueryBuilder, value: QueryType.Builder },
];
const [errorMessage, setErrorMessage] = useState<string>('');
const templateVars = getTemplateSrv().getVariables() as VariableWithMultiSupport[];

async function onQueryTypeChange(queryType: QueryType, confirm = false) {
if (query.queryType === QueryType.SQL && queryType === QueryType.Builder && !confirm) {
const queryOptionsFromSql = await getQueryOptionsFromSql(query.rawSql);
Expand All @@ -43,7 +46,9 @@ export const QueryTypeSwitcher = ({ query, onChange, datasource }: QueryTypeSwit
builderOptions = query.builderOptions;
break;
case QueryType.SQL:
builderOptions = (await getQueryOptionsFromSql(query.rawSql, datasource) as SqlBuilderOptions) || defaultBuilderQuery.builderOptions;
builderOptions =
((await getQueryOptionsFromSql(query.rawSql, datasource)) as SqlBuilderOptions) ||
defaultBuilderQuery.builderOptions;
break;
default:
builderOptions = defaultBuilderQuery.builderOptions;
Expand All @@ -53,13 +58,13 @@ export const QueryTypeSwitcher = ({ query, onChange, datasource }: QueryTypeSwit
onChange({
...query,
queryType,
rawSql: getSQLFromQueryOptions(builderOptions),
rawSql: getSQLFromQueryOptions(builderOptions, templateVars),
meta: { builderOptions },
format: query.format,
selectedFormat: query.selectedFormat,
});
} else if (queryType === QueryType.Builder) {
onChange({ ...query, queryType, rawSql: getSQLFromQueryOptions(builderOptions), builderOptions });
onChange({ ...query, queryType, rawSql: getSQLFromQueryOptions(builderOptions, templateVars), builderOptions });
}
}
}
Expand Down
Loading

0 comments on commit df9f894

Please sign in to comment.