repository-go

Implements Go domain repositories with Postgres, in-memory mocks, and fx dependency wiring.

4|Updated Jul 30, 2026
One-click install
npx skills add https://github.com/gabriellst/codm --skill repository-go-gabriellst
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: repository-go
Source: https://github.com/gabriellst/codm/tree/main/.claude/skills/repository/go
Command: npx skills add https://github.com/gabriellst/codm --skill repository-go-gabriellst

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It standardizes how Go backend developers build persistence layers for domain aggregates, preventing common mistakes like leaking sql.ErrNoRows, skipping optimistic-lock version increments, or bypassing UnitOfWork transactions. ## Core Features & Use Cases - Three-file repository pattern: Generates the interface, Postgres implementation, and in-memory mock in a folder-per-repo layout under <ctx>/repositories/<snake_name>/. - Transaction-aware persistence: Enforces the txOrDB helper so every query flows through the active UnitOfWork transaction, and Save drains domain events to the outbox. - fx dependency injection wiring: Binds interfaces to implementations via fx.Annotate and fx.As so consumers depend on interfaces, not concrete structs. - Use Case: When adding a new aggregate like TranscodingJob to the api-go workspace, follow the skill to produce a compliant repository with compile-time interface checks, (nil, nil) not-found semantics, and a mock whose Save mirrors Postgres behavior for tests. ## Quick Start Ask the agent to create a Go repository for a new domain entity following the repository skill, including the Postgres implementation, mock, and fx wiring.

Frequently Asked Questions about repository-go

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a domain repository in Go with Postgres?▼

Create a folder-per-repo package with three files: an interface declaring Find and Save, a pg implementation using database/sql with a txOrDB helper for transaction support, and an in-memory mock. Save must call IncrementVersion and drain domain events via domainEventRepo.SaveAll.

How should a Go repository handle rows that are not found?▼

Single-row queries should convert sql.ErrNoRows into a (nil, nil) return at the scan boundary. Callers never see ErrNoRows, so they can check for a nil entity without special-casing database errors.

How do I wire a Go repository with fx dependency injection?▼

Use fx.Provide with fx.Annotate and fx.As(new(XRepository)) in module.go so consumers depend on the interface. Plain fx.Provide of the constructor would expose the unexported concrete struct, which cannot be injected cross-package.

Why does my repository bypass the UnitOfWork transaction?▼

This happens when methods call r.db directly instead of the txOrDB helper. txOrDB extracts the active *sql.Tx placed in context by SQLUnitOfWork.Execute and falls back to the default DB only when no transaction exists.

Should pagination and listing methods go on a domain repository?▼

No. Domain repositories only expose write-side lookups like Find and Save. Listings for the UI belong in projection repositories or query use cases that return DTOs via direct SQL.