mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* SQL: toRawSQL required and escape table * Fix autocomplete for MySQL * Change the way we escape for builder * Rework escape ident to be smart instead * Fix A11y for alias * Add first e2e test * Add test for code editor * Add doc * Review comments * Move functions to sqlUtil
24 lines
639 B
TypeScript
24 lines
639 B
TypeScript
import { useCallback } from 'react';
|
|
|
|
import { DB, SQLExpression, SQLQuery } from '../types';
|
|
|
|
interface UseSqlChange {
|
|
db: DB;
|
|
query: SQLQuery;
|
|
onQueryChange: (query: SQLQuery) => void;
|
|
}
|
|
|
|
export function useSqlChange({ query, onQueryChange, db }: UseSqlChange) {
|
|
const onSqlChange = useCallback(
|
|
(sql: SQLExpression) => {
|
|
const toRawSql = db.toRawSql;
|
|
const rawSql = toRawSql({ sql, dataset: query.dataset, table: query.table, refId: query.refId });
|
|
const newQuery: SQLQuery = { ...query, sql, rawSql };
|
|
onQueryChange(newQuery);
|
|
},
|
|
[db, onQueryChange, query]
|
|
);
|
|
|
|
return { onSqlChange };
|
|
}
|