go-database
Database patterns for Go services: database/sql, connection management, transactions, migrations, query builders, and ORM usage (sqlc, GORM, ent).
Skill by eduardo-sl
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/eduardo-sl-go-database
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, data, security
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/go-database
Tools it pre-approves 7
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
ReadEditWriteGlobGrepBash(go:*)Bash(gofmt:*)
What's inside
- Skill name
go-database- Description
- Database patterns for Go services: database/sql, connection management, transactions, migrations, query builders, and ORM usage (sqlc, GORM, ent). Use when: "database access", "SQL query", "connection pool", "transactions", "database migration", "sqlc", "GORM", "ent", "prepared statement", "repository pattern". Not for: in-memory structures (go-data-structures), SQL security (go-security-audit), query profiling (go-performance-review).
- License
- MIT
- Compatibility
- Designed for Claude Code or similar AI coding agents working on Go projects. Requires the Go toolchain. sqlc, golang-migrate and Docker are optional.
- Allowed tools
- Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(gofmt:*)
- Metadata
- author: eduardo-sl · version: 1.5.1
- Instructions
- 199 lines in SKILL.md · view on GitHub
Before installing
- Pre-approves some shell commands
Files (6)
- SKILL.md
- locking-and-retries.md · references/
- performance.md · references/
- query-patterns.md · references/
- testing.md · references/
- tooling.md · references/
SKILL.md (first lines)
# Go Database Patterns
Database access is where most Go services spend their complexity budget.
Get connection management, transactions, and query patterns right.
> Community default. A project skill or agent-config rule that explicitly
> supersedes `go-database` takes precedence over this one.
Detailed reference material, loaded on demand:
- `references/query-patterns.md` — full query/scan/rows patterns, null
handling, N+1 avoidance, connection-leak examples.
- `references/tooling.md` — repository pattern implementation, sqlc
annotated queries, migration tooling and rules.
- `references/locking-and-retries.md` — `FOR UPDATE`/`SKIP LOCKED`,
optimistic versioning, retrying `40001`/`40P01`, constraint errors.
- `references/performance.md` — COPY and batched inserts, keyset
pagination, pool statistics, `sql.Null[T]`.
- `references/testing.md` — choosing fakes vs a real database,
testcontainers setup, isolation strategies.
Read a reference file only when the summary below is not enough.
## 1. Connection Management
Configure the pool explicitly — the default is unbounded connections:
```go
func OpenDB(dsn string) (*sql.DB, error) {
db, err := sql.Open("postgres", dsn)
if err != nil {
return nil, fmt.Errorf("open db: %w", err)
}
db.SetMaxOpenConns(25)
db.SetMaxIdleConns(10)
db.SetConnMaxLifetime(5 * time.Minute)
db.SetConnMaxIdleTime(1 * time.Minute)
if err := db.PingContext(context.Background()); err != nil {
return nil, fmt.Errorf("ping db: %w", err)
}
return db, nil
}
```
| Setting | Guideline |
|---|---|
| `MaxOpenConns` | Match your DB's max connections / number of app instances |
| `MaxIdleConns` | 40-50% of MaxOpenConns |
| `ConnMaxLifetime` | 5-10 minutes (prevents stale connections behind load balancers) |
| `ConnMaxIdleTime` | 1-2 minutes |
## 2. Query Rules
1. **Parameterized queries only** — string concatenation into SQL is an
injection vulnerability, no exceptions.
2. **Always pass context** — use the `*Context` variants
(`QueryContext`, `QueryRowContext`, `ExecContext`) so queries respect
cancellation and timeouts.
3. **`defer rows.Close()`** immediately after the error check, and check
`rows.Err()` after the iteration loop.
4. **Handle `sql.ErrNoRows` explicitly** with `errors.Is`, mapping it to
a domain error like `ErrUserNotFound`.
```go
var user User
err := db.QueryRowContext(ctx,
"SELECT id, name, email FROM users WHERE id = $1", id,
).Scan(&user.ID, &user.Name, &user.Email)
if errors.Is(err, sql.ErrNoRows) {
return nil, ErrUserNotFound
}
if err != nil {
return nil, fmt.Errorf("get user %s: %w", id, err)
}
```
Multi-row iteration patterns: `references/query-patterns.md`.
## 3. Transactions
Use a helper that guarantees rollback on error:
```go
func WithTx(ctx context.Context, db *sql.DB, fn func(tx *sql.Tx) error) (err error) {
tx, err := db.BeginTx(ctx, nil)
if err != nil {
return fmt.Errorf("begin tx: %w", err)
}
defer func() {
if p := recover(); p != nil {
_ = tx.Rollback() // release the connection, then keep panicking
panic(p)
}
if err != nil {
if rbErr := tx.Rollback(); rbErr != nil && !errors.Is(rbErr, sql.ErrTxDone) {
err = errors.Join(err, fmt.Errorf("rollback: %w", rbErr))
}
}
}()
if err := fn(tx); err != nil {
return err
}
if err := tx.Commit(); err != nil {
return fmt.Errorf("commit tx: %w", err)
}
return nil
}
```
The deferred rollback covers a panic inside `fn`, which would otherwise
leave the transaction open and its connection out of the pool until the
context ends. `errors.Join` keeps both errors inspectable.
Set isolation explicitly for critical operations:From eduardo-sl/go-agent-skills, MIT.
More from eduardo-sl/go-agent-skills
- 0.676score
go-cli
eduardo-sl
Build command-line tools in Go: flag handling, subcommands, stdin/stdout discipline, exit codes, signal handling, and when Cobra/Viper earn their weight over…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-modernize
eduardo-sl
Modernize Go code to use current language features and standard library additions, Go 1.21 through 1.27: generics and generic methods, log/slog, errors.Join…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-graphql
eduardo-sl
Build GraphQL servers in Go with gqlgen: schema-first generation, resolver structure, the N+1 problem and dataloaders, complexity and depth limits, error…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-grpc
eduardo-sl
gRPC services in Go beyond the basics: proto design, status codes and error details, interceptors, deadlines, streaming, health checks, and graceful shutdown.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-interface-design
eduardo-sl
Go interface design patterns: implicit interfaces, consumer-side definition, interface compliance verification, composition, the…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-api-design
eduardo-sl
HTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-coding-standards
eduardo-sl
Go coding standards and style conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-context
eduardo-sl
Correct usage of context.Context in Go: propagation, cancellation, timeouts, deadlines, values, and common anti-patterns.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-data-structures
eduardo-sl
Correct use of Go's built-in data structures: slices (nil vs empty, append semantics, aliasing, preallocation), maps (comma-ok, sets, iteration order)…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-documentation
eduardo-sl
Go documentation conventions: godoc comments, package docs, testable Example functions, deprecation notices, doc links, and project docs (README, CHANGELOG…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-error-handling
eduardo-sl
Go error handling patterns, wrapping, sentinel errors, custom error types, and the errors package.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-naming
eduardo-sl
Go naming conventions for packages, files, types, functions, methods, receivers, variables, constants, errors, acronyms and tests, grounded in Effective Go…
SkillAFreshness: A★ 82Claude Code +9
Signals
- Stars
- 82
- Forks
- 10
- Open issues
- 0
- Last commit (this folder)
- Oct 14, 2026 (14 days ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.5.1
- License
- MIT
- Repository
- github.com/eduardo-sl/go-agent-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from eduardo-sl
- 0.676score
go-cli
eduardo-sl
Build command-line tools in Go: flag handling, subcommands, stdin/stdout discipline, exit codes, signal handling, and when Cobra/Viper earn their weight over…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-api-design
eduardo-sl
HTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-graphql
eduardo-sl
Build GraphQL servers in Go with gqlgen: schema-first generation, resolver structure, the N+1 problem and dataloaders, complexity and depth limits, error…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-grpc
eduardo-sl
gRPC services in Go beyond the basics: proto design, status codes and error details, interceptors, deadlines, streaming, health checks, and graceful shutdown.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-interface-design
eduardo-sl
Go interface design patterns: implicit interfaces, consumer-side definition, interface compliance verification, composition, the…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-coding-standards
eduardo-sl
Go coding standards and style conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms.
SkillAFreshness: A★ 82Claude Code +9
Cite this page
go-database skill. Agent Mart. https://agentmart.dev/skills/eduardo-sl-go-database (last updated 2026-10-24)