agentsclimarketplace

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

Install
npx -y skills add saifoelloh/golang-best-practices-skill --skill gorm-query-patterns

Assembled 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

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

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.