Skip to content

Commit b83465a

Browse files
kyleconroyclaude
andauthored
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

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

go.mod

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,24 @@ require (
1616
github.com/jackc/pgx/v5 v5.7.6
1717
github.com/jinzhu/inflection v1.0.0
1818
github.com/lib/pq v1.10.9
19+
github.com/ncruces/go-sqlite3 v0.30.2
1920
github.com/pganalyze/pg_query_go/v6 v6.1.0
2021
github.com/pingcap/tidb/pkg/parser v0.0.0-20250324122243-d51e00e5bbf0
2122
github.com/riza-io/grpc-go v0.2.0
2223
github.com/spf13/cobra v1.10.1
2324
github.com/spf13/pflag v1.0.10
24-
github.com/tetratelabs/wazero v1.9.0
25+
github.com/tetratelabs/wazero v1.10.1
2526
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07
2627
github.com/xeipuuv/gojsonschema v1.2.0
27-
golang.org/x/sync v0.17.0
28+
golang.org/x/sync v0.18.0
2829
google.golang.org/grpc v1.76.0
2930
google.golang.org/protobuf v1.36.10
3031
gopkg.in/yaml.v3 v3.0.1
31-
modernc.org/sqlite v1.39.1
3232
)
3333

3434
require (
3535
cel.dev/expr v0.24.0 // indirect
3636
filippo.io/edwards25519 v1.1.0 // indirect
37-
github.com/dustin/go-humanize v1.0.1 // indirect
38-
github.com/google/uuid v1.6.0 // indirect
3937
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4038
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
4139
github.com/jackc/pgconn v1.14.3 // indirect
@@ -45,12 +43,10 @@ require (
4543
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
4644
github.com/jackc/pgtype v1.14.0 // indirect
4745
github.com/jackc/puddle/v2 v2.2.2 // indirect
48-
github.com/mattn/go-isatty v0.0.20 // indirect
49-
github.com/ncruces/go-strftime v0.1.9 // indirect
46+
github.com/ncruces/julianday v1.0.0 // indirect
5047
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect
5148
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
5249
github.com/pingcap/log v1.1.0 // indirect
53-
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
5450
github.com/rogpeppe/go-internal v1.10.0 // indirect
5551
github.com/stoewer/go-strcase v1.2.0 // indirect
5652
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
@@ -59,15 +55,12 @@ require (
5955
go.uber.org/atomic v1.11.0 // indirect
6056
go.uber.org/multierr v1.11.0 // indirect
6157
go.uber.org/zap v1.27.0 // indirect
62-
golang.org/x/crypto v0.40.0 // indirect
58+
golang.org/x/crypto v0.45.0 // indirect
6359
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
64-
golang.org/x/net v0.42.0 // indirect
65-
golang.org/x/sys v0.36.0 // indirect
66-
golang.org/x/text v0.27.0 // indirect
60+
golang.org/x/net v0.47.0 // indirect
61+
golang.org/x/sys v0.38.0 // indirect
62+
golang.org/x/text v0.31.0 // indirect
6763
google.golang.org/genproto/googleapis/api v0.0.0-20250804133106-a7a43d27e69b // indirect
6864
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b // indirect
6965
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
70-
modernc.org/libc v1.66.10 // indirect
71-
modernc.org/mathutil v1.7.1 // indirect
72-
modernc.org/memory v1.11.0 // indirect
7366
)

go.sum

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ github.com/cubicdaiya/gonp v1.0.4/go.mod h1:iWGuP/7+JVTn02OWhRemVbMmG1DOUnmrGTYY
1818
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1919
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2020
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
21-
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
22-
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
2321
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
2422
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
2523
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
@@ -41,8 +39,6 @@ github.com/google/cel-go v0.26.1/go.mod h1:A9O8OU9rdvrK5MQyrqfIxo1a0u4g3sF8KB6PU
4139
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4240
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
4341
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
44-
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
45-
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
4642
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
4743
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4844
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -123,10 +119,10 @@ github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
123119
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
124120
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
125121
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
126-
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
127-
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
128-
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
129-
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
122+
github.com/ncruces/go-sqlite3 v0.30.2 h1:1GVbHAkKAOwjJd3JYl8ldrYROudfZUOah7oXPD7VZbQ=
123+
github.com/ncruces/go-sqlite3 v0.30.2/go.mod h1:AxKu9sRxkludimFocbktlY6LiYSkxiI5gTA8r+os/Nw=
124+
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
125+
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
130126
github.com/pganalyze/pg_query_go/v6 v6.1.0 h1:jG5ZLhcVgL1FAw4C/0VNQaVmX1SUJx71wBGdtTtBvls=
131127
github.com/pganalyze/pg_query_go/v6 v6.1.0/go.mod h1:nvTHIuoud6e1SfrUaFwHqT0i4b5Nr+1rPWVds3B5+50=
132128
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
@@ -143,8 +139,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
143139
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
144140
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
145141
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
146-
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
147-
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
148142
github.com/riza-io/grpc-go v0.2.0 h1:2HxQKFVE7VuYstcJ8zqpN84VnAoJ4dCL6YFhJewNcHQ=
149143
github.com/riza-io/grpc-go v0.2.0/go.mod h1:2bDvR9KkKC3KhtlSHfR3dAXjUMT86kg4UfWFyVGWqi8=
150144
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@@ -177,8 +171,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
177171
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
178172
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
179173
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
180-
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
181-
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
174+
github.com/tetratelabs/wazero v1.10.1 h1:2DugeJf6VVk58KTPszlNfeeN8AhhpwcZqkJj2wwFuH8=
175+
github.com/tetratelabs/wazero v1.10.1/go.mod h1:DRm5twOQ5Gr1AoEdSi0CLjDQF1J9ZAuyqFIjl1KKfQU=
182176
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo=
183177
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07/go.mod h1:Ak17IJ037caFp4jpCw/iQQ7/W74Sqpb1YuKJU6HTKfM=
184178
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4=
@@ -236,25 +230,23 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
236230
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
237231
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
238232
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
239-
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
240-
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
233+
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
234+
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
241235
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
242236
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
243237
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
244238
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
245239
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
246-
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
247-
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
248240
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
249241
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
250242
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
251243
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
252244
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
253-
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
254-
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
245+
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
246+
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
255247
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
256-
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
257-
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
248+
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
249+
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
258250
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
259251
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
260252
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -267,18 +259,17 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
267259
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
268260
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
269261
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
270-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
271-
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
272-
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
262+
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
263+
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
273264
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
274265
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
275266
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
276267
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
277268
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
278269
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
279270
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
280-
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
281-
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
271+
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
272+
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
282273
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
283274
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
284275
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
@@ -288,8 +279,6 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn
288279
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
289280
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
290281
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
291-
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
292-
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
293282
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
294283
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
295284
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -324,29 +313,3 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
324313
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
325314
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
326315
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
327-
modernc.org/cc/v4 v4.26.5 h1:xM3bX7Mve6G8K8b+T11ReenJOT+BmVqQj0FY5T4+5Y4=
328-
modernc.org/cc/v4 v4.26.5/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
329-
modernc.org/ccgo/v4 v4.28.1 h1:wPKYn5EC/mYTqBO373jKjvX2n+3+aK7+sICCv4Fjy1A=
330-
modernc.org/ccgo/v4 v4.28.1/go.mod h1:uD+4RnfrVgE6ec9NGguUNdhqzNIeeomeXf6CL0GTE5Q=
331-
modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA=
332-
modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
333-
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
334-
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
335-
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
336-
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
337-
modernc.org/libc v1.66.10 h1:yZkb3YeLx4oynyR+iUsXsybsX4Ubx7MQlSYEw4yj59A=
338-
modernc.org/libc v1.66.10/go.mod h1:8vGSEwvoUoltr4dlywvHqjtAqHBaw0j1jI7iFBTAr2I=
339-
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
340-
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
341-
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
342-
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
343-
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
344-
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
345-
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
346-
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
347-
modernc.org/sqlite v1.39.1 h1:H+/wGFzuSCIEVCvXYVHX5RQglwhMOvtHSv+VtidL2r4=
348-
modernc.org/sqlite v1.39.1/go.mod h1:9fjQZ0mB1LLP0GYrp39oOJXx/I2sxEnZtzCmEQIKvGE=
349-
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
350-
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
351-
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
352-
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=

internal/cmd/vet.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,19 @@ type checker struct {
391391
Replacer *shfmt.Replacer
392392
}
393393

394+
// isInMemorySQLite checks if a SQLite URI refers to an in-memory database
395+
func isInMemorySQLite(uri string) bool {
396+
if uri == ":memory:" || uri == "" {
397+
return true
398+
}
399+
// Check for file URI with mode=memory parameter
400+
// e.g., "file:test?mode=memory&cache=shared"
401+
if strings.Contains(uri, "mode=memory") {
402+
return true
403+
}
404+
return false
405+
}
406+
394407
func (c *checker) fetchDatabaseUri(ctx context.Context, s config.SQL) (string, func() error, error) {
395408
cleanup := func() error {
396409
return nil
@@ -517,14 +530,31 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
517530
prep = &dbPreparer{db}
518531
expl = &mysqlExplainer{db}
519532
case config.EngineSQLite:
520-
db, err := sql.Open("sqlite", dburl)
533+
db, err := sql.Open("sqlite3", dburl)
521534
if err != nil {
522535
return fmt.Errorf("database: connection error: %s", err)
523536
}
524537
if err := db.PingContext(ctx); err != nil {
525538
return fmt.Errorf("database: connection error: %s", err)
526539
}
527540
defer db.Close()
541+
// For in-memory SQLite databases, apply migrations
542+
if isInMemorySQLite(dburl) {
543+
files, err := sqlpath.Glob(s.Schema)
544+
if err != nil {
545+
return fmt.Errorf("schema: %w", err)
546+
}
547+
for _, schema := range files {
548+
contents, err := os.ReadFile(schema)
549+
if err != nil {
550+
return fmt.Errorf("read schema file: %w", err)
551+
}
552+
ddl := migrations.RemoveRollbackStatements(string(contents))
553+
if _, err := db.ExecContext(ctx, ddl); err != nil {
554+
return fmt.Errorf("apply schema %s: %w", schema, err)
555+
}
556+
}
557+
}
528558
prep = &dbPreparer{db}
529559
// SQLite really doesn't want us to depend on the output of EXPLAIN
530560
// QUERY PLAN: https://www.sqlite.org/eqp.html

internal/cmd/vet_modernc.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

internal/cmd/vet_sqlite.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package cmd
2+
3+
import (
4+
_ "github.com/ncruces/go-sqlite3/driver"
5+
_ "github.com/ncruces/go-sqlite3/embed"
6+
)

internal/compiler/analyze.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
7979
}
8080
if len(prev.Columns) == len(cols) {
8181
for i := range prev.Columns {
82-
prev.Columns[i].DataType = cols[i].DataType
83-
prev.Columns[i].IsArray = cols[i].IsArray
84-
prev.Columns[i].ArrayDims = cols[i].ArrayDims
82+
// Only override column types if the analyzer provides a specific type
83+
// (not "any"), since the catalog-based inference may have better info
84+
if cols[i].DataType != "any" {
85+
prev.Columns[i].DataType = cols[i].DataType
86+
prev.Columns[i].IsArray = cols[i].IsArray
87+
prev.Columns[i].ArrayDims = cols[i].ArrayDims
88+
}
8589
}
8690
} else {
8791
embedding := false
@@ -96,9 +100,13 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
96100
}
97101
if len(prev.Parameters) == len(params) {
98102
for i := range prev.Parameters {
99-
prev.Parameters[i].Column.DataType = params[i].Column.DataType
100-
prev.Parameters[i].Column.IsArray = params[i].Column.IsArray
101-
prev.Parameters[i].Column.ArrayDims = params[i].Column.ArrayDims
103+
// Only override parameter types if the analyzer provides a specific type
104+
// (not "any"), since the catalog-based inference may have better info
105+
if params[i].Column.DataType != "any" {
106+
prev.Parameters[i].Column.DataType = params[i].Column.DataType
107+
prev.Parameters[i].Column.IsArray = params[i].Column.IsArray
108+
prev.Parameters[i].Column.ArrayDims = params[i].Column.ArrayDims
109+
}
102110
}
103111
} else {
104112
prev.Parameters = params

0 commit comments

Comments
 (0)