Gorm query patterns
Skill saifoelloh/golang-best-practices-skill/gorm-query-patterns
Production-ready Go code review skill for AI agents based on authoritative sources
npx -y skills add saifoelloh/golang-best-practices-skill --skill gorm-query-patternsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 16 stars16 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
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 declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
3.1 KB, as published. Nobody here has run it
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 here
High-Impact Patterns: X
Medium Improvements: X