Skip to content

Commit 25e9c08

Browse files
committed
fix: PR fixes
1 parent cc16e88 commit 25e9c08

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/store/reducers/query/__test__/prepareQueryWithPragmas.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
// This is a test file for the prepareQueryWithPragmas function
2-
// Since the function is not exported, we'll test it indirectly through integration
3-
// This file is for documentation purposes and can be removed
1+
import {prepareQueryWithPragmas} from '../utils';
42

53
describe('prepareQueryWithPragmas', () => {
64
test('Should prepend pragmas correctly', () => {
75
// This tests the behavior through the actual query API
86
const pragma = 'PRAGMA OrderedColumns;';
97
const query = 'SELECT * FROM table;';
10-
const expectedResult = `${pragma}\n\n${query}`;
8+
const expectedResult = prepareQueryWithPragmas(query, pragma);
119

1210
// The actual test would be integration test with the query API
1311
expect(expectedResult).toBe('PRAGMA OrderedColumns;\n\nSELECT * FROM table;');
1412
});
1513

1614
test('Should handle empty pragmas', () => {
17-
const _pragma = '';
1815
const query = 'SELECT * FROM table;';
16+
const pragma = '';
17+
const expectedResult = prepareQueryWithPragmas(query, pragma);
1918

2019
// When pragma is empty, query should remain unchanged
21-
expect(query).toBe('SELECT * FROM table;');
20+
expect(expectedResult).toBe('SELECT * FROM table;');
2221
});
2322

2423
test('Should handle pragmas without semicolon', () => {
2524
const pragma = 'PRAGMA OrderedColumns';
2625
const query = 'SELECT * FROM table;';
27-
const expectedResult = `${pragma};\n\n${query}`;
26+
const expectedResult = prepareQueryWithPragmas(query, pragma);
2827

2928
expect(expectedResult).toBe('PRAGMA OrderedColumns;\n\nSELECT * FROM table;');
3029
});

src/store/reducers/query/query.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
setStreamSession as setStreamSessionReducer,
1919
} from './streamingReducers';
2020
import type {QueryResult, QueryState} from './types';
21-
import {getActionAndSyntaxFromQueryMode, getQueryInHistory} from './utils';
21+
import {getActionAndSyntaxFromQueryMode, getQueryInHistory, prepareQueryWithPragmas} from './utils';
2222

2323
const MAXIMUM_QUERIES_IN_HISTORY = 20;
2424

@@ -209,18 +209,6 @@ interface QueryStats {
209209
const DEFAULT_STREAM_CHUNK_SIZE = 1000;
210210
const DEFAULT_CONCURRENT_RESULTS = false;
211211

212-
const prepareQueryWithPragmas = (query: string, pragmas?: string): string => {
213-
if (!pragmas || !pragmas.trim()) {
214-
return query;
215-
}
216-
217-
// Add pragmas at the beginning with proper line separation
218-
const trimmedPragmas = pragmas.trim();
219-
const separator = trimmedPragmas.endsWith(';') ? '\n\n' : ';\n\n';
220-
221-
return `${trimmedPragmas}${separator}${query}`;
222-
};
223-
224212
export const queryApi = api.injectEndpoints({
225213
endpoints: (build) => ({
226214
useStreamQuery: build.mutation<null, StreamQueryParams>({

src/store/reducers/query/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,15 @@ export function isQueryResponseChunk(content: StreamingChunk): content is QueryR
5050
export function isKeepAliveChunk(content: StreamingChunk): content is SessionChunk {
5151
return content?.meta?.event === 'KeepAlive';
5252
}
53+
54+
export const prepareQueryWithPragmas = (query: string, pragmas?: string): string => {
55+
if (!pragmas || !pragmas.trim()) {
56+
return query;
57+
}
58+
59+
// Add pragmas at the beginning with proper line separation
60+
const trimmedPragmas = pragmas.trim();
61+
const separator = trimmedPragmas.endsWith(';') ? '\n\n' : ';\n\n';
62+
63+
return `${trimmedPragmas}${separator}${query}`;
64+
};

src/utils/query.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,16 @@ export const parseQueryErrorToString = (error: unknown) => {
297297
return parsedError?.error?.message;
298298
};
299299

300+
export const defaultPragma = 'PRAGMA OrderedColumns;';
301+
300302
export const DEFAULT_QUERY_SETTINGS = {
301303
queryMode: QUERY_MODES.query,
302304
transactionMode: TRANSACTION_MODES.implicit,
303305
timeout: null,
304306
limitRows: 10000,
305307
statisticsMode: STATISTICS_MODES.none,
306308
tracingLevel: TRACING_LEVELS.off,
307-
pragmas: 'PRAGMA OrderedColumns;',
309+
pragmas: defaultPragma,
308310
};
309311

310312
export const queryModeSchema = z.nativeEnum(QUERY_MODES);

tests/suites/tenant/diagnostics/tabs/queries.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {expect, test} from '@playwright/test';
22

3+
import {prepareQueryWithPragmas} from '../../../../../src/store/reducers/query/utils';
4+
import {defaultPragma} from '../../../../../src/utils/query';
35
import {tenantName} from '../../../../utils/constants';
46
import {NavigationTabs, TenantPage} from '../../TenantPage';
57
import {longRunningQuery, longRunningStreamQuery} from '../../constants';
@@ -51,8 +53,9 @@ test.describe('Diagnostics Queries tab', async () => {
5153
const diagnostics = new Diagnostics(page);
5254
await diagnostics.clickTab(DiagnosticsTab.Queries);
5355
await diagnostics.clickRadioSwitch(QueriesSwitch.Running);
56+
const finalQueryText = prepareQueryWithPragmas(longRunningQuery, defaultPragma);
5457
expect(
55-
await diagnostics.table.waitForCellValueByHeader(1, 'Query text', longRunningQuery),
58+
await diagnostics.table.waitForCellValueByHeader(1, 'Query text', finalQueryText),
5659
).toBe(true);
5760
});
5861

0 commit comments

Comments
 (0)