go-repository-pattern

Implement Go repository patterns with pgx for atomic persistence and domain error handling.

1|Updated Jun 20, 2026
One-click install
npx skills add https://github.com/shafibabar/SDLC-Artifact-Factory --skill go-repository-pattern-shafibabar
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-repository-pattern
Source: https://github.com/shafibabar/SDLC-Artifact-Factory/tree/main/skills/go-repository-pattern
Command: npx skills add https://github.com/shafibabar/SDLC-Artifact-Factory --skill go-repository-pattern-shafibabar

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill addresses the complexity of implementing robust, maintainable, and transaction-aware persistence layers in Go, preventing common pitfalls like SQL injection, connection leaks, and broken transaction boundaries.

Core Features & Use Cases

  • Transactional Integrity: Ensures atomic state changes and outbox event publishing using caller-supplied transactions.
  • Error Translation: Maps low-level pgx/pgconn errors into domain-specific sentinels for clean application-layer handling.
  • Query Safety: Enforces parameterised SQL and tenant-scoped filtering to prevent injection and data leakage.

Quick Start

Use the go-repository-pattern skill to generate a new repository implementation that satisfies the domain port and includes the required error translation and transaction-aware save methods.

Frequently Asked Questions about go-repository-pattern

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

FAQPage Schema
How do I implement the repository pattern in Go with pgx for transactional integrity?

Implement the repository pattern in Go using pgx by enforcing caller-supplied transactions to ensure atomic state changes and transactional outbox event publishing. This approach maintains strict transaction boundaries and prevents connection leaks.

What is the best way to translate pgx errors to domain-specific errors in Go backend development?

The best way to translate pgx errors is to map low-level pgx and pgconn errors into domain-specific sentinel errors. This provides complete pgx-to-domain error translation for clean application-layer handling without leaking infrastructure details.

How do I manage transaction boundaries and optimistic concurrency in a Go postgres backend?

Manage transaction boundaries in a Go postgres backend by applying the repository pattern with strict transaction boundaries and optimistic concurrency. This ensures atomic persistence and prevents broken transaction states during concurrent data access.

Does this Go repository pattern support tenant-scoped data access and parameterised query construction?

Yes, this Go repository pattern supports tenant-scoped data access and parameterised query construction. It enforces tenant-scoped filtering to prevent data leakage and uses parameterised SQL to prevent injection attacks.

When should I use a transactional outbox pattern in Go repository implementations?

Use a transactional outbox pattern in Go repository implementations when you need to ensure atomic state changes alongside event publishing. Caller-supplied transactions guarantee that database updates and outbox events are persisted together.

Why does my Go pgx repository leak connections or break transaction boundaries?

Your Go pgx repository may leak connections or break transaction boundaries due to unmanaged persistence layers. Implementing a transaction-aware repository pattern with caller-supplied transactions solves this by enforcing strict transaction boundaries.