golang-database

Enforce safe Go database access patterns with parameterized SQL and error handling.

4|Updated May 17, 2026
One-click install
npx skills add https://github.com/hellopoisonx/aim --skill golang-database-hellopoisonx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-database
Source: https://github.com/hellopoisonx/aim/tree/main/skills/golang-database
Command: npx skills add https://github.com/hellopoisonx/aim --skill golang-database-hellopoisonx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill prevents common and costly database bugs in Go by enforcing parameterized SQL, correct NULL handling, safe query execution patterns, and reliable transaction and connection-pool behavior.

Core Features & Use Cases

  • Parameterized queries and SQL injection safety: Ensures user input never gets concatenated into SQL strings.
  • Correct scanning and NULLable column handling: Recommends pointer fields and/or sql.NullXxx patterns that round-trip cleanly to JSON.
  • Robust query lifecycle and error handling: Requires context propagation, explicit sql.ErrNoRows handling, and proper rows.Close() plus rows.Err() checks.
  • Transactions and locking: Guides use of isolation levels and SELECT ... FOR UPDATE to avoid race conditions during multi-step writes.
  • Performance-aware database coding: Covers connection pool configuration, batching, pagination strategies, and bulk insert options (e.g., pgx COPY).

Quick Start

Ask for a production-ready Go database function (sqlx or pgx) that uses *Context calls, parameterized SQL, correct NULL handling, and proper error translation for sql.ErrNoRows.

Frequently Asked Questions about golang-database

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

FAQPage Schema
How do I prevent SQL injection in golang database/sql queries?

Prevent SQL injection in golang database/sql by enforcing parameterized queries, ensuring user input is never concatenated into SQL strings, and binding variables through driver placeholders rather than string formatting.

What's the best way to handle NULLable columns scanning structs in Go with sqlx or pgx?

Handle NULLable columns scanning structs in Go with sqlx or pgx by using pointer fields or sql.NullXxx types, ensuring values round-trip cleanly to JSON without triggering scan errors.

How do I properly close rows and check errors in golang database/sql?

Properly close rows in golang database/sql by calling rows.Close() explicitly and checking rows.Err() after iteration completes to catch mid-query execution errors, while propagating context through all calls.

How do I use transactions and SELECT FOR UPDATE locking in Go PostgreSQL?

Use transactions and SELECT FOR UPDATE locking in Go PostgreSQL by setting appropriate isolation levels through context to avoid race conditions during multi-step writes and concurrent data modifications.

Does this approach support connection pool configuration and pgx COPY bulk inserts?

This approach supports connection pool configuration and pgx COPY bulk inserts by providing performance-aware database coding guidance for batching, pagination strategies, and high-throughput data loading operations.

How should I handle sql.ErrNoRows correctly when querying a single row in Go?

Handle sql.ErrNoRows correctly in Go by explicitly checking for this specific error after QueryRow scans to distinguish between an actual query failure and an empty result set, translating it appropriately.