golang-database

Implement safe, observable Go database access with parameterized queries and context propagation.

2.9k|191|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-database
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-database
Source: https://github.com/samber/cc-skills-golang/tree/main/skills/golang-database
Command: npx skills add https://github.com/samber/cc-skills-golang --skill golang-database

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Parameterized, context-aware, observable database access in Go—without relying on ORMs or opaque abstractions, enabling safer and clearer data interactions.

Core Features & Use Cases

  • Parameterized queries and explicit error handling to distinguish not-found and real failures.
  • Context propagation for every DB operation and consistent use of QueryContext / GetContext / ExecContext.
  • Transaction patterns with BeginTx, proper rollback handling, and selective isolation levels.
  • NULL handling with pointer fields and proper struct scanning for sqlx and pgx.
  • Testing patterns: unit tests with mocks and integration tests against a real database.

Quick Start

Create a minimal Go data layer using sqlx that queries a PostgreSQL table with parameterized SQL and returns results.

Frequently Asked Questions about golang-database

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

FAQPage Schema
How do I handle database transactions in Go without an ORM?

Database transactions in Go without an ORM require using BeginTx with proper rollback handling and selective isolation levels. This approach enforces explicit error handling and context propagation for every transaction operation to ensure safe data interactions.

What is the best way to handle NULL values when scanning database rows in sqlx?

Handling NULL values in sqlx involves using pointer fields within your structs for proper scanning. This avoids opaque abstractions and allows clear, explicit data interactions by directly mapping nullable database columns to Go pointers.

How do I propagate context in Go database queries using pgx?

Context propagation in pgx requires consistent use of QueryContext, GetContext, and ExecContext methods for every database operation. This ensures your queries are observable, context-aware, and safely cancellable without relying on ORMs.

Does this Go database approach work with both sqlx and pgx?

Yes, this approach applies to codebases using database/sql with either sqlx or pgx. It enforces parameterized queries, explicit error handling to distinguish not-found results from real failures, and proper row closing across both libraries.

How do I test Go database access code that uses sqlx and pgx?

Testing Go database access involves unit tests with mocks and integration tests against a real database. This strategy ensures your parameterized queries and transaction patterns perform safely and observably without ORM dependencies.