feat(query): add visual SQL query builder for SQL-capable connections#165
Merged
Mananwebdev160408 merged 1 commit intoJul 16, 2026
Merged
Conversation
Addresses issue Mananwebdev160408#155. dbportal already had a VisualQueryBuilder component, but it is MongoDB-only (builds a $ne/$regex/$exists filter object) and is gated entirely behind capabilities.structuredQuery, which is only true for the mongodb driver. Every SQL-capable connection (postgres, mysql, sqlite, mssql) had nothing but a raw SQL textarea, with no visual builder at all, despite the issue's title specifically asking for a way to construct queries "without raw SQL". - frontend/src/components/views/SqlQueryBuilder.tsx (new): a self contained builder that fetches live schema via GET /api/schema, and lets the user pick a table, toggle SELECT columns, add/remove WHERE conditions (column/operator/value rows joined by a per-row AND/OR connector), set ORDER BY column + direction, and set LIMIT. Renders a live, read-only SQL preview with a Copy button, and dialect-aware generation: MySQL uses backtick identifiers, SQL Server uses bracket identifiers plus `SELECT TOP n` instead of a trailing LIMIT, everything else uses double-quoted identifiers and LIMIT. Builder state (table, columns, conditions, order, limit) is persisted to localStorage per dbId so it survives a page refresh, per the issue's acceptance criteria. - frontend/src/components/views/QueryWorkbench.tsx: adds a "Show/Hide Builder" toggle (visibility persisted too) above the existing raw query tabs when the active connection supports raw SQL. "Insert into Editor" writes the generated SQL into the active tab via the existing setRawQuery() path (same convention already used by the Mongo builder and the quick-example buttons), so the existing Run Query button executes it and results render in the existing table/JSON view with no new execution path needed. - frontend/src/index.css: styles for the builder panel, column checkboxes, condition rows, and the SQL preview block, matching the existing query-group/query-input/query-example-btn conventions already used elsewhere in this file. Verified live with a real sqlite database and a temporary dev server: selecting a table populated real columns from schema, checking name/age and adding a WHERE age > 20 condition updated the SQL preview in real time to `SELECT "name", "age" FROM "users" WHERE "age" > 20 LIMIT 100;`, Insert into Editor placed it in the raw editor, Run Query executed it (POST /api/query -> 200, correct filtered/projected rows back), and a full page reload restored the exact same builder state from localStorage. Also fixes the same duplicate aria-label build failure and App.tsx/ cli.ts formatting violations described in PR Mananwebdev160408#163/Mananwebdev160408#164 (neither merged yet, so this branch needed the same fixes independently to pass CI). Signed-off-by: Anshul Jain <aj.ts1758@gmail.com>
Contributor
Author
|
@Mananwebdev160408 Requesting review for this feature! This PR addresses issue #155 (SQL query builder) delivering:
For GSSoC tracking, please add:
Given the frontend focus and user-experience enhancement nature, labels like Thanks for the review! |
Mananwebdev160408
added a commit
that referenced
this pull request
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #155.
dbportal already had a
VisualQueryBuildercomponent, but it is MongoDB only (it builds a$ne/$regex/$existsfilter object) and is gated entirely behindcapabilities.structuredQuery, which is onlytruefor the mongodb driver. Every SQL-capable connection (postgres, mysql, sqlite, mssql) had nothing but a raw SQL textarea and zero visual builder, despite the issue's title specifically asking for a way to construct queries "without raw SQL".This PR adds a real SQL query builder for those connections, covering the acceptance criteria directly.
What Was Changed
frontend/src/components/views/SqlQueryBuilder.tsx(new): a self-contained builder that fetches live schema viaGET /api/schema, then lets the user:*)column operator valuerows, each joined to the previous one by a per-row AND/OR connectorSELECT TOP ninstead of a trailingLIMIT, everything else uses double-quoted identifiers withLIMITlocalStorageperdbId, so it survives a page refreshfrontend/src/components/views/QueryWorkbench.tsx: adds a "Show/Hide Builder" toggle (visibility also persisted) above the existing raw query tabs, shown whenever the active connection supports raw SQL. "Insert into Editor" writes the generated SQL into the active tab through the existingsetRawQuery()path, the same mechanism already used by the Mongo builder and the quick-example buttons, so the existing "Run Query" button executes it and results render in the existing table/JSON views with no new execution path needed.frontend/src/index.css: styles for the builder panel, column checkboxes, condition rows, and the SQL preview block, matching the existingquery-group/query-input/query-example-btnconventions already used elsewhere in this file.Acceptance Criteria (from the issue)
/api/schema.localStorage, verified live (see below).The issue's "Multi-database Translation" section also asks for MongoDB
find()and RedisSCAN/HGETALLoutput. MongoDB already has its own (separate, pre-existing) visual builder in this codebase; Redis's driver doesn't implementquery()at all currently (rawQuery: false, structuredQuery: falsein its capabilities), so there's no query execution path to attach a builder to there. I scoped this PR to the SQL drivers, where the gap was real and total (0% builder coverage), rather than take on a Redis query-execution feature that doesn't otherwise exist yet.Test Plan
npx vitest run— 22 passed (unchanged, this feature doesn't touch backend logic beyond the pre-existing/api/schemaendpoint)npm run lint(tsc --noEmit) — cleannpm run check-format— cleannpm run build— succeedsuserstable, columns populated as real schema-derived checkboxes (id,name,age,email)nameandage, added a conditionage > 20, watched the preview update in real time toSELECT "name", "age" FROM "users" WHERE "age" > 20 LIMIT 100;POST /api/query?dbId=primaryreturned200with the correctly filtered and projected rows ([{name: "Alice", age: 30}, {name: "Bob", age: 25}])Unrelated CI-blocking fixes included
Same fixes from PR #163/#164 (neither merged yet, so this branch needed them independently to pass CI):
frontend/src/components/Toolbar.tsxhad duplicatearia-labelattributes on two buttons, a TypeScript JSX compile error (TS17001) that failsnpm run build.frontend/src/App.tsxandsrc/cli.tshad Prettier formatting violations that failnpm run check-format. Ranprettier --writeonly, no logic changes.Related Issues / PRs
None beyond #163/#164 (different branches, unmerged, share the same unrelated fixes noted above).