agentleFS
saifoellohsaifoelloh/golang-best-practices-skill/gorm-query-patterns/SKILL.md

gorm-sql-gorm-query-patterns

Skill15 starsChanged 9 months agoMITView on GitHub

GORM ORM query pattern review for PostgreSQL. Use when reviewing or writing Go database code using GORM — covers N+1, Preload vs Joins, transactions, error checking, Save vs Updates, and context propagation. Trigger on any GORM method usage.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 22

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

GORM Query Patterns

Expert-level review of GORM ORM usage in Go services backed by PostgreSQL. Covers correctness, safety, and idiomatic patterns.

When to Apply

Use this skill when:

  • Writing or reviewing repository layer code using GORM
  • Debugging unexpected query behavior (wrong results, wrong ORDER, missing data)
  • Reviewing association loading (Preload, Joins)
  • Auditing multi-step write operations for transaction safety

Rule Categories

PriorityCountFocus
Critical3SQL injection, silent errors, partial writes
High5N+1, First vs Find, Save vs Updates, context, column selection
Medium3Scopes, pagination, association upserts

Rules Covered (11 total)

Critical Issues (3)

  • critical-sql-injection — Never concatenate user input into SQL strings
  • critical-error-check — Always check .Error after every GORM operation
  • critical-transaction-wrap — Wrap multi-step operations in db.Transaction()

High-Impact Patterns (5)

  • high-preload-vs-joins — Preload for loading, Joins for filtering
  • high-first-vs-find — First for single record, Find for lists
  • high-save-vs-updates — Use Updates with map for partial updates, not Save
  • high-with-context — Always pass context via db.WithContext(ctx)
  • high-select-columns — Select only required columns, never SELECT *

Medium Improvements (3)

  • medium-scopes — Extract reusable WHERE logic into GORM scopes
  • medium-pagination-order — Always include ORDER BY in paginated queries
  • medium-omit-associations — Use Omit to prevent unintended association upserts

Trigger Phrases

  • "Review this GORM query"
  • "Check repository layer"
  • "db.Find / db.First / db.Create / db.Where"
  • "Preload / Joins"
  • "GORM transaction"
  • "Is this GORM code correct?"

Related Skills

  • postgresql-syntax — For raw SQL correctness and Postgres-specific syntax
  • query-performance — For index usage and N+1 detection
  • error-handling — For GORM and PostgreSQL error handling patterns
  • golang-best-practices-skill database-repository — Companion Go skill covering identifier quoting and select redundancy

Output Format

## Critical Issues Found: X

### [Rule ID] (File: repository.go, approx. line Y)
**Issue**: Brief description
**Fix**: Suggested correction
**Example**:
```go
// Corrected code here

High-Impact Patterns: X

Medium Improvements: X

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.