Skip to content

feat: add backend SQL construction service and fix query result display#118

Open
Blankll wants to merge 1 commit into
masterfrom
fix/sql-service-query-construction
Open

feat: add backend SQL construction service and fix query result display#118
Blankll wants to merge 1 commit into
masterfrom
fix/sql-service-query-construction

Conversation

@Blankll

@Blankll Blankll commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

Moves all SQL construction (wrapping, filtering, sorting, pagination) from the frontend to the backend with proper sqlparser-based parsing and validation.

Changes

sql_service.rs (new)

Centralized SQL construction service. Handles:

  • Stripping trailing semicolons and -- comments before wrapping
  • Parsing with sqlparser to validate single SELECT/WITH statements
  • Injecting schema qualification on unqualified table references
  • Building WHERE/ORDER BY/LIMIT clauses from structured data
  • Rejecting multi-statement or DML input with clear error messages

QueryResultPanel.vue

  • Removed buildWrappedSql — frontend no longer constructs SQL strings
  • Sends structured sort/filter state to new execute_sorted_query command
  • Backend derives database type from active connection

DataGrid.vue

  • Fixed virtual scroller: column header moved outside scroll container
    so rows are never hidden behind the sticky header
  • Added hideBatchActions prop to suppress batch action bar in query
    result panel

useSqlStatements.ts

  • Replaced line-based + regex statement parser with a character-based
    state machine that tracks quotes, backticks, and comments
  • Fixes false splitting of correlated subqueries like
    (SELECT count(*) FROM t WHERE x = y) as alias

search.rs

  • UUID columns use ::text cast instead of CAST(... AS TEXT)
  • Added exact-match optimization for UUID-formatted search terms
  • JSON/JSONB columns also use ::text for compatibility

Testing

  • 14 new unit tests for sql_service.rs covering: trailing semicolons,
    comments, multi-statement rejection, DML rejection, schema injection,
    filter/sort/pagination, MySQL and SQL Server dialects
  • All 286 existing Rust tests pass
  • All 416 frontend tests pass

- Add sql_service.rs — centralized SQL wrapping with sqlparser validation,
  trailing semicolon/comment stripping, schema injection, and structured
  sort/filter/pagination construction. Replaces frontend buildWrappedSql.
- Add execute_sorted_query Tauri command — structured sort/filter API
  that derives database type from the active connection.
- Fix DataGrid virtual scroller — move column header outside scroll
  container so rows with 0-1 results aren't hidden behind sticky header.
- Fix statement parser — replace line-based + regex approach with
  character-based state machine that correctly handles correlated
  subqueries spanning multiple lines.
- Add hideBatchActions prop to DataGrid to suppress batch action bar
  in query result panel (no table context for delete/export).
- Type-aware table search — UUID/JSON columns use ::text cast instead
  of fragile CAST(... AS TEXT), with exact-match optimization.
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.

1 participant