database

Define a Go Repository pattern using context-aware database/sql queries.

31|4|Updated Aug 24, 2021
One-click install
npx skills add https://github.com/razorpay/trino-gateway --skill database-razorpay
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database
Source: https://github.com/razorpay/trino-gateway/tree/main/.agents/skills/databases
Command: npx skills add https://github.com/razorpay/trino-gateway --skill database-razorpay

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Database access is often ad-hoc and scattered, making error handling and testing difficult across domain packages.

Core Features & Use Cases

  • Enforces a Repository pattern with a dedicated repository.go in each domain package.
  • Uses database/sql with raw queries (no ORMs) for transparency and portability.
  • Requires ctx context.Context in every method and wraps errors with the domain name for easier tracing.
  • Use Case: Implement standard CRUD for core domain entities with consistent data access.

Quick Start

Create a basic Repository in your domain package using context-aware database/sql queries for CRUD operations.

Frequently Asked Questions about database

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

FAQPage Schema
How do I standardize SQL repository patterns in Go without an ORM?

Standardize SQL repository patterns in Go by implementing a dedicated repository.go file in each domain package using raw database/sql queries. This approach enforces consistent context-aware data access and explicit error wrapping for transparent testing.

Why should I pass context.Context in every database query method?

Passing context.Context in every database query method is required to enforce context-aware data access across bounded contexts and microservices. It ensures explicit request tracing and allows proper cancellation or timeouts for raw database/sql operations.

What is the best way to wrap database errors in Go microservices?

The best way to wrap database errors in Go microservices is to explicitly wrap them with the originating domain name. This standard Repository pattern practice ensures easier tracing and debugging across scattered domain packages using raw database/sql queries.

How do I implement raw database/sql queries for domain entities in Go?

Implement raw database/sql queries for domain entities by creating a standard Repository pattern in your domain package. Use explicit context-aware CRUD operations to maintain data access transparency and portability without relying on ORMs.

When do I need a standard Repository pattern for SQL access in Go?

You need a standard Repository pattern for SQL access in Go when database operations become ad-hoc and scattered across domain packages. It solves difficult error handling and testing by enforcing raw database/sql queries with consistent context propagation.

Does this Go repository pattern work without ORM dependencies?

Yes, this Go repository pattern works entirely without ORM dependencies. It uses raw database/sql queries for transparency and portability, applying explicit context-aware data access and error wrapping strictly within your bounded contexts.