pg-repository-crud

Implement tenant-scoped PostgreSQL CRUD with pgxpool and search_path.

1|Updated Apr 17, 2026
One-click install
npx skills add https://github.com/PremModhaOfficial/motadata-ai-pipeline --skill pg-repository-crud
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pg-repository-crud
Source: https://github.com/PremModhaOfficial/motadata-ai-pipeline/tree/main/.claude/skills/pg-repository-crud
Command: npx skills add https://github.com/PremModhaOfficial/motadata-ai-pipeline --skill pg-repository-crud

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go data-access layer that implements a repository pattern for PostgreSQL 18 in a schema-per-tenant environment. It uses a single shared app-database pool (pgxpool) and tenant isolation via search_path, providing a concrete interface and implementation for CRUD, transactions, and a helper to map query results.

Core Features & Use Cases

  • Shared pool per app-database with tenant-scoped access via AcquireForTenant.
  • CRUD operations (Create, FindByID, Update, SoftDelete) with optimistic locking and soft-delete semantics.
  • Transaction management support through WithTransaction to ensure atomic tenant-scoped operations.
  • scanToMaps helper to convert query results into a serializable structure for downstream encoding.

Quick Start

Instantiate the repository with the pool, acquire a tenant-scoped connection, and perform a Create operation.

Frequently Asked Questions about pg-repository-crud

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

FAQPage Schema
How do I implement a repository pattern for multi-tenant PostgreSQL in Go?▼

A multi-tenant PostgreSQL repository pattern uses a shared pgxpool with tenant-scoped access via search_path. You acquire a connection for a specific tenant, then execute CRUD operations and transactions safely isolated within that tenant's schema.

How does tenant isolation work with a shared pgxpool connection?▼

Tenant isolation with a shared pgxpool connection works by setting the search_path to the tenant's specific schema. The AcquireForTenant helper retrieves a connection and scopes it, ensuring queries only access data within that tenant's boundary.

Can I use transactions with tenant-scoped PostgreSQL repository operations?▼

Yes, you can use transactions with tenant-scoped PostgreSQL repository operations. The WithTransaction helper ensures atomic operations within a specific tenant's schema, guarding against race conditions by maintaining the search_path context throughout the transaction block.

What's the best way to handle soft deletes in a multi-tenant Go data-access layer?▼

Handling soft deletes in a multi-tenant Go data-access layer involves marking records as deleted rather than removing them. The repository pattern implementation includes a SoftDelete operation that applies this semantic alongside optimistic locking to prevent concurrent conflicts.

Does this PostgreSQL repository pattern support optimistic locking?▼

Yes, this PostgreSQL repository pattern supports optimistic locking. CRUD operations like Create, FindByID, and Update are implemented with locking semantics to prevent concurrent modifications, ensuring data integrity within the multi-tenant environment.

How do I convert pgxpool query results to a serializable format in Go?▼

You convert pgxpool query results to a serializable format in Go using the scanToMaps helper. This function maps query rows into a structure suitable for downstream encoding, bridging the raw database output and application-level JSON responses.