Commit b83465a
feat(sqlite): Add database analyzer using ncruces/go-sqlite3 (#4199)
* feat(sqlite): Add database analyzer using ncruces/go-sqlite3
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>
* refactor(sqlite): Replace modernc.org/sqlite with ncruces/go-sqlite3
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>
* chore: Run go mod tidy after removing modernc.org/sqlite
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>
* fix(sqltest): Restore SQLite helper functions for ncruces driver
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>
* chore(sqltest): Remove unnecessary wasm build constraint
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>
* chore(cmd): Remove unnecessary wasm build constraint from vet_sqlite.go
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(sqlite): Handle in-memory databases and preserve inferred types
- 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>
* fix(testdata): Update SQLite tests for real database analyzer
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>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b807fe9 commit b83465a
File tree
43 files changed
+508
-164
lines changed- internal
- cmd
- compiler
- endtoend
- testdata
- builtins/sqlite
- go
- queries
- ddl_create_trigger/sqlite
- go
- insert_select_invalid/sqlite
- invalid_group_by_reference/sqlite
- invalid_table_alias/sqlite
- join_left_same_table/sqlite
- go
- limit/sqlite
- go
- quoted_names_complex/sqlite
- select_exists/sqlite
- select_not_exists/sqlite
- go
- sqlc_embed/sqlite
- go
- engine/sqlite/analyzer
- sqltest
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
43 files changed
+508
-164
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
| |||
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
48 | | - | |
49 | | - | |
| 46 | + | |
50 | 47 | | |
51 | 48 | | |
52 | 49 | | |
53 | | - | |
54 | 50 | | |
55 | 51 | | |
56 | 52 | | |
| |||
59 | 55 | | |
60 | 56 | | |
61 | 57 | | |
62 | | - | |
| 58 | + | |
63 | 59 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
67 | 63 | | |
68 | 64 | | |
69 | 65 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 66 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
| |||
41 | 39 | | |
42 | 40 | | |
43 | 41 | | |
44 | | - | |
45 | | - | |
46 | 42 | | |
47 | 43 | | |
48 | 44 | | |
| |||
123 | 119 | | |
124 | 120 | | |
125 | 121 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
130 | 126 | | |
131 | 127 | | |
132 | 128 | | |
| |||
143 | 139 | | |
144 | 140 | | |
145 | 141 | | |
146 | | - | |
147 | | - | |
148 | 142 | | |
149 | 143 | | |
150 | 144 | | |
| |||
177 | 171 | | |
178 | 172 | | |
179 | 173 | | |
180 | | - | |
181 | | - | |
| 174 | + | |
| 175 | + | |
182 | 176 | | |
183 | 177 | | |
184 | 178 | | |
| |||
236 | 230 | | |
237 | 231 | | |
238 | 232 | | |
239 | | - | |
240 | | - | |
| 233 | + | |
| 234 | + | |
241 | 235 | | |
242 | 236 | | |
243 | 237 | | |
244 | 238 | | |
245 | 239 | | |
246 | | - | |
247 | | - | |
248 | 240 | | |
249 | 241 | | |
250 | 242 | | |
251 | 243 | | |
252 | 244 | | |
253 | | - | |
254 | | - | |
| 245 | + | |
| 246 | + | |
255 | 247 | | |
256 | | - | |
257 | | - | |
| 248 | + | |
| 249 | + | |
258 | 250 | | |
259 | 251 | | |
260 | 252 | | |
| |||
267 | 259 | | |
268 | 260 | | |
269 | 261 | | |
270 | | - | |
271 | | - | |
272 | | - | |
| 262 | + | |
| 263 | + | |
273 | 264 | | |
274 | 265 | | |
275 | 266 | | |
276 | 267 | | |
277 | 268 | | |
278 | 269 | | |
279 | 270 | | |
280 | | - | |
281 | | - | |
| 271 | + | |
| 272 | + | |
282 | 273 | | |
283 | 274 | | |
284 | 275 | | |
| |||
288 | 279 | | |
289 | 280 | | |
290 | 281 | | |
291 | | - | |
292 | | - | |
293 | 282 | | |
294 | 283 | | |
295 | 284 | | |
| |||
324 | 313 | | |
325 | 314 | | |
326 | 315 | | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
394 | 407 | | |
395 | 408 | | |
396 | 409 | | |
| |||
517 | 530 | | |
518 | 531 | | |
519 | 532 | | |
520 | | - | |
| 533 | + | |
521 | 534 | | |
522 | 535 | | |
523 | 536 | | |
524 | 537 | | |
525 | 538 | | |
526 | 539 | | |
527 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
528 | 558 | | |
529 | 559 | | |
530 | 560 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
| |||
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
99 | | - | |
100 | | - | |
101 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
102 | 110 | | |
103 | 111 | | |
104 | 112 | | |
| |||
0 commit comments