golang-database

Guide Go database code toward explicit SQL and context-aware execution.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-database-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-database
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-database
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-database-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you write, review, and debug Go database code that is safe, explicit, and production-ready, especially when working with SQL-backed services.

Core Features & Use Cases

  • Query Safety: Uses parameterized SQL, context-aware calls, and explicit error handling to reduce injection risk and improve reliability.
  • Transaction Handling: Covers BeginTxx patterns, rollback safety, isolation levels, and row locking for multi-step operations.
  • Performance and Data Handling: Guides connection pool tuning, batching, cursor pagination, and nullable field scanning with sqlx or pgx.
  • Use Case: Apply it when building a repository layer for a Go API that needs correct reads and writes, clean transaction boundaries, and predictable database behavior in production.

Quick Start

Use this Skill to review or generate Go database code that follows safe SQL practices, transaction patterns, and production-grade pool and scanning conventions.

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

Database transactions in Go require explicit BeginTxx patterns, context-aware execution, and proper rollback safety on errors before committing. You must manage isolation levels and row locking for multi-step operations to ensure data integrity.

What is the best way to write production-ready Go database code without an ORM?

Production-ready Go database code without an ORM uses explicit SQL, parameterized queries to prevent injection, and context-aware calls. It enforces rows closing, sql.ErrNoRows translation, and predictable connection pool tuning for reliable repository-layer operations.

How do I tune connection pools and handle nullable fields with sqlx in Go?

Connection pool tuning with sqlx involves configuring pool limits and timeouts for your database driver. Nullable fields require explicit scanning logic to avoid panics and ensure safe data mapping across PostgreSQL, MariaDB, MySQL, or SQLite queries.

Why do I need to check rows iteration and close rows explicitly in Golang database queries?

Checking rows iteration and closing rows explicitly in Golang prevents resource leaks and ensures connection return to the pool. It is a required safety practice for explicit SQL query execution to avoid exhausting database connections during reads.

Does this Go database approach work with PostgreSQL and MySQL for integration testing?

Yes, this explicit SQL approach works across PostgreSQL, MariaDB, MySQL, and SQLite. It applies to repository-layer reads, writes, batching, pagination, and integration testing by enforcing parameterized queries and safe transaction rollback patterns.

When should I avoid using ORMs and schema generation for Go database access?

Avoid ORMs and schema generation when you need predictable database behavior, explicit SQL control, and hidden feature prevention. Explicit SQL with context-aware execution and manual transaction handling provides safer production-grade reliability.