Repository navigation
feat(BAR-54): Adds a visual query builder - #68
Merged
Merged
Conversation
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.
📝 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 + Bor 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 aUNION, aWITHor a subquery inFROM, 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,RIGHTorFULLor 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 + Bthere, 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
BEGINtyped 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, orOFFSET … FETCHon SQL Server. A sort by an alias follows the alias through renames. GROUP BY follows every aggregate, including ones inside expressions, inHAVINGand inORDER BY, and keeps a grouping that only removes duplicates.ORDER BY 2reads as the column it points at, so reordering columns can't change it. On MySQL, a*after other columns becomest.*.Reading SQL:
barsql_sql::designputs aSELECTwith its joins,WHERE,GROUP BY,HAVING,ORDER BYand 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:* EXCEPT/REPLACE/APPLYASOF,GLOBALorHASHFOR UPDATEandSETTINGSFor 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 (
builderTabin the session). Duplicate copies all of it.Shortcut:
Ctrl/⌘ + Shift + Bis 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:
barsql_sql::design(the model, rendering per dialect, and import) andquery_builderwithgeometryandpanel.layout::route(now used by the builder too),zoom::stage,form::warning_barandcheck_mark,list_nav::drag_chip,tokens::STRIP_PADandworkspace::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:
USINGjoins and the refusals.🧩 Type of change
🧪 Tested
📖 Docs
📌 Notes