Skip to content

Commit ff85ffc

Browse files
Copilotadameat
andauthored
feat(query): apply pragmas setting to Table Preview queries (#2575)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: adameat <34044711+adameat@users.noreply.github.com>
1 parent 7a7f038 commit ff85ffc

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {prepareQueryWithPragmas} from '../../../../../store/reducers/query/utils';
2+
3+
describe('TablePreview - Pragma Integration', () => {
4+
test('should correctly prepare query with pragmas for table preview', () => {
5+
const baseQuery = 'select * from `test-table` limit 101';
6+
const pragmas = 'PRAGMA OrderedColumns;';
7+
8+
const result = prepareQueryWithPragmas(baseQuery, pragmas);
9+
10+
expect(result).toBe('PRAGMA OrderedColumns;\n\nselect * from `test-table` limit 101');
11+
});
12+
13+
test('should handle empty pragmas correctly in table preview', () => {
14+
const baseQuery = 'select * from `test-table` limit 101';
15+
const pragmas = '';
16+
17+
const result = prepareQueryWithPragmas(baseQuery, pragmas);
18+
19+
expect(result).toBe('select * from `test-table` limit 101');
20+
});
21+
22+
test('should handle multiple pragmas correctly in table preview', () => {
23+
const baseQuery = 'select * from `test-table` limit 101';
24+
const pragmas = 'PRAGMA OrderedColumns;\nPRAGMA AnsiOptionalAS;';
25+
26+
const result = prepareQueryWithPragmas(baseQuery, pragmas);
27+
28+
expect(result).toBe(
29+
'PRAGMA OrderedColumns;\nPRAGMA AnsiOptionalAS;\n\nselect * from `test-table` limit 101',
30+
);
31+
});
32+
33+
test('should handle pragmas without semicolon correctly in table preview', () => {
34+
const baseQuery = 'select * from `test-table` limit 101';
35+
const pragmas = 'PRAGMA OrderedColumns';
36+
37+
const result = prepareQueryWithPragmas(baseQuery, pragmas);
38+
39+
expect(result).toBe('PRAGMA OrderedColumns;\n\nselect * from `test-table` limit 101');
40+
});
41+
});

src/containers/Tenant/Query/Preview/components/TablePreview.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {QueryResultTable} from '../../../../../components/QueryResultTable';
22
import {previewApi} from '../../../../../store/reducers/preview';
3+
import {prepareQueryWithPragmas} from '../../../../../store/reducers/query/utils';
4+
import {useQueryExecutionSettings} from '../../../../../utils/hooks/useQueryExecutionSettings';
35
import {isExternalTableType} from '../../../utils/schema';
46
import type {PreviewContainerProps} from '../types';
57

@@ -8,7 +10,11 @@ import {Preview} from './PreviewView';
810
const TABLE_PREVIEW_LIMIT = 100;
911

1012
export function TablePreview({database, path, type}: PreviewContainerProps) {
11-
const query = `select * from \`${path}\` limit 101`;
13+
const [querySettings] = useQueryExecutionSettings();
14+
15+
const baseQuery = `select * from \`${path}\` limit 101`;
16+
const query = prepareQueryWithPragmas(baseQuery, querySettings.pragmas);
17+
1218
const {currentData, isFetching, error} = previewApi.useSendQueryQuery(
1319
{
1420
database,

0 commit comments

Comments
 (0)