x-database-patterns

Design PostgreSQL repository layers in Go with pgx or sqlx.

2|Updated Apr 12, 2026
One-click install
npx skills add https://github.com/pure-golang/level85 --skill x-database-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: x-database-patterns
Source: https://github.com/pure-golang/level85/tree/main/.agents/skills/x-database-patterns
Command: npx skills add https://github.com/pure-golang/level85 --skill x-database-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps you structure PostgreSQL access in a Go service or adapter so that database drivers, repository boundaries, transactions across repos, and constraint error handling are consistent and maintainable.

Core Features & Use Cases

  • Driver choice & data modeling guidance: Decide between pgx and sqlx based on project needs and avoid using JSONB as the primary data model when constraints/search/join logic matters.
  • Repository layer design with shared dbQuerier: Build a repo package layout that keeps constructors side-effect free and uses a common dbQuerier contract for both pools and transactions.
  • Transaction and constraint error handling: Pass a single transaction into multiple repos for cross-repository operations and handle constraint errors via sqlx helper functions.

Quick Start

Ask the assistant to design your PostgreSQL repo layer for a Go service using pgx, including a shared dbQuerier, cross-repository transactions, and constraint-error handling strategy.

Frequently Asked Questions about x-database-patterns

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

FAQPage Schema
How do I design a PostgreSQL repository layer in Go that supports transactions across multiple repositories?

Design a PostgreSQL repository layer by defining a shared dbQuerier interface that works with both connection pools and transactions, allowing a single transaction to be passed into multiple repositories for atomic cross-repository operations.

When should I choose pgx over sqlx for my Go database access layer?

Choose between pgx and sqlx for your Go database access layer based on specific project needs; pgx offers native PostgreSQL protocol support while sqlx provides constraint helper functions for reliable error mapping, and this decision guides the entire repository structure.

How do I handle PostgreSQL constraint violations consistently in a Go service?

Handle PostgreSQL constraint violations consistently by using sqlx helper functions for reliable constraint error mapping, ensuring your service or adaptor catches and translates these database errors into predictable application-level responses.

Can I use JSONB as my primary data model in PostgreSQL for a Go service requiring joins and constraints?

Avoid using JSONB as the primary data model in PostgreSQL when your Go service requires constraints, search, or join logic; structured relational data modeling is necessary to maintain query performance and data integrity.

What is a dbQuerier contract in Go and how does it unify database pools and transactions?

A dbQuerier contract in Go is a shared interface that standardizes query execution methods, unifying connection pools and transactions so repository constructors remain side-effect free and can operate seamlessly within either context.