golang-database
Comprehensive guide for Go database access. Covers parameterized queries, struct scanning, NULLable column handling, error patterns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context propagation, and migration tooling. Use this skill wh
供给资产档案
编程与开发 Agent
代码审查、仓库分析、测试、CI、GitHub、DevOps 与开发工作流 Skill。
场景
Database and SQL
I need my agent to inspect database schemas, write SQL, and explain query results.
适配 Agent
Claude Code + CLI + Codex
适用于 Codex、Claude Code、Cursor、CLI 或自定义 Agent。
安装
就绪
npx skills add yzfly/skills --skill golang-database
维护状态
新鲜
今天有推送
风险
需审查
Dependency or permission surface needs review
GitHub 质量
12
58/100 质量 · 70/100 信任
覆盖标签
审查说明
Dependency or permission surface needs review · Permission surface may require sandboxing
Agent 采用评分卡
一眼查看信任、审计与安装准备度
这些分数综合公开仓库元数据、OpenAgentSkill 审查信号、维护新鲜度与安装准备度。它用于候选筛选,不替代人工审查。
质量
有潜力有用的候选项,但采用前应与替代方案比较。
信任
仅限沙盒有用但信任信号不足或混杂的候选项。在结果闭环证明任务匹配前,请保持在隔离工作区内使用。
审计
需审查对安装准备度、安全元数据、维护情况与采用风险的机器可读审查。
OpenAgentSkill 信任评分 v5
安装前需人工审查
仅在沙盒中运行,并在用于真实工作前比较接近的替代方案。
Stars
12 个 GitHub Stars
仓库活跃度
12 个 Star,2 个 Fork
维护状态
今天有推送
许可证
MIT
安装
npx skills add yzfly/skills --skill golang-database
安装安全性
标准软件包或运行时安装路径
权限范围
shell or command execution, filesystem or document access
Agent 结果
暂未有 Agent 结果数据
文档
README/SKILL.md 上下文充分
风险摘要
生产前审查
- Financial research output is not financial advice; require human review before any live investment decision.
- Low GitHub adoption signal
- Quality score needs review
- Permission surface needs review: shell or command execution, filesystem or document access
安装准备度
安装路径可用
- 安装路径可用
- 仓库证据可用
- 已声明许可证
- 暂无 Agent 验证结果证据
Agent 可读元数据
这个 Skill 的机器可读决策数据。
使用此区块或内嵌 JSON 判断 Agent 是否应安装该 Skill、选择替代方案,或先请求人工审查。
适用任务
- Database and SQL 工作流
- Claude Code 团队
- builders willing to evaluate younger projects
- Understand table relationships
适用 Agent
安装决策
- 命令
- npx skills add yzfly/skills --skill golang-database
- 策略
- 审查
- 人工审查
- 是
信任与风险
- 信任
- 62/100
- 审计
- 74/100
- 风险级别
- 需审查
结果闭环
- 端点
- /api/agent/outcome
- 事件 ID
- resolve
- 结果
- 5
不适用场景
- 需要厂商支持 SLA 的团队
- production agents without a repository review
- Low GitHub adoption signal
- 暂未有 OpenAgentSkill 使用反馈数据
- 高风险权限提示:Shell 或命令执行
替代 Skill
Frontend Design
171.1K Stars
npx skills add anthropics/skills --skill frontend-design
替代 Skill
Taste Skill: Anti-Slop Frontend
79.4K Stars
npx skills add Leonxlnx/taste-skill --skill design-taste-frontend
替代 Skill
Canvas Design
171.1K Stars
npx skills add anthropics/skills --skill canvas-design
替代 Skill
Anthropic Brand Guidelines
171.1K Stars
npx skills add anthropics/skills --skill brand-guidelines
Agent 安全 v2
42/100 · 避免自动安装
Sparse or mixed signals. Useful for discovery, but not for autonomous installation.
Test manually in an isolated workspace and compare against safer alternatives.
高
Shell 或命令执行
Skill 元数据引用了终端、CLI、Shell、子进程或命令执行工作流。
中
网络访问
Skill 可能访问远程页面、API、仓库或外部服务。
中
文件系统访问
Skill 可能读取或写入项目文件、文档、生成产物或本地工作区状态。
中
数据库访问
Skill 可能检查 Schema、查询数据库或处理持久化存储。
- 高风险权限提示:Shell 或命令执行
- Dependency or permission surface needs review
安装目标
在你的 Agent 工作流中安装此 Skill
通过公开安装端点获取命令、安全清单、目标提示词和该 Skill 的规范链接。
OpenAgentSkill CLI
Resolve policy, run the source installer safely, and report a verified install receipt.
$ npx --yes https://github.com/Leon-Drq/openagentskill/releases/download/cli-v0.2.1/openagentskill-0.2.1.tgz install yzfly-golang-databaseAgent 解析计划
让 Agent 在安装前验证匹配度。
Resolve API 返回首选 Skill、替代方案、安全策略、审计说明、安装目标和可直接执行的提示词,无需抓取此页面。
打开 JSON
/api/agent/resolve?task=Use%20golang-database%20for%20an%20agent%20workflow&agent=codex&max_risk=medium
Resolve 文本
/api/agent/resolve?task=Use%20golang-database%20for%20an%20agent%20workflow&agent=codex&max_risk=medium&format=text
安装交接
/api/skills/yzfly-golang-database/install
Agent 应检查
- 从 Resolve API 检查任务匹配与替代方案。
- 检查审计评分、信任评分和安全策略警告。
- 检查 Codex、Claude Code、Cursor 或 CLI 的安装目标兼容性。
复制提示词
Task: Use golang-database in this workspace.
Resolve first: https://www.openagentskill.com/api/agent/resolve?task=Use%20golang-database%20for%20an%20agent%20workflow&agent=codex&max_risk=medium
Review install handoff: https://www.openagentskill.com/api/skills/yzfly-golang-database/install
Install command: npx skills add yzfly/skills --skill golang-database
Before running it, summarize audit warnings, required permissions, and the fallback skill if install is risky.Agent 交接
把安装路径交给 Agent,而不是再给一个目录页。
通过公开安装端点获取命令、安全清单、目标提示词和该 Skill 的规范链接。
安装交接
/api/skills/yzfly-golang-database/install
LLM 文本格式
/api/skills/yzfly-golang-database/install?format=text
寻找替代方案
/api/skills/search?q=golang-database&limit=3
Agent 提示词
Use golang-database for this task. Review https://www.openagentskill.com/api/skills/yzfly-golang-database/install, then install with: npx skills add yzfly/skills --skill golang-databaseRegistry 元数据
用于自动选择 Skill 的 Agent 可读档案。
本页通过 Registry API 提供相同的决策、信任、审计、场景和安装信号,让 Agent 无需抓取界面即可排序。
Agent 决策面板
Needs validation for Database and SQL
在将它加入 Agent 工作流前先人工审查仓库。
栈中角色
需要验证
主要匹配
Database and SQL
信任标签
需要人工审查
安装路径
命令已就绪
适用场景
- Database and SQL 工作流
- Claude Code 团队
- builders willing to evaluate younger projects
证据
- 仓库近期活跃
- 已提供安装命令或 GitHub 仓库
- 58/100 质量档案
先审查
- Low GitHub adoption signal
- 暂未有 OpenAgentSkill 使用反馈数据
实施路径
- 1在沙盒 Agent 中安装它,并端到端完成一次Database and SQL任务。
- 2Compare output quality, latency, and failure behavior against at least one alternative.
- 3Promote it into production only after reviewing repository permissions, license, and maintenance signals.
信任档案
仅限沙盒
有用但信任信号不足或混杂的候选项。在结果闭环证明任务匹配前,请保持在隔离工作区内使用。
GitHub 采用度
修复12 个 GitHub Stars
Star/Fork 活跃度
修复12 个 Star,2 个 Fork; 当前元数据中没有议题活跃度信息
近期维护
通过今天有推送
许可证清晰度
通过MIT
积极信号
- AI 审查已通过
- 安装路径可用
- 仓库证据可用
- 近期维护的仓库
- 安装命令未发现明显高风险模式
- 结果闭环已就绪,但需要首次真实 Agent 运行
安装前审查
- Financial research output is not financial advice; require human review before any live investment decision.
- Low GitHub adoption signal
- Quality score needs review
- Permission surface needs review: shell or command execution, filesystem or document access
- GitHub adoption: 12 GitHub stars
- Stars/forks activity: 12 stars, 2 forks; issue activity unavailable in current metadata
- Dependency/runtime risk: command execution surface, network or browser surface
- Permission surface: shell or command execution, filesystem or document access
- 暂未有真实 Agent 结果报告
- 无人值守安装前需要人工审查
建议操作
仅在沙盒中运行,并在用于真实工作前比较接近的替代方案。
质量档案
有潜力 适用于 Agent 工作流的候选
有用的候选项,但采用前应与替代方案比较。
工作流匹配
在这些场景使用此 Skill
Work with data stores
Database and SQL
I need my agent to inspect database schemas, write SQL, and explain query results.
Build and ship code
Coding agents
I need a coding agent that can understand a repository, edit code, and review pull requests.
Manage repositories
GitHub automation
I need my agent to triage GitHub issues, review pull requests, and summarize repository changes.
工作流匹配
加入完整工作流
Inspect, patch, and verify code
Coding review agent
A workflow for software agents that inspect repositories, review pull requests, generate tests, and turn findings into shippable patches.
Operate and verify web apps
Browser QA agent
A workflow for agents that navigate products, fill forms, take screenshots, and verify real user flows across web applications.
Turn skills into distribution
Content growth agent
A workflow for turning newly indexed skills into SEO briefs, social drafts, comparison pages, and reusable publishing workflows.
替代方案短名单
安装前对比
可能适合该任务的相近 Skill。
Frontend Design
Guidance for distinctive, intentional UI design, typography, visual direction, and non-template-like product interfaces.
Taste Skill: Anti-Slop Frontend
Design and implementation guidance for distinctive landing pages, portfolios, product demos, and purposeful redesigns.
Canvas Design
Create original visual art, posters, PNG assets, and PDF documents through a clear design philosophy.
Anthropic Brand Guidelines
Apply Anthropic official brand colors, typography, and visual standards to appropriate Anthropic-related artifacts.
概览
--- name: golang-database description: "Comprehensive guide for Go database access. Covers parameterized queries, struct scanning, NULLable column handling, error patterns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context propagation, and migration tooling. Use this skill whenever writing, reviewing, or debugging Golang code that interacts with PostgreSQL, MariaDB, MySQL, or SQLite. Also triggers for database testing or any question about database/sql, sqlx, pgx, or SQL queries in Golang. This skill explicitly does NOT generate database schemas or migration SQL." user-invocable: true license: MIT compatibility: Designed for Claude Code or similar AI coding agents, and for projects using Golang. metadata: author: samber version: "1.1.2" openclaw: emoji: "🗄️" homepage: https://github.com/samber/cc-skills-golang requires: bins: - go install: [] allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestion ---
**Persona:** You are a Go backend engineer who writes safe, explicit, and observable database code. You treat SQL as a first-class language — no ORMs, no magic — and you catch data integrity issues at the boundary, not deep in the application.
**Modes:**
- **Write mode** — generating new repository functions, query helpers, or transaction wrappers: follow the skill's sequential instructions; launch a background agent to grep for existing query patterns and naming conventions in the codebase before generating new code. - **Review/debug mode** — auditing or debugging existing database code: use a sub-agent to scan for missing `rows.Close()`, un-parameterized queries, missing context propagation, and absent error checks in parallel with reading the business logic.
> **Community default.** A company skill that explicitly supersedes `samber/cc-skills-golang@golang-database` skill takes precedence.
# Go Database Best Practices
Go's `database/sql` provides a solid foundation for database access. Use `sqlx` or `pgx` on top of it for ergonomics — never an ORM.
When using sqlx or pgx, refer to the library's official documentation and code examples for current API signatures.
## Best Practices Summary
1. **Use sqlx or pgx, not ORMs** — ORMs hide SQL, generate unpredictable queries, and make debugging harder 2. Queries MUST use parameterized placeholders — NEVER concatenate user input into SQL strings 3. Context MUST be passed to all database operations — use `*Context` method variants (`QueryContext`, `ExecContext`, `GetContext`) 4. `sql.ErrNoRows` MUST be handled explicitly — distinguish "not found" from real errors using `errors.Is` 5. Rows MUST be closed after iteration — `defer rows.Close()` immediately after `QueryContext` calls 6. NEVER use `db.Query` for statements that don't return rows — `Query` returns `*Rows` which must be closed; if you forget, the connection leaks back to the pool. Use `db.Exec` instead 7. **Use transactions for multi-statement operations** — wrap related writes in `BeginTxx`/`Commit` 8. **Use `SELECT ... FOR UPDATE`** when reading data you intend to modify — prevents race conditions 9. **Set custom isolation levels** when default READ COMMITTED is insufficient (e.g., serializable for financial operations) 10. **Handle NULLable columns** with pointer fields (`*string`, `*int`) or `sql.NullXxx` types 11. Connection pool MUST be configured — `SetMaxOpenConns`, `SetMaxIdleConns`, `SetConnMaxLifetime`, `SetConnMaxIdleTime` 12. **Use external tools for migrations** — golang-migrate or Flyway, never hand-rolled or AI-generated migration SQL 13. **Batch operations in reasonable sizes** — not row-by-row (too many round trips), not millions at once (locks and memory) 14. **Never create or modify database schemas** — a schema that looks correct on toy data can create hotspots, lock contention, or missing indexes under real production load. Schema design requires understanding of data volumes, access patterns, and production constraints that AI does not have 15. **Avoid hidden SQL features** — do not rely on triggers, views, materialized views, stored procedures, or row-level security in application code
## Library Choice
| Library | Best for | Struct scanning | PostgreSQL-specific | | --- | --- | --- | --- | | `database/sql` | Portability, minimal deps | Manual `Scan` | No | | `sqlx` | Multi-database projects | `StructScan` | No | | `pgx` | PostgreSQL (30-50% faster) | `pgx.RowToStructByName` | Yes (COPY, LISTEN, arrays) | | GORM/ent | **Avoid** | Magic | Abstracted away |
**Why NOT ORMs:**
- Unpredictable query generation — N+1 problems you cannot see in code - Magic hooks and callbacks (BeforeCreate, AfterUpdate) make debugging harder - Schema migrations coupled to application code - Learning the ORM API is harder than learning SQL, and the abstraction leaks
## Parameterized Queries
```go // ✗ VERY BAD — SQL injection vulnerability query := fmt.Sprintf("SELECT * FROM users WHERE email = '%s'", email)
// ✓ Good — parameterized (PostgreSQL) var user User err := db.GetContext(ctx, &user, "SELECT id, name, email FROM users WHERE email = $1", email)
// ✓ Good — parameterized (MySQL) err := db.GetContext(ctx, &user, "SELECT id, name, email FROM users WHERE email = ?", email) ```
### Dynamic IN clauses
```go query, args, err := sqlx.In("SELECT * FROM users WHERE id IN (?)", ids) if err != nil { return fmt.Errorf("building IN clause: %w", err) } query = db.Rebind(query) // adjust placeholders for your driver err = db.SelectContext(ctx, &users, query, args...) ```
### Dynamic column names
Never interpolate column names from user input. Use an allowlist:
```go allowed := map[string]bool{"name": true, "email": true, "created_at": true} if !allowed[sortCol] { return fmt.Errorf("invalid sort column: %s", sortCol) } query := fmt.Sprintf("SELECT id, name, email FROM users ORDER BY %s", sortCol) ```
For more injection prevention patterns, see the `samber/cc-skills-golang@golang-security` skill.
## Struct Scanning and NULLable Columns
Use `db:"column_name"` tags for sqlx, `pgx.CollectRows` with `pgx.RowToStructByName` for pgx. Handle NULLable columns with pointer fields (`*string`, `*time.Time`) — they work cleanly with both scanning and JSON marshaling. See [Scanning Reference](./references/scanning.md) for examples of all approaches.
## Error Handling
```go func GetUser(id string) (*User, error) { var user User
err := db.GetContext(ctx, &user, "SELECT id, name FROM users WHERE id = $1", id) if err != nil { if errors.Is(err, sql.ErrNoRows) { return nil, ErrUserNotFound // translate to domain error } return nil, fmt.Errorf("querying user %s: %w", id, err) }
return &user, nil } ```
or:
```go func GetUser(id string) (u *User, exists bool, err error) { var user User
err := db.GetContext(ctx, &user, "SELECT id, name FROM users WHERE id = $1", id) if err != nil { if errors.Is(err, sql.ErrNoRows) { return nil, false, nil // "no user" is not a technical error, but a domain error } return nil, false, fmt.Errorf("querying user %s: %w", id, err) }
return &user, true, nil } ```
### Always close rows
```go rows, err := db.QueryContext(ctx, "SELECT id, name FROM users") if err != nil { return fmt.Errorf("querying users: %w", err) } defer rows.Close() // prevents connection leaks
for rows.Next() { // ... } if err := rows.Err(); err != nil { // always check after iteration return fmt.Errorf("iterating users: %w", err) } ```
### Common database error patterns
| Error | How to detect | Action | | --- | --- | --- | | Row not found | `errors.Is(err, sql.ErrNoRows)` | Return domain error | | Unique constraint | Check driver-specific error code | Return conflict error | | Connection refused | `err != nil` on `db.PingContext` | Fail fast, log, retry with backoff | | Serialization failure | PostgreSQL error code `40001` | Retry the entire transaction | | Context canceled | `errors.Is(err, context.Canceled)` | Stop processing, propagate |
## Context Propagation
Always use the `*Context` method variants to propagate deadlines and cancellation:
```go // ✗ Bad — no context, query runs until completion even if client disconnects db.Query("SELECT ...")
// ✓ Good — respects context cancellation and timeouts db.QueryContext(ctx, "SELECT ...") ```
For context patterns in depth, see the `samber/cc-skills-golang@golang-context` skill.
## Transactions, Isolation Levels, and Locking
For transaction patterns, isolation levels, `SELECT FOR UPDATE`, and locking variants, see [Transactions](./references/transactions.md).
## Connection Pool
```go db.SetMaxOpenConns(25) // limit total connections db.SetMaxIdleConns(10) // keep warm connections ready db.SetConnMaxLifetime(5 * time.Minute) // recycle stale connections db.SetConnMaxIdleTime(1 * time.Minute) // close idle connections faster ```
For sizing guidance and formulas, see [Database Performance](./references/performance.md).
## Migrations
Use an external migration tool. Schema changes require human review with understanding of data volumes, existing indexes, foreign keys, and production constraints.
Recommended tools:
- [golang-migrate](https://github.com/golang-migrate/migrate) — CLI + Go library, supports all major databases - [Flyway](https://flywaydb.org/) — JVM-based, widely used in enterprise environments - [Atlas](https://atlasgo.io/) — modern, declarative schema management
Migration SQL should be written and reviewed by humans, versioned in source control, and applied through CI/CD pipelines.
## Avoid Hidden SQL Features
Do not rely on triggers, views, materialized views, stored procedures, or row-level security in application code — they create invisible side effects and make debugging impossible. Keep SQL explicit and visible in Go where it can be tested and version-controlled.
## Schema Creation
**This skill does NOT cover schema creation.** AI-generated schemas are often subtly wrong — missing indexes, incorrect column types, bad normalization, or missing constraints. Schema design requires understanding data volumes, access patterns, query profiles, and business constraints. Use dedicated database tooling and human review.
## Deep Dives
- **[Transactions](./references/transactions.md)** — Transaction boundaries, isolation levels, deadlock prevention, `SELECT FOR UPDATE` - **[Testing Database Code](./references/testing.md)** — Mock connections, integration tests with containers, fixtures, schema setup/teardown - **[Database Performance](./references/performance.md)** — Connection pool sizing, batch processing, indexing strategy, query optimization - **[Struct Scanning](./references/scanning.md)** — Struct tags, NULLable column handling, JSON marshaling patterns
## Cross-References
- → See `samber/cc-skills-golang@golang-security` skill for SQL injection prevention patterns - → See `samber/cc-skills-golang@golang-context` skill for context propagation to database operations - → See `samber/cc-skills-golang@golang-error-handling` skill for database error wrapping patterns - → See `samber/cc-skills-golang@golang-testing` skill for database integration test patterns
## References
- [database/sql tutorial](https://go.dev/doc/database/) - [sqlx](https://github.com/jmoiron/sqlx) - [pgx](https://github.com/jackc/pgx) - [golang-migrate](https://github.com/golang-migrate/migrate)
技术详情
- 版本
- 1.0.0
- 许可证
- MIT
- 最近更新
- 2026年8月23日
- 发布时间
- 2026年8月23日
决策摘要
需要验证
仓库近期活跃
Agent 验证证据
Agent 验证证据
来自解析、审查、安装和一次小范围运行后的结果报告。
- 成功率
- —
- 近期失败
- —
- 结果
- 0
- 输出质量
- —
- 失败
- 0
- 不相关
- 0
- 安装次数
- 0
- 风险拦截
- 0
- 需要配置
- 0
- 生产环境
- 0
暂时没有 Agent 结果数据。首次 Agent 执行可以通过 /api/agent/outcome 报告成功、需要设置、风险拦截、失败或不相关。
增长闭环
分享工具包
为 golang-database 准备的场景化草稿,可手动发布到 X。
A practical pick for design or creative work: golang-database: Comprehensive guide for Go database access. Covers parameterized queries, struct scanning, NULLable column handling, error... 12 stars https://www.openagentskill.com/skills/yzfly-golang-database?ref=x
可选:带安装命令的回复
Listing + install path for golang-database: https://www.openagentskill.com/skills/yzfly-golang-database?ref=x Install: npx skills add yzfly/skills --skill golang-database
收录来源
Registry 收录
此列表来自公开来源,维护者认领获批前不会标记为官方。
- 创作者
- yzfly
- 收录方
- OpenAgentSkill 社区索引
归属链接指向公开仓库或创作者主页。创作者可认领列表以更新所有权信号。
认领此 Skill所有者认领
认领此 Skill 页面
这条 Registry 收录 列表归属于 yzfly,但尚未标记为官方。认领后可增加已验证所有者信号,使后续发布、安装和审计更新更值得信赖。
创作者外链工具包
将证据徽章加入你的 README
在开发者评估仓库的位置展示规范页面、当前信任与审计信号,以及真实的 Agent 验证证据。
[](https://www.openagentskill.com/skills/yzfly-golang-database)
[](https://www.openagentskill.com/skills/yzfly-golang-database)
[](https://www.openagentskill.com/skills/yzfly-golang-database/audit)
[](https://www.openagentskill.com/skills/yzfly-golang-database)作者
yzfly
@yzfly
平台适配
健康信号
- GitHub Stars
- 12
- 质量评分
- 32/100
- 最近 GitHub 推送
- 2026年8月23日
- 框架提示
- 未知
- OpenAgentSkill 浏览量
- 0
- 复制安装命令
- 0
- 跳转点击
- 0
社区信号
告诉我们这个 Skill 是否对你的 Agent 工作流有帮助。汇总反馈会持续改善排序。
信任与安全
仅限沙盒
- GitHub 采用度12 个 GitHub Stars修复
- Star/Fork 活跃度12 个 Star,2 个 Fork; 当前元数据中没有议题活跃度信息修复
- 近期维护今天有推送通过
- 许可证清晰度MIT通过
- README/SKILL.md 完整度元数据包含足够的用法与工作流上下文通过
- 依赖与运行时风险command execution surface, network or browser surface检查
相关 Skill
Frontend Design
Guidance for distinctive, intentional UI design, typography, visual direction, and non-template-like product interfaces.
171.1K StarsTaste Skill: Anti-Slop Frontend
Design and implementation guidance for distinctive landing pages, portfolios, product demos, and purposeful redesigns.
79.4K StarsCanvas Design
Create original visual art, posters, PNG assets, and PDF documents through a clear design philosophy.
171.1K StarsAnthropic Brand Guidelines
Apply Anthropic official brand colors, typography, and visual standards to appropriate Anthropic-related artifacts.
171.1K Stars