data-access-patterns

Enforce raw SQL database access in Go repositories with transactions.

1|1|Updated Dec 16, 2023
One-click install
npx skills add https://github.com/sjtw/tarkov-build-optimiser --skill data-access-patterns-sjtw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-access-patterns
Source: https://github.com/sjtw/tarkov-build-optimiser/tree/main/.cursor/skills/data-access-patterns
Command: npx skills add https://github.com/sjtw/tarkov-build-optimiser --skill data-access-patterns-sjtw

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlines Go database code by enforcing explicit SQL usage over ORMs, delivering transparent performance and precise control over data access patterns.

Core Features & Use Cases

  • Enforces direct SQL via database/sql for reads and writes
  • Uses JSONB, ON CONFLICT, and PostgreSQL features for robust data handling
  • Emphasizes transactional integrity using *sql.Tx and careful error management
  • Keeps models and repository logic separated to improve maintainability

Quick Start

Get started by implementing a simple GetEntityById using database/sql with a prepared statement and wrap associated writes in a transaction.

Frequently Asked Questions about data-access-patterns

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

FAQPage Schema
How do I write raw SQL in Go without using an ORM?

You can write raw SQL in Go by using the standard database/sql package for reads and writes, avoiding ORMs to ensure transparent performance and precise control over data access patterns.

How do I handle PostgreSQL JSONB and upsert operations in Go?

Handle PostgreSQL JSONB and upsert operations in Go by executing explicit SQL queries that leverage native PostgreSQL features like JSONB handling and ON CONFLICT clauses for robust data management directly through the database driver.

What is the best way to manage database transactions in Go?

The best way to manage database transactions in Go is by using *sql.Tx objects to wrap associated writes, ensuring transactional integrity and careful error management across repository operations.

Should I separate models from repository logic in Go database code?

Yes, you should separate models from repository logic in Go database code. This architectural pattern improves maintainability by isolating data access logic from your data structures when using raw SQL.

When should I avoid using an ORM for Go database access?

You should avoid using an ORM for Go database access when you need explicit, high-performance control over SQL execution, precise transactional integrity, and direct utilization of PostgreSQL features like JSONB.