database-patterns

database-patterns is a skill for Claude Code, Codex from daibang123a/golang-agent-skills. It costs 87 tokens per session (2,589 once invoked), scanned A, original, MIT.

A guide to connecting Go programs to databases and working with stored data. It covers database/sql, SQLX, GORM, connection pools, transactions, schema migrations, and tests.

In plain words
What is it for?
Use it when setting up database connections, writing SQL queries, building repository layers, adding transactions or migrations, and testing database code in Go.
Why use it?
It helps avoid common database problems such as poorly managed connections, missing cleanup, weak error handling, and untested queries.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument.

Good fit Use it when setting up database connections, writing SQL queries, building repository layers, adding transactions or migrations, and testing database code in Go.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/daibang123a/golang-agent-skills/database-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add daibang123a/golang-agent-skills --skill database-patterns
Clone the repo
git clone --depth 1 https://github.com/daibang123a/golang-agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for database-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/daibang123a/golang-agent-skills/database-patterns/github.svg)](https://agentmods.dev/skills/daibang123a/golang-agent-skills/database-patterns)
Your own site
<a href="https://agentmods.dev/skills/daibang123a/golang-agent-skills/database-patterns"><img src="https://agentmods.dev/badge/skills/daibang123a/golang-agent-skills/database-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for database-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/daibang123a/golang-agent-skills/database-patterns"><img src="https://agentmods.dev/badge/skills/daibang123a/golang-agent-skills/database-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 87 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,589 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00087 $0.02589
Opus 5 $0.00044 $0.01295
Sonnet 5 $0.00017 $0.00518
Haiku 4.5 $0.00009 $0.00259

Measured 9d ago against content hash 541e3a81f1c2, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

database-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/migration-check.sh), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/database-patterns/SKILL.md · 304 lines

How it starts

The opening of the file, as written. The whole thing — 304 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Go Database Patterns

Production-grade database access patterns for Go. Covers connection management, query patterns, transactions, migrations, and testing.

How It Works

  1. Agent identifies the database need (setup, query, migration, optimization)
  2. Agent applies the appropriate pattern using the right abstraction level
  3. Agent ensures proper connection management, error handling, and resource cleanup
  4. Agent generates tests with appropriate mocking or containerized databases

Rules

1. Connection Management (Critical)

# Rule Description
CM1 Configure pool limits Set MaxOpenConns, MaxIdleConns, ConnMaxLifetime, ConnMaxIdleTime.
CM2 Always pass context Use QueryContext, ExecContext, PrepareContext — never the non-context variants.
CM3 Close rows Always defer rows.Close() immediately after Query().
CM4 Ping on startup Call db.PingContext(ctx) to verify the connection before serving traffic.
CM5 Use connection string builder Don't concatenate connection strings. Use the driver's config builder.
func Connect(ctx context.Context, dsn string) (*sql.DB, error) {
    db, err := sql.Open("pgx", dsn)
    if err != nil {
        return nil, fmt.Errorf("opening database: %w", err)
    }

    // Connection pool settings
    db.SetMaxOpenConns(25)                 // Max concurrent connections
    db.SetMaxIdleConns(10)                 // Keep idle connections ready
    db.SetConnMaxLifetime(30 * time.Minute) // Recycle connections
    db.SetConnMaxIdleTime(5 * time.Minute)  // Close idle connections

    // Verify connection
    if err := db.PingContext(ctx); err != nil {
        db.Close()
        return nil, fmt.Errorf("pinging database: %w", err)
    }

    return db, nil
}

2. Repository Pattern (Critical)

# Rule Description
RP1 Define repository interface at the consumer The service package defines what it needs from the repository.
RP2 Accept context as first parameter Every repository method takes context.Context.
RP3 Return domain types, not DB types Map between sql.NullString and *string at the repository boundary.
RP4 Handle sql.ErrNoRows Map to a domain-specific ErrNotFound. Don't leak sql.ErrNoRows.
RP5 Use prepared statements for repeated queries db.PrepareContext() once, then reuse.

Read the full file on GitHub · 304 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 304 lines · 87 tokens per session scan A 541e3a81f1c2

Subscribe to this mod's changes

database-patterns is a skill published in the GitHub repository daibang123a/golang-agent-skills (2 stars, last pushed 6mo ago), licensed MIT. It adds 87 tokens to every session and 2,589 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

golang-database

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…

samber/cc-skills-golang · 99 tokens

golang-samber-hot

In-memory caching in Golang using samber/hot — eviction algorithms (LRU, LFU, TinyLFU, W-TinyLFU, S3FIFO, ARC, TwoQueue, SIEVE, FIFO), TTL, cache loaders, sharding, stale-while-revalidate, missing key caching, and Prometheus metrics. Apply when using or adopting samber/hot, when the codebase imports…

samber/cc-skills-golang · 122 tokens

vendor-update

Upgrade Go/Node.js vendor dependencies and sync tool versions. Use whenever the user says "upgrade dependencies", "update vendors", "vendor update", "run vendor-upgrade", "bump dependencies", "update packages", or asks to run the vendor-update Make target. This skill also checks scripts/build/version.mk after…

apache/skywalking-banyandb · 95 tokens

compiling

Compile and build the SkyWalking BanyanDB project. Use when the user asks to compile, build, or generate code for this project.

apache/skywalking-banyandb · 31 tokens

neo4j-driver-go-skill

Covers the Neo4j Go Driver v6 — driver lifecycle, ExecuteQuery, managed and explicit transactions, session config, error handling, data type mapping, and connection tuning. Use when writing Go code that connects to Neo4j, setting up NewDriver or ExecuteQuery, debugging sessions/transactions/result handling, or working…

neo4j-contrib/neo4j-skills · 143 tokens

go-database

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…

eduardo-sl/go-agent-skills · 103 tokens