refactor(db)!: replace SQLite Driver with glebarez/sqlite to avoid CGO#2211
refactor(db)!: replace SQLite Driver with glebarez/sqlite to avoid CGO#2211
Conversation
There was a problem hiding this comment.
Pull request overview
This PR switches the project’s SQLite GORM dialect from the CGO-based gorm.io/driver/sqlite (mattn/go-sqlite3) to the pure-Go github.com/glebarez/sqlite (modernc.org/sqlite) to enable CGO_ENABLED=0 builds.
Changes:
- Updated DB bootstrap code to open SQLite connections via
github.com/glebarez/sqlite. - Updated Go module dependencies, including adding
github.com/glebarez/sqliteand bumpinggorm.io/gormtov1.30.0. - Refreshed dependency hashes in
go.sum.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/bootstrap/db.go | Switches the SQLite dialect import/usage to github.com/glebarez/sqlite. |
| go.mod | Adds github.com/glebarez/sqlite, upgrades GORM, and adjusts indirect deps (but still retains CGO SQLite deps). |
| go.sum | Updates module sums to reflect the dependency graph changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@PIKACHUIM I've opened a new pull request, #2213, to work on those changes. Once the pull request is ready, I'll request review from you. |
* Initial plan * fix: address review comments - fix import order, update test, remove CGO sqlite deps Co-authored-by: PIKACHUIM <40362270+PIKACHUIM@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PIKACHUIM <40362270+PIKACHUIM@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description / 描述
将 SQLite 数据库驱动从基于 CGO 的
gorm.io/driver/sqlite(底层依赖mattn/go-sqlite3)替换为纯 Go 实现的github.com/glebarez/sqlite(底层依赖modernc.org/sqlite),彻底消除对 CGO 的依赖,实现真正的纯 Go 跨平台编译。主要变更:
internal/bootstrap/db.go:将 SQLite 驱动导入从gorm.io/driver/sqlite替换为github.com/glebarez/sqlitego.mod:新增github.com/glebarez/sqlite v1.11.0,移除github.com/mattn/go-sqlite3(CGO 依赖),同步升级gorm.io/gorm v1.25.11 → v1.30.0go.sum:更新依赖哈希Motivation and Context / 背景
原有的
gorm.io/driver/sqlite驱动底层依赖mattn/go-sqlite3,该库需要通过 CGO 编译 C 代码,导致:CGO_ENABLED=0进行纯 Go 静态编译github.com/glebarez/sqlite是gorm.io/driver/sqlite的纯 Go 替代品,底层使用modernc.org/sqlite(SQLite 官方 C 代码通过工具自动转译为 Go 代码),与 GORM 完全兼容,无需任何 CGO 即可完成编译。How Has This Been Tested? / 测试
CGO_ENABLED=0 go build验证纯 Go 编译成功sqlite3)验证数据库连接正常--dev)下内存数据库(file::memory:?cache=shared)正常工作_journal=WAL&_vacuum=incremental)下数据库读写正常Checklist / 检查清单
我已阅读 CONTRIBUTING 文档。
go fmtor prettier.我已使用
go fmt或 prettier 格式化提交的代码。我已为此 PR 添加了适当的标签(建议添加
enhancement、dependencies标签)。我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
我已相应更新了相关仓库(若适用)。