CodeSampleX

示例

gorm.io/gorm 1.31.2: Run GORM on SQLite with CGO_ENABLED=0, past go-sqlite3's runtime stub error

已验证示例 — golang gorm.io/gorm 1.31.2: Run GORM on SQLite with CGO_ENABLED=0, past go-sqlite3's runtime stub error. contract 在 go 1.26 · linux alpine/x64 …

sha256:c3632f2f8dc28bb7ef59c80bcd728225b10ed65370fcd4c71af75032848b2f02

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
2
声明的环境 go 1.26 linux · musl x64 go 1.26 go go

验证运行环境

环境 契约 阶段 运行日期
go 1.26 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-14
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-18

案例

HOW
目标
Run GORM on SQLite with CGO_ENABLED=0, past go-sqlite3's runtime stub error
符号
  • sqlite.Open
  • gorm.Open
  • gorm.DeletedAt
  • gorm.ErrRecordNotFound
  • gorm.ErrDuplicatedKey
  • gorm.Config.TranslateError
  • sql.Open
  • sql.Drivers
  • DB.Ping
  • DB.AutoMigrate
  • DB.Updates
  • DB.Update
  • DB.Select
  • DB.First
  • DB.Find
  • DB.Unscoped
  • DB.Create
环境
go 1.26
创建时间
2026-08-14T13:23:54Z

契约

  1. assert the build has cgo off and that there is no C compiler on PATH, so rebuilding with CGO_ENABLED=1 has nothing to invoke
  2. assert gorm.io/driver/sqlite still compiles and links with cgo off, since the contract binary imports it, and that its stub registers the database/sql driver name sqlite3 alongside the pure-Go engine's sqlite
  3. assert opening that cgo driver fails only at connection time, with go-sqlite3's Binary was compiled with CGO_ENABLED=0 stub message
  4. assert sql.Open on sqlite3 returns no error at all, because it does not connect, and that Ping is where the stub surfaces
  5. assert the linked pure-Go engine reports SQLite 3.53.3, so the forced modernc.org/sqlite pin cannot drift back to what minimal version selection would pick
  6. assert AutoMigrate creates the table and its deleted_at column, that running it again on an unchanged model is a no-op rather than an error, and that Create writes the auto-increment key back into the struct
  7. assert Updates with a struct writes the non-zero field and silently omits false and 0, returning no error and RowsAffected 1
  8. assert Updates with a map writes those same zero values, since a map has no zero value to be confused by
  9. assert Select names the columns that force a struct's zero values through
  10. assert Update with an explicit value writes a literal zero
  11. assert First on a missing row returns gorm.ErrRecordNotFound while Find returns a nil error with RowsAffected 0
  12. assert gorm.DeletedAt makes Delete an UPDATE: Find and First skip the row, Unscoped finds it with DeletedAt.Valid set, and a raw count shows the row still in the table
  13. assert reusing the primary key of a soft-deleted row fails with SQLite's own UNIQUE constraint failed: users.id message, which does not match gorm.ErrDuplicatedKey by default
  14. assert TranslateError makes that same conflict match gorm.ErrDuplicatedKey and replaces the driver error, so the constraint message is gone
  15. assert two connections to :memory: are two separate databases, so the migrated table is missing on the second one unless the pool is pinned to a single connection

文件

  • csx.json
  • go.mod
  • go.sum
  • src/cgo_off.go
  • src/cgo_on.go
  • src/store.go
  • test/main.go

下载源代码构件 (tar.gz)

原始种子者

anonymous