Add client-side SQL syntax pre-validation before execution#62
Open
Add client-side SQL syntax pre-validation before execution#62
Conversation
Uses the sqlparser crate (already a dependency) to parse SQL locally before sending to PostgreSQL. This catches obvious syntax errors instantly without a database round-trip. - Pre-validates on F5/Ctrl+Enter using PostgreSqlDialect - Skips validation for PostgreSQL-specific commands (SHOW, SET, COPY, etc.) - Extracts line/column from sqlparser error messages - Displays errors using existing StructuredError UI - Fails open: if sqlparser can't parse valid PostgreSQL syntax, the query is still sent to the server Closes #55 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
sqlparsercrate (already a dependency) that runs before sending queries to PostgreSQLSELEC, missing clauses, etc.) instantly without a database round-tripsqlparserdoesn't support (SHOW,SET,COPY,VACUUM,DO, etc.) — these are sent directly to PostgreSQLsqlparsererror messages and displays them using the existing structured error UIsqlparserrejects a query that might be valid PostgreSQL-specific syntax, a hint is shown suggesting the parser may not support itWhat Changed
src/ui/app.rs: Addedprevalidate_sql()method andparse_line_col_from_sqlparser_error()helper. Integrated pre-validation into theexecute_query()flow — if parsing fails, the error is shown immediately without contacting the database.Test Plan
SELEC * FROM users) and press F5 — should see an instant syntax error without hitting the databaseSELECT * FROM users LIMIT 10) — should execute normally against the databaseSHOW server_version) — should skip pre-validation and execute on the server\meta-command prefix — should skip pre-validationcargo test— all 230 tests passCloses #55
🤖 Generated with Claude Code