feat(views): add SQL beautify button to view editor#372
Open
danielnuld wants to merge 2 commits into
Open
Conversation
Add a "Beautify" button to the view editor modal that formats the view definition SQL using sql-formatter, mapping the active driver's dialect (postgres, mysql, mssql, sqlite, oracle) to the matching formatter language. The formatter falls back to the original text on empty input or parse errors so the user's SQL is never lost. Adds the `views.formatSql` i18n key across all 8 locales.
d87a938 to
a9422a4
Compare
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Previous Review Summary (commit a9422a4)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit a9422a4)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (11 files)
Reviewed by kimi-k2.7-code · Input: 48.9K · Output: 6.6K · Cached: 365.8K |
- Read the editor's live value in handleFormat via an onMount editor ref instead of the debounced `definition` state, so edits typed within the 300ms debounce window are no longer discarded by the format. - Add tests for sqlFormat covering each dialect mapping, keyword casing, empty/whitespace passthrough, and the parse-error fallback path.
Contributor
Author
|
Thanks for the review. Both warnings addressed in bcd169b:
|
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
Adds a Beautify button to the view editor modal (create & edit) that pretty-prints the view definition SQL.
Why
When editing a view, the definition returned by the database is often a single dense line (e.g. MySQL stores
SELECT c.id,c.name,...with no whitespace). This makes it hard to read and edit. A one-click formatter improves the editing experience.How
sql-formatter(^15.8.2) as a dependency.src/utils/sqlFormat.tsexposingformatSql(sql, dialect), which maps the active driver's dialect to the matchingsql-formatterlanguage:postgres → postgresql,mysql → mysql,mssql → transactsql,sqlite → sqlite,oracle → plsql, everything else →sql.ViewEditorModalgets aBeautifybutton next to the View Definition label, wired to the active connection'ssql_dialect.views.formatSqli18n key to all 8 locales (en, es, it, fr, de, ja, ru, zh).Testing
pnpm typecheckandpnpm buildpass; ESLint clean on changed files.SELECT … JOIN … WHERE … GROUP BY … HAVING … ORDER BYreformatted with proper indentation and keyword casing.