# golang-database

> Claude/Codex skill by [@samber](https://omgskills.com/library/samber/index.md) · 2.8k stars · 38k installs · Updated 2026-08-01

Comprehensive guide for Go database access — parameterized queries, struct scanning, NULLable columns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context propagation, and migration tooling. Use when writing, reviewing, or debugging Golang code that interacts with PostgreSQL, MariaDB, MySQL, or SQLite; for database testing; or for questions about database/sql, sqlx, or pgx. Does NOT generate database schemas or migration SQL.

Tags: agent, agent-skills, ai, antigravity, claude, claude-code, code, codex, coding, copilot, cursor, gemini, gemini-cli-extension, openclaw, opencode, plugin, skills, skillsmp, vibe-coding

## Install

```sh
git clone https://github.com/samber/cc-skills-golang /tmp/cc-skills-golang && ln -s /tmp/cc-skills-golang/skills/golang-database ~/.claude/skills/golang-database
```

## From README

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 Use sqlx or pgx, not ORMs — ORMs hide SQL, generate unpredictable queries, and make debugging harder Queries MUST use parameterized placeholders — NEVER concatenate user input into SQL strings Context MUST be passed to all database operations — use Context method variants (QueryContext, ExecContext, GetContext) sql.ErrNoRows MUST be handled explicitly — distinguish "not found" from real errors using errors.Is Rows MUST be closed after iteration — defer rows.Close() immediately after QueryContext calls 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.

## Links

- HTML page: https://omgskills.com/skills/samber/cc-skills-golang/golang-database/
- GitHub: https://github.com/samber/cc-skills-golang
- Author: [@samber](https://omgskills.com/library/samber/index.md)

## More from this repo

- [golang-google-wire](https://omgskills.com/skills/samber/cc-skills-golang/skills/golang-google-wire/index.md) — Compile-time dependency injection in Golang using google/wire — wire.NewSet, wire.Build, wire.Bind...
   - [@samber](https://omgskills.com/library/samber/index.md) · 3.1k stars
- [golang-gopls](https://omgskills.com/skills/samber/cc-skills-golang/skills/golang-gopls/index.md) — Golang semantic code intelligence via \`gopls\`, the official Go language server — go-to-definition, find references,...
   - [@samber](https://omgskills.com/library/samber/index.md) · 3k stars
- [golang-how-to](https://omgskills.com/skills/samber/cc-skills-golang/skills/golang-how-to/index.md) — Golang skills orchestrator — always active on any Golang coding, review, debug, or setup task.
   - [@samber](https://omgskills.com/library/samber/index.md) · 3k stars
