Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 16, 2025

Summary

This PR implements support for applying pragmas from the Query Settings Dialog to Table Preview queries, ensuring consistent behavior between regular query execution and table previews.

Problem

Previously, when users configured pragmas in the Query Settings Dialog, these pragmas were only applied to regular query executions but not to Table Preview queries. This created inconsistent behavior where:

  • Regular queries: PRAGMA OrderedColumns; SELECT * FROM table
  • Table previews: SELECT * FROM table LIMIT 101 (pragmas ignored)

Solution

Updated the Table Preview feature to include pragmas from Query Settings, making it consistent with regular query execution:

  • Regular queries: PRAGMA OrderedColumns; SELECT * FROM table
  • Table previews: PRAGMA OrderedColumns; SELECT * FROM table LIMIT 101

Changes Made

1. Enhanced Preview API (src/store/reducers/preview.ts)

  • Added pragmas?: string parameter to SendQueryParams interface
  • Updated query execution to use existing prepareQueryWithPragmas() function
  • Maintains consistency with regular query execution flow

2. Updated TablePreview Component (src/containers/Tenant/Query/Preview/components/TablePreview.tsx)

  • Added useQueryExecutionSettings hook to access current query settings
  • Pass current pragmas setting to preview API calls
  • Minimal, non-breaking changes to existing component

3. Comprehensive Test Coverage (src/containers/Tenant/Query/Preview/components/__test__/TablePreview.test.tsx)

  • Tests pragmas application to table preview queries
  • Tests handling of empty, undefined, and multiple pragmas
  • Validates existing functionality remains intact

Testing

  • ✅ All new tests pass (4 tests for table preview pragmas)
  • ✅ All existing pragma tests continue to pass (6 existing tests)
  • ✅ TypeScript compilation successful
  • ✅ Production build completes successfully
  • ✅ ESLint passes with no new issues

Example Usage

-- User sets pragma in Query Settings Dialog
PRAGMA OrderedColumns;

-- Now both work consistently:
-- 1. Regular query execution:
SELECT * FROM my_table WHERE id > 100

-- 2. Table preview (via preview button):
SELECT * FROM my_table LIMIT 101

-- Both queries will be executed with the pragma prepended

Implementation Details

  • Reuses existing prepareQueryWithPragmas() utility function
  • No code duplication or architectural changes
  • Backward compatible - no impact when pragmas are not set
  • Follows existing patterns for query settings integration

Fixes: table-preview-pragmas (follow-up to PR #2563)

This pull request was created as a result of the following prompt from Copilot chat.

Update the Table Preview feature so that all preview queries also include the pragmas value from the Query Settings Dialog, prepended to the SQL query, just like regular query executions.

Acceptance Criteria:

  • Whenever a Table Preview query is run, the current 'Pragmas' setting is prepended to the preview SQL.
  • This works for all tenant/table previews where the Query Settings Dialog is in use.
  • Tests are updated to cover this logic.
  • Documentation and i18n are updated if necessary.

Reference issue: table-preview-pragmas (follow-up to PR #2563: #2563)


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Apply pragmas setting to Table Preview queries Add pragmas support to Table Preview queries Jul 16, 2025
Copilot AI requested a review from adameat July 16, 2025 10:32
Copilot finished work on behalf of adameat July 16, 2025 10:32
@adameat adameat closed this Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants