Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enclose variables in quotes #107

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading