Borrowing it
Nothing to install: this file belongs to chirino/memory-service. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.
curl -O https://raw.githubusercontent.com/chirino/memory-service/main/.skills/gorm-query-patterns/SKILL.mdgit clone --depth 1 https://github.com/chirino/memory-serviceWrote 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.
[](https://agentmods.dev/skills/chirino/memory-service/gorm-query-patterns)<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/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.
<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="Reviewed on agentmods" width="80" height="20"></a>- NVIDIA SkillSpector pass
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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00096 | $0.00806 |
| Opus 5.5 | $0.00038 | $0.00322 |
| Sonnet 5.5 | $0.00019 | $0.00161 |
| Haiku 4.5 | $0.00010 | $0.00081 |
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 1mo 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.
How it starts
The opening of the file, as written. The whole thing — 83 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 onRowsAffected. - Do not use
Find(&row)withoutLimit(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, orLastonly when you want GORM to returnErrRecordNotFound. - Use
FirstorLastonly when the ordering is part of the behavior. Otherwise preferTakefor required single-row fetches. - When the store API returns a domain-level
ErrNotFoundornil, nilfor absence, do not route that control flow throughgorm.ErrRecordNotFound; checkRowsAffectedinstead.
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
- GORM stores live in
internal/plugin/store/postgresandinternal/plugin/store/sqlite. Inside route-scoped transactions, get the handle withdbFor(ctx)/writeDBFor(ctx, ...), nots.db. - Example of the optional single-row pattern:
internal/plugin/store/postgres/episodic_kind.go(Limit(1).Find(...)plusRowsAffected). - Prefer consistent query shapes within one file. If a helper uses the optional-single-row pattern, keep nearby helpers aligned.
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.
- 1mo ago Changed · -5 lines 184dc57c458a
- 2mo ago First seen · 88 lines · 96 tokens per session scan A 19453bf234be
gorm-query-patterns is a skill published in the GitHub repository chirino/memory-service (12 stars, last pushed yesterday), licensed Apache-2.0. It adds 96 tokens to every session and 806 once invoked, about $0.0004 per session on Opus 5.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.
Other skills, from other repositories
sql-query-performance
Use when writing or changing a query against PostgreSQL from Go — avoiding N+1 loops, reading EXPLAIN output, indexing, and keyset pagination.
encore-go-database
Work with PostgreSQL in Encore Go using sqldb.NewDatabase from encore.dev/storage/sqldb — schema migrations and SQL queries.
go-add-migration
Create properly named PostgreSQL migration files for GOB microservices.
mfd
A Go code generator that reads XML descriptions of a PostgreSQL schema and creates models, repositories, services, and test helpers. It is used through project Makefile commands.
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.
go-data-persistence
Data persistence patterns in Go covering raw SQL with sqlx/pgx, ORMs like Ent and GORM, connection pooling, migrations with golang-migrate, and transaction management. Use when implementing database access, designing repositories, or managing schema migrations.