Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

Add a SQLite database analyzer that uses the ncruces/go-sqlite3 library,
which is a pure Go SQLite implementation using WebAssembly (no CGO required).

The analyzer provides column and parameter type information by:

  • Connecting to a SQLite database (in-memory for managed databases)
  • Preparing SQL statements to extract metadata
  • Returning column names, types, and table information
  • Returning parameter information

Changes:

  • Add internal/engine/sqlite/analyzer/analyze.go with the Analyzer implementation
  • Add internal/engine/sqlite/analyzer/analyze_test.go with tests
  • Wire the analyzer into internal/compiler/engine.go for SQLite engine
  • Update internal/endtoend/endtoend_test.go to enable managed databases for SQLite
  • Add github.com/ncruces/go-sqlite3 dependency

Co-Authored-By: Claude noreply@anthropic.com

Add a SQLite database analyzer that uses the ncruces/go-sqlite3 library,
which is a pure Go SQLite implementation using WebAssembly (no CGO required).

The analyzer provides column and parameter type information by:
- Connecting to a SQLite database (in-memory for managed databases)
- Preparing SQL statements to extract metadata
- Returning column names, types, and table information
- Returning parameter information

Changes:
- Add internal/engine/sqlite/analyzer/analyze.go with the Analyzer implementation
- Add internal/engine/sqlite/analyzer/analyze_test.go with tests
- Wire the analyzer into internal/compiler/engine.go for SQLite engine
- Update internal/endtoend/endtoend_test.go to enable managed databases for SQLite
- Add github.com/ncruces/go-sqlite3 dependency

Co-Authored-By: Claude <noreply@anthropic.com>
Replace the modernc.org/sqlite driver with ncruces/go-sqlite3 driver
throughout the codebase. This provides a consistent SQLite implementation
using a single library (ncruces/go-sqlite3) which is pure Go and uses
WebAssembly, requiring no CGO.

Changes:
- Replace modernc.org/sqlite imports with ncruces/go-sqlite3/driver
- Rename vet_modernc.go to vet_sqlite.go
- Rename sqlite_modernc.go to sqlite.go
- Remove modernc.org/sqlite and its dependencies from go.mod
- Make github.com/ncruces/go-sqlite3 a direct dependency

Co-Authored-By: Claude <noreply@anthropic.com>
Clean up go.mod and go.sum after replacing modernc.org/sqlite with
ncruces/go-sqlite3. Removes unused indirect dependencies.

Co-Authored-By: Claude <noreply@anthropic.com>
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang labels Nov 29, 2025
kyleconroy and others added 5 commits November 29, 2025 12:05
The previous refactor accidentally removed the SQLite and CreateSQLiteDatabase
functions from sqltest/sqlite.go, breaking example tests. This restores the
functions while using the correct "sqlite3" driver name for ncruces/go-sqlite3.

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

Co-Authored-By: Claude <noreply@anthropic.com>
The original sqlite.go on main had no build constraint. The ncruces/go-sqlite3
driver works differently from modernc.org/sqlite (it uses embedded WASM
internally), so the !wasm constraint is not needed for test code.

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

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Apply migrations for in-memory SQLite databases in both the analyzer
  and vet command, since they start empty and need schema setup
- Preserve catalog-inferred column/parameter types when the database
  analyzer returns "any" (SQLite doesn't provide type info for parameters)
- Change driver name from "sqlite" to "sqlite3" for ncruces/go-sqlite3

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

Co-Authored-By: Claude <noreply@anthropic.com>
The SQLite database analyzer now validates queries against real SQLite,
revealing several issues in test files:

- builtins: Remove sqlite_offset (not available in standard SQLite)
- ddl_create_trigger: Add missing tables referenced by trigger
- insert_select_invalid: Separate schema from query, update error message
- invalid_group_by_reference: Separate schema from query, update error message
- invalid_table_alias: Fix INT to INTEGER, separate schema, update error
- join_left_same_table: Fix authors.parent_id to a.parent_id (use alias)
- limit: Remove UPDATE/DELETE LIMIT (requires special compile option)
- quoted_names_complex: Fix UPDATE referencing renamed table
- select_exists: Change INT to INTEGER for AUTOINCREMENT
- select_not_exists: Fix whitespace, detect parameter
- sqlc_embed: Use :memory: for ATTACH, fix u.users.id to u.id

Tests with different error messages in base vs managed-db contexts now
have exec.json files limiting them to managed-db context only.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@kyleconroy kyleconroy merged commit b83465a into main Nov 29, 2025
13 checks passed
@kyleconroy kyleconroy deleted the claude/add-sqlite-analyzer-01DeQ9Y85DroTibtAdBZRNHw branch November 29, 2025 22:19
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.

3 participants