gorm-query-patterns

gorm-query-patterns is a skill for Claude Code, Codex from chirino/memory-service. It costs 96 tokens per session (820 once invoked), scanned A, original, Apache-2.0.

A set of rules for writing and reviewing Go database queries that use GORM, a Go library for working with databases. It explains how to handle lists, single-row lookups, ordering, and expected missing records.

In plain words
What is it for?
Use it when editing PostgreSQL or SQLite storage code, choosing between GORM query methods, or handling records that may be absent.
Why use it?
It helps prevent queries from reading unintended rows and keeps normal “not found” cases from becoming noisy errors.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/chirino/memory-service/gorm-query-patterns
Any agent
npx skills add chirino/memory-service --skill gorm-query-patterns
Clone the repo
git clone --depth 1 https://github.com/chirino/memory-service

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 gorm-query-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/chirino/memory-service/gorm-query-patterns.svg)](https://agentmods.dev/skills/chirino/memory-service/gorm-query-patterns)
Your own site
<a href="https://agentmods.dev/skills/chirino/memory-service/gorm-query-patterns"><img src="https://agentmods.dev/badge/skills/chirino/memory-service/gorm-query-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 96 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 820 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00096 $0.00820
Opus 5 $0.00048 $0.00410
Sonnet 5 $0.00019 $0.00164
Haiku 4.5 $0.00010 $0.00082

Measured 5d ago against content hash 19453bf234be, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

gorm-query-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 5d ago.

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/gorm-query-patterns/SKILL.md · 88 lines

How it starts

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

GORM Query Patterns

Use this skill when touching GORM-backed persistence code in this repo.

Base the query shape on whether "no row" is expected control flow or an exceptional condition.

Rules

  • For slice reads, use Find(&rows). An empty result set is normal.
  • For a single-row lookup where "not found" is expected, use Limit(1).Find(&row) and branch on RowsAffected.
  • Do not use Find(&row) without Limit(1) for a single struct destination. GORM's query docs warn that it can read more than one row and is not deterministic without a limit.
  • Use Take, First, or Last only when you want GORM to return ErrRecordNotFound.
  • Use First or Last only when the ordering is part of the behavior. Otherwise prefer Take for required single-row fetches.
  • When the store API returns a domain-level ErrNotFound or nil, nil for absence, do not route that control flow through gorm.ErrRecordNotFound; check RowsAffected instead.

Preferred Patterns

Expected absence, returning a domain ErrNotFound:

var row SomeRecord
result := tx.Where("user_id = ? AND external_id = ?", companyID, externalID).
	Limit(1).
	Find(&row)
if result.Error != nil {
	return nil, result.Error
}
if result.RowsAffected == 0 {
	return nil, ErrNotFound
}
return &row, nil

Expected absence, returning no result:

var row SomeRecord
result := tx.Where("user_id = ? AND status = ?", companyID, "running").
	Order("started_at desc").
	Limit(1).
	Find(&row)
if result.Error != nil {
	return nil, result.Error
}
if result.RowsAffected == 0 {
	return nil, nil
}
return &row, nil

Required row, missing row is exceptional:

var row SomeRecord
if err := tx.Where("id = ? AND user_id = ?", id, companyID).Take(&row).Error; err != nil {
	if errors.Is(err, gorm.ErrRecordNotFound) {
		return ErrNotFound
	}
	return err
}

Repo Notes

  • The noisy log pattern in this repo comes from optional lookups implemented with Take(...) and then translated from gorm.ErrRecordNotFound.
  • When reviewing internal/store/gormstore, inspect helper methods first. A single helper often drives many log lines.
  • Prefer consistent query shapes within one file. If a helper uses the optional-single-row pattern, keep nearby helpers aligned.

Read the full file on GitHub · 88 lines

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. 5d ago First seen · 88 lines · 96 tokens per session scan A 19453bf234be

Subscribe to this mod's changes

gorm-query-patterns is a skill published in the GitHub repository chirino/memory-service (11 stars, last pushed yesterday), licensed Apache-2.0. It adds 96 tokens to every session and 820 once invoked, about $0.0005 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-30.

Related

Other skills, from other repositories

encore-go-database

Work with PostgreSQL in Encore Go using sqldb.NewDatabase from encore.dev/storage/sqldb — schema migrations and SQL queries.

encoredev/skills · 37 tokens

go-add-migration

Create properly named PostgreSQL migration files for GOB microservices.

JotJunior/cstk · 17 tokens

mfd

MFD Generator — генерация Go-кода из PostgreSQL-схемы (модели, репозитории, фабрики тестов). Используй при правке .mfd файла, запуске make generate/make mfd, добавлении search-полей или db-test фабрик.

vmkteam/claude-plugins · 67 tokens

golang-fullstack-error-handling

Unified Go + GORM + PostgreSQL error handling review. Covers error wrapping, context propagation, PostgreSQL error codes (23505, 40001), errors.Is/As mapping, and retry logic. Ensures proper error chains and robust database failure recovery.

saifoelloh/golang-best-practices-skill · 60 tokens

gorm-sql-postgresql-syntax

PostgreSQL SQL syntax review for Go/GORM projects. Use when writing or reviewing raw SQL used via db.Raw(), db.Exec(), or migrations. Covers placeholder style, reserved keyword quoting, RETURNING, ILIKE, JSONB operators, and type casting. Don't use for MySQL or SQLite.

saifoelloh/golang-best-practices-skill · 68 tokens

azure-resource-manager-postgresql-dotnet

Azure PostgreSQL Flexible Server SDK for .NET. Database management for PostgreSQL Flexible Server deployments. Use for creating servers, databases, firewall rules, configurations, backups, and high availability. Triggers: "PostgreSQL", "PostgreSqlFlexibleServer", "PostgreSQL Flexible Server", "Azure Database for…

microsoft/skills · 97 tokens