AGENT SKILL

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 migrations, transaction boundaries, parameterized queries, adapter error mapping, Scanner and Valuer types, SQLite or server databases, and real-driver integration tests. Use when a Go command stores durable state in SQL, initializes a local database, applies schema changes, or needs safe repository and transaction behavior.

License 许可
MIT
最近更新
2026-11-14
Stars
★ 1.6k
Forks
491

01 前言 Front Matter

name
go-cli-sql-storage
license
MIT
metadata
{ "tags": "go,golang,cli,sql,database,storage", "version": "0.2.0", "category": "Go", "displayName": "Go CLI SQL Storage" }
description
Design, implement, test, and ship SQL-backed persistence for Go CLIs using database/sql, explicit pool ownership, bounded startup checks, embedded migrations, transaction boundaries, parameterized queries, adapter error mapping, Scanner and Valuer types, SQLite or server databases, and real-driver integration tests. Use when a Go command stores durable state in SQL, initializes a local database, applies schema changes, or needs safe repository and transaction behavior.
compatibility
Codex, Claude Code, and other Agent Skills-compatible clients.

02 资源文件 9

03 SKILL.md 正文

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

  1. Choose the database and driver from workload, platform, and distribution needs.
  2. Define domain operations and transaction ownership before repository methods.
  3. Open and configure one long-lived pool at the composition root.
  4. Verify required startup connectivity with a bounded PingContext.
  5. Apply versioned migrations using an explicit serialization policy.
  6. Implement parameterized queries and map driver errors to stable domain errors.
  7. Test consumers with fakes and adapters with the real driver and production schema.
  8. 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.Open as 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.

04 同仓库更多 Skills

hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-review-with-annotations

Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-find-and-synthesize-context

Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-create-or-update-docs

Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-create-or-manage-records

Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-create-or-manage-interactive-html

Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-collaborate-threads

Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.

★ 1.6k