Provides Go database patterns including connection management, transactions, migrations, query builders, and ORM usage (sqlc, GORM, ent). Useful when working with database access, SQL queries, connection pools, or repository patterns in Go services.
Ships in go-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
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-databasetakes 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.
Configure the pool explicitly — the default is unbounded connections:
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 |
*Context variants
(QueryContext, QueryRowContext, ExecContext) so queries respect
cancellation and timeouts.defer rows.Close() immediately after the error check, and check
rows.Err() after the iteration loop.sql.ErrNoRows explicitly with errors.Is, mapping it to
a domain error like ErrUserNotFound.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.
Use a helper that guarantees rollback on error:
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:
sql.TxOptions{Isolation: sql.LevelSerializable}.
SELECT ... FOR UPDATE; job
queues claim rows with FOR UPDATE SKIP LOCKED; lock rows in a
consistent order to avoid deadlocks.version column in the
WHERE, and zero rows affected means conflict.40001 (serialization failure) and 40P01 (deadlock) are retryable:
retry the whole transaction function with jittered backoff and a cap.
The function must have no side effects outside the transaction.23505 unique →
ErrEmailTaken → 409). Let the database enforce uniqueness; check-then-
insert races.Code: references/locking-and-retries.md.
goose, golang-migrate, atlas), one
migration per change, forward-only in production, with down SQL, run
as a separate step — not at server startup.Implementations and examples: references/tooling.md.
sql.NullString/sql.NullInt64 or pointer
fields (*string, nil = SQL NULL). Scanning NULL into a plain string
errors at runtime.WHERE id = ANY($1)).return between Query and
defer rows.Close() leaks a connection from the pool — and so does
db.Query for a statement that returns no rows; use ExecContext.Worked examples of each pitfall: references/query-patterns.md.
CopyFrom, or multi-row INSERT in batches of a few
hundred rows — never one round trip per row.WHERE (created_at, id) < ($1, $2)), not
OFFSET, which scans skipped rows and shifts under inserts.db.Stats(): a rising WaitCount means the pool, or something
holding connections, is the bottleneck.sql.Null[T] (Go 1.22+) replaces the per-type NullString family.Examples: references/performance.md.
Fake the consumer-side repository interface for service logic; test SQL
against a real database in a container (testcontainers, behind
//go:build integration), running the production migrations. Isolate
tests with a transaction per test, a template database, or truncation.
Examples: references/testing.md.
MaxOpenConns, MaxIdleConns, lifetimes)QueryContext results have defer rows.Close() immediately after error checkrows.Err() checked after row iteration loopsql.ErrNoRows handled explicitly with errors.Is*Context variants)sql.NullString / sql.NullInt64 or pointer typesOFFSET pagination on large tables; bulk writes batchedWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Go, SQL, PostgreSQL, Docker
/go-agent-skills:go-databasefrom go-agent-skills
npx claudepluginhub eduardo-sl/go-agent-skills --plugin go-agent-skills35 skills in this plugin
/git-commitStructured git commit messages following Conventional Commits format for Go projects. Generates well-scoped, atomic commits with clear descriptions. Use when committing changes, writing commit messages, preparing PRs, or reviewing commit history quality. Trigger examples: "commit these changes", "create commit", "commit message", "prepare PR", "squash commits". Not for: code review (go-code-review), changelog generation.
/go-api-designHTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and graceful shutdown. Use when designing APIs, writing HTTP handlers, implementing middleware, or structuring REST endpoints. Trigger examples: "design API", "REST endpoints", "HTTP handler", "middleware pattern", "graceful shutdown", "API versioning". Not for: gRPC services (go-grpc), spec-first OpenAPI work (go-openapi), general architecture (go-architecture-review), concurrency in handlers (go-concurrency-review).
/go-architecture-reviewReview Go project architecture: package structure, dependency direction, layering, separation of concerns, domain modeling, and module boundaries. Use when reviewing architecture, designing package layout, evaluating dependency graphs, or refactoring monoliths into modules. Trigger examples: "review architecture", "package structure", "project layout", "dependency direction", "clean architecture Go", "module boundaries". Not for: code-level style (go-coding-standards), endpoint design (go-api-design).
/go-binary-sizeReduce the size of compiled Go binaries and container images: linker flags, inlining budget, CGO and build tags, embedded assets, dependency weight, and measuring what actually costs bytes. Use when a binary or image is too large, when shrinking a CLI for distribution, or when auditing what a dependency adds to the build. Trigger examples: "binary is too big", "shrink the binary", "reduce image size", "strip symbols", "what is making my binary large", "ldflags -s -w". Not for: runtime speed and allocations (go-performance-review), CI setup (go-ci), release pipelines and signing (go-build-release), dependency CVEs (go-dependency-audit).
/go-build-releaseBuild and release Go binaries that are reproducible and verifiable: version stamping, -trimpath builds, cross-compilation, GoReleaser, checksums, SBOMs, cosign signing, build provenance attestations, and container images with ko or a multi-stage Dockerfile. Use when: "release a Go binary", "set up GoReleaser", "cross-compile", "reproducible build", "sign the release", "generate an SBOM", "build provenance", "publish a container image", "version command shows (devel)". Not for: test and lint pipelines (go-ci), shrinking the binary or image (go-binary-size), auditing dependencies (go-dependency-audit).
/go-ciContinuous integration for Go projects: GitHub Actions pipelines, caching, golangci-lint setup, test/coverage gates, vulnerability scanning, SAST (CodeQL, gosec), Dependabot, action pinning, build matrices, Makefile targets. Use when: "set up CI", "GitHub Actions for Go", "add lint to the pipeline", "CI is slow", "coverage gate", "build matrix", "write a Makefile", "run govulncheck in CI". Not for: commit conventions (git-commit), choosing or auditing dependencies (go-dependency-audit), writing the tests themselves (go-test-quality), releases and signing (go-build-release).
Other plugins' skills for the same job