Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

Summary

  • Implements comprehensive formatting support for SQLite SQL statements, enabling round-trip format testing similar to MySQL
  • Adds SQLite-specific format.go implementing the Formatter interface with proper named parameter syntax (:name)
  • Fixes several AST formatting issues discovered during SQLite format testing

Key Changes

Formatter Interface:

  • Add NamedParam(name string) string method to support dialect-specific named parameter syntax
  • PostgreSQL: @name, MySQL: ?, SQLite: :name

AST Formatting Fixes:

  • CollateExpr: Add missing Format method for COLLATE <collation> support
  • InsertStmt: Add DefaultValues bool field for INSERT INTO ... DEFAULT VALUES syntax
  • A_Expr: Refactor named param detection to work regardless of Kind field

SQLite Parser Improvements:

  • Fix BoolExpr Boolop field not being set for AND/OR expressions
  • Add proper EXISTS/NOT EXISTS subquery handling via SubLink nodes
  • Fix table function argument conversion (e.g., json_each(json_extract(...)))
  • Add unary expression support (NOT operator)
  • Fix NULL literal conversion

Test plan

  • All TestFormat tests pass (validates AST→SQL→fingerprint matches original)
  • All TestReplay tests pass (regenerated expected output for EXISTS tests)
  • All existing go test ./... tests pass
  • No regressions in PostgreSQL or MySQL formatting

🤖 Generated with Claude Code

Implements comprehensive formatting support for SQLite SQL statements,
enabling round-trip format testing similar to MySQL. Key changes:

**New SQLite Formatter:**
- Add format.go implementing Formatter interface for SQLite dialect
- Support SQLite-specific named parameter syntax (`:name` instead of `@name`)

**AST Formatting Fixes:**
- Add `NamedParam` method to Formatter interface for dialect-specific named params
- Fix `CollateExpr` missing Format method for COLLATE clause support
- Add `DefaultValues` field to InsertStmt for INSERT DEFAULT VALUES syntax
- Fix table function argument conversion (e.g., json_each())

**SQLite Parser Improvements:**
- Fix BoolExpr Boolop field for AND/OR expressions
- Add EXISTS/NOT EXISTS subquery handling via SubLink nodes
- Add unary expression support (NOT operator)
- Fix NULL literal conversion in COALESCE expressions

**Test Updates:**
- Add SQLite case to fmt_test.go with case-insensitive fingerprinting
- Regenerate expected output for select_exists/select_not_exists tests
  (EXISTS now correctly returns bool instead of int64)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang labels Dec 1, 2025
@kyleconroy kyleconroy merged commit 166398d into main Dec 1, 2025
13 checks passed
@kyleconroy kyleconroy deleted the kyle/sqlite-format-tests branch December 1, 2025 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants