go-cli-sql-storage
Design, implement, test, and ship SQL-backed persistence for Go CLIs using database/sql, explicit pool ownership, bounded startup checks, embedded m…
它会碰到什么
这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。
技能内容
Go CLI SQL Storage
Treat *sql.DB as a long-lived pool owned by the composition root. Keep SQL,
driver behavior, migrations, and sensitive connection details inside adapters.
Core Workflow
- Choose the database and driver from workload, platform, and distribution needs.
- Define domain operations and transaction ownership before repository methods.
- Open and configure one long-lived pool at the composition root.
- Verify required startup connectivity with a bounded
PingContext. - Apply versioned migrations using an explicit serialization policy.
- Implement parameterized queries and map driver errors to stable domain errors.
- Test consumers with fakes and adapters with the real driver and production schema.
- Build the final artifact and smoke-test database initialization.
Read Next
| Task | Load |
|---|---|
| Design storage for a CLI | guidelines.md, workflows/build-sql-storage.md |
| Add or change migrations | workflows/apply-schema-migrations.md |
| Test an adapter | workflows/test-sql-adapter.md |
| Review pools, transactions, queries, or conversions | references/sql-storage/rules.md |
| Understand driver and pool contracts | references/sql-storage/knowledge.md |
| Build a multi-process SQLite cache | references/sql-storage/sqlite.md |
| Review patterns | references/sql-storage/examples.md |
Guardrails
- Do not treat
sql.Openas a connectivity check. - Do not interpolate untrusted values or identifiers into SQL.
- Do not treat embedded schema text as a migration system.
- Do not expose driver error types as the application contract.
- Do not use a broad repository interface that mirrors an adapter.
- Do not assume an in-memory SQLite database is shared across pooled connections.
Source Notes
Guidance is transformed and paraphrased from Inanc Gumus, *Go by Example:
Programmer's Guide to Idiomatic and Testable Programs* (Manning, 2025),
Chapter 10. Examples are original.
Nullable values, row lifecycle, and pool guidance also incorporates transformed
material from Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning,
2022), Chapter 10.
Book: https://www.manning.com/books/go-by-example
Verify current contracts against https://pkg.go.dev/database/sql,
https://pkg.go.dev/database/sql/driver, and the selected driver's documentation.
For SQLite, also verify https://sqlite.org/wal.html,
https://sqlite.org/lang_transaction.html, and https://sqlite.org/backup.html.
想直接用这个技能?
本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。
它属于哪个仓库
plugins/LVTD-LLC/skills/skills/go-cli-sql-storage/SKILL.md