golang-database

Document Go database best practices for safe access with database/sql, sqlx, and pgx.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/nrmnqdds/gomaluum --skill golang-database-nrmnqdds
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-database
Source: https://github.com/nrmnqdds/gomaluum/tree/main/.agents/skills/golang-database
Command: npx skills add https://github.com/nrmnqdds/gomaluum --skill golang-database-nrmnqdds

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go applications often struggle with writing safe, testable database code: manual SQL, inconsistent error handling, and brittle transaction patterns. This skill provides a concise, opinionated guide to Go database best practices that emphasize explicit SQL, parameterization, and proper resource management.

Core Features & Use Cases

  • Parameterized queries and strict use of database/sql with optional sqlx/pgx ergonomics.
  • Context propagation and cancellation for all DB operations.
  • Transaction patterns, NULL handling, and deterministic error wrapping.
  • Guidance for testing DB code using mocks and integration tests, plus performance considerations.

Quick Start

Write a small Go function that fetches a user by ID using GetContext and a parameterized query, handling sql.ErrNoRows and wrapping other errors.

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 and NULLable columns in Go safely?

Handle Go database transactions and NULLable columns by using explicit transaction patterns with Tx, scanning into sql.Null* types, and wrapping errors deterministically. This approach ensures safe database access across PostgreSQL, MySQL, and SQLite.

What's the best way to write testable Go database code using database/sql?

The best way to write testable Go database code is by using parameterized queries, propagating context for cancellation, and applying testing patterns with mocks and integration tests to ensure observable and deterministic behavior.

How does context propagation work for Go database operations?

Context propagation for Go database operations works by passing context.Context to query methods like GetContext, ensuring operations respect cancellation deadlines and timeouts for safe, observable database access.

Should I use an ORM or explicit SQL with sqlx and pgx in Go?

You should use explicit SQL with sqlx and pgx in Go rather than an ORM. This enforces strict parameterized queries, strong error handling, and observable code while maintaining direct control over database/sql operations.

Can I use sqlx and pgx for database access across PostgreSQL, MySQL, and SQLite?

Yes, you can use sqlx and pgx for database access across PostgreSQL, MySQL, and SQLite. They provide ergonomics over database/sql while maintaining explicit SQL usage, proper rows handling, and consistent error wrapping.

Why do I get sql.ErrNoRows and how should I handle it in Go database queries?

You get sql.ErrNoRows when a Go database query returns no results, handled by checking against the error explicitly and wrapping other errors. This deterministic pattern ensures strong error handling and observable code.