|
| 1 | +// Integration test for pragmas functionality |
| 2 | +describe('Pragmas Integration Tests', () => { |
| 3 | + test('should correctly prepend pragmas to query for execution', () => { |
| 4 | + // Test the actual function logic that would be used in query execution |
| 5 | + const testQuery = 'SELECT * FROM users WHERE id = 1;'; |
| 6 | + const testPragmas = 'PRAGMA OrderedColumns;'; |
| 7 | + |
| 8 | + // This is the logic from our prepareQueryWithPragmas function |
| 9 | + const prepareQuery = (query: string, pragmas?: string): string => { |
| 10 | + if (!pragmas || !pragmas.trim()) { |
| 11 | + return query; |
| 12 | + } |
| 13 | + |
| 14 | + const trimmedPragmas = pragmas.trim(); |
| 15 | + const separator = trimmedPragmas.endsWith(';') ? '\n\n' : ';\n\n'; |
| 16 | + |
| 17 | + return `${trimmedPragmas}${separator}${query}`; |
| 18 | + }; |
| 19 | + |
| 20 | + const result = prepareQuery(testQuery, testPragmas); |
| 21 | + |
| 22 | + expect(result).toBe('PRAGMA OrderedColumns;\n\nSELECT * FROM users WHERE id = 1;'); |
| 23 | + }); |
| 24 | + |
| 25 | + test('should handle multiple pragmas correctly', () => { |
| 26 | + const query = 'SELECT COUNT(*) FROM orders;'; |
| 27 | + const pragmas = `PRAGMA OrderedColumns; |
| 28 | +PRAGMA AnsiOptionalAS; |
| 29 | +PRAGMA DisableAnsiRankForNullableKeys;`; |
| 30 | + |
| 31 | + const prepareQuery = (query: string, pragmas?: string): string => { |
| 32 | + if (!pragmas || !pragmas.trim()) { |
| 33 | + return query; |
| 34 | + } |
| 35 | + |
| 36 | + const trimmedPragmas = pragmas.trim(); |
| 37 | + const separator = trimmedPragmas.endsWith(';') ? '\n\n' : ';\n\n'; |
| 38 | + |
| 39 | + return `${trimmedPragmas}${separator}${query}`; |
| 40 | + }; |
| 41 | + |
| 42 | + const result = prepareQuery(query, pragmas); |
| 43 | + |
| 44 | + expect(result).toContain('PRAGMA OrderedColumns;'); |
| 45 | + expect(result).toContain('PRAGMA AnsiOptionalAS;'); |
| 46 | + expect(result).toContain('PRAGMA DisableAnsiRankForNullableKeys;'); |
| 47 | + expect(result).toContain('SELECT COUNT(*) FROM orders;'); |
| 48 | + }); |
| 49 | + |
| 50 | + test('should preserve query when pragmas are empty', () => { |
| 51 | + const query = 'EXPLAIN SELECT * FROM table;'; |
| 52 | + const pragmas = ''; |
| 53 | + |
| 54 | + const prepareQuery = (query: string, pragmas?: string): string => { |
| 55 | + if (!pragmas || !pragmas.trim()) { |
| 56 | + return query; |
| 57 | + } |
| 58 | + |
| 59 | + const trimmedPragmas = pragmas.trim(); |
| 60 | + const separator = trimmedPragmas.endsWith(';') ? '\n\n' : ';\n\n'; |
| 61 | + |
| 62 | + return `${trimmedPragmas}${separator}${query}`; |
| 63 | + }; |
| 64 | + |
| 65 | + const result = prepareQuery(query, pragmas); |
| 66 | + |
| 67 | + expect(result).toBe(query); |
| 68 | + }); |
| 69 | +}); |
0 commit comments