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.
In this repository9 other files it gives its agents.
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
- Distinctive: line 22
Use this skill when:
≈ “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.
Files
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
| Priority | Count | Focus |
| Critical | 3 | SQL injection, silent errors, partial writes |
| High | 5 | N+1, First vs Find, Save vs Updates, context, column selection |
| Medium | 3 | Scopes, pagination, association upserts |
Rules Covered (11 total)
Critical Issues (3)
critical-sql-injection— Never concatenate user input into SQL stringscritical-error-check— Always check.Errorafter every GORM operationcritical-transaction-wrap— Wrap multi-step operations indb.Transaction()
High-Impact Patterns (5)
high-preload-vs-joins— Preload for loading, Joins for filteringhigh-first-vs-find— First for single record, Find for listshigh-save-vs-updates— Use Updates with map for partial updates, not Savehigh-with-context— Always pass context viadb.WithContext(ctx)high-select-columns— Select only required columns, neverSELECT *
Medium Improvements (3)
medium-scopes— Extract reusable WHERE logic into GORM scopesmedium-pagination-order— Always include ORDER BY in paginated queriesmedium-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 hereHigh-Impact Patterns: X
Medium Improvements: X
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
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.

