Skip to content

feat(BAR-54): Adds a visual query builder - #68

Merged
Bare7a merged 1 commit into
masterfrom
feat/BAR-54_visual-query-builder
Nov 30, 2026
Merged

Bare7a merged 1 commit into
masterfrom
feat/BAR-54_visual-query-builder

Conversation

@Bare7a

@Bare7a Bare7a commented Nov 30, 2026

Copy link
Copy Markdown
Owner

📝 What changed?

BarSQL had no way to build a query without writing it. Now a builder tab shows a query's tables as cards on a canvas, its joins as lines between their columns, and what it picks, filters, groups and sorts in a panel beside them. Every change rewrites the tab's SQL in the connection's own dialect, and the tab runs and explains it like a query tab. BarSQL's own parser reads the SQL. Closes #29.

  • Opening one: Builder on a query tab's toolbar, Open in builder in the editor's right-click menu, Ctrl/⌘ + Shift + B or the command palette copies the selection, or the statement at the caret, into a new builder tab. It's a one-off copy, and neither tab changes the other after. SQL the builder can't show, like a UNION, a WITH or a subquery in FROM, gets a toast saying why, and no tab opens. From any other tab it opens an empty builder, and Open in builder in a table's tree menu starts one on that table. Builder tabs are titled "Builder N · Connection", numbered apart from query tabs, with a blocks icon.

  • Canvas: tables come in by dragging them from the schema tree or through Add table. A table with a foreign key to one already there joins it on that key. Dragging a column onto another table's column joins on them, and a join's label switches it to LEFT, RIGHT or FULL or removes it. A click picks a column (none picked is *), and its right-click menu aggregates, sorts or filters on it. Cards read from SQL list their keys and the columns the query uses, with the rest a click away. Arrange lays the cards out, and zoom, pan, Fit and help look and work like the ER diagram's.

  • Panel: the picked columns in order, with their aggregates and names. Then DISTINCT, the filters (a column, an operator and a value, or any SQL condition), the grouping and its group filters, the sort, and how many rows to return and skip. Columns, filters and sorts reorder by their grips. The panel can be widened, and keeps its width, or hidden.

  • SQL view: Builder | SQL on the toolbar, or Ctrl/⌘ + Shift + B there, swaps the canvas for the query's SQL, which can be edited. It has Copy and Open in editor, which puts the SQL in a new query tab to save. Edits redraw the canvas when it shows again. SQL it can't show greys the canvas out and says why, with Edit SQL.

  • Running: Run, Explain (with Explain analyze where the engine has it) and Relational algebra take the whole query, with the results below as in a query tab. Each canvas change is one edit to the tab's SQL, so Undo and Redo step through canvas changes and SQL edits alike. The toolbar also has the database picker, and Commit / Rollback once a BEGIN typed in the SQL view opens a transaction.

  • The SQL it writes: names are quoted only where they need it. The rows to return become LIMIT / OFFSET, TOP, or OFFSET … FETCH on SQL Server. A sort by an alias follows the alias through renames. GROUP BY follows every aggregate, including ones inside expressions, in HAVING and in ORDER BY, and keeps a grouping that only removes duplicates. ORDER BY 2 reads as the column it points at, so reordering columns can't change it. On MySQL, a * after other columns becomes t.*.

  • Reading SQL: barsql_sql::design puts a SELECT with its joins, WHERE, GROUP BY, HAVING, ORDER BY and limit onto the canvas, and expressions it doesn't take apart keep their SQL. Anything it can't show is refused rather than dropped, such as:

    • set operations, CTEs and derived tables
    • ClickHouse's * EXCEPT / REPLACE / APPLY
    • join hints like ASOF, GLOBAL or HASH
    • FOR UPDATE and SETTINGS

    For this, the parser now records what it reads past (Query.skipped, Join.hint).

  • Sessions: a builder tab comes back with its SQL, the view it showed, and the cards that were moved, where they were left (builderTab in the session). Duplicate copies all of it.

  • Shortcut: Ctrl/⌘ + Shift + B is Query builder in the shortcuts dialog. A default whose keys were already given to another shortcut now stays unset instead of taking them, and Reset says which shortcut holds them.

  • Also fixed: zoomed in, the ER diagram and the relational algebra graph scroll up to their top again. A table row in the schema tree opens on a click that slips a few pixels into a drag.

  • Code:

    • New: barsql_sql::design (the model, rendering per dialect, and import) and query_builder with geometry and panel.
    • Shared helpers: the ER diagram's layout::route (now used by the builder too), zoom::stage, form::warning_bar and check_mark, list_nav::drag_chip, tokens::STRIP_PAD and workspace::open_numbered.
    • TabView::editor() picks query tabs where a builder tab doesn't fit: history reuse, Insert, saved-query matching, the status bar's caret and Go to line.
  • Size: no new crates. The exe grows about 1 MB (985 KB when last measured, before the review fixes).

  • Docs: a Query Builder section in the editor guide, the shortcut in the app guide, and the guide index.

  • Tests:

    • SQL: rendering and import per engine, every prefix importing or refusing with a stable round trip, grouping, ORDER BY positions, aliases, USING joins and the refusals.
    • Builder tabs: opening from a query tab, a selection and the tree; canvas picks rewriting the SQL, with undo; Run; the SQL view and its problem bar; foreign-key and drag joins; card layout; the session.
    • Panel: names, alignment, drag order, width and hiding.
    • Review fixes: the hidden editor never taking keys, stale canvas writes, unfinished filters, columns reloading, focus after ×, a transaction in a builder tab.
    • Elsewhere: the algebra graph from a builder tab, the ER diagram's zoomed top, the shortcut rule, the tree's slipped click, and the E2E tree menu positions.

🧩 Type of change

  • 🐛 Bug fix
  • ✨ Feature
  • ♻️ Refactor
  • ⬆️ Dependencies
  • 📝 Docs or landing page
  • 🛠️ Build, CI or packaging

🧪 Tested

  • By hand on Windows
  • By hand on macOS
  • By hand on Linux
  • Tests workflow on macOS and Windows

📖 Docs

  • Updated the guide
  • Updated the README or landing page
  • No docs needed

📌 Notes

@Bare7a
Bare7a merged commit 56b386c into master Nov 30, 2026
3 checks passed
@Bare7a
Bare7a deleted the feat/BAR-54_visual-query-builder branch November 30, 2026 22:40
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.

feat: visual query builder

1 participant