golang-database

Implement and debug Go database access with sqlx or pgx.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you prevent common database bugs in Go by enforcing parameterized SQL, correct context propagation, reliable row handling, safe transactions, and production-safe patterns for scanning, NULLs, and error handling.

Core Features & Use Cases

  • Parameterize every query: avoids SQL injection by banning string-built predicates and requiring driver-appropriate placeholders.
  • Correct database/sql usage: enforces the *Context method variants, explicit sql.ErrNoRows handling, and guaranteed rows.Close() plus rows.Err() checks.
  • Production-grade safety patterns: guides transactions (with proper isolation levels), SELECT ... FOR UPDATE locking, NULLable column modeling, connection pool sizing, and bulk/batch processing heuristics.
  • Scope control: explicitly covers database access practices and debugging, while refusing to generate schema- or migration-defining SQL.

Quick Start

Use golang-database to implement or review a Go repository method that uses sqlx or pgx with safe parameterized queries, context-aware calls, correct scanning (including NULLable columns), and robust transaction behavior.

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 Go database queries?

To prevent SQL injection in Go, you must use parameterized queries with driver-appropriate placeholders, explicitly banning string-built predicates. This ensures inputs are treated strictly as data values, not executable SQL code.

What is the correct way to handle sql.ErrNoRows and rows.Close in Go?

Correct database/sql usage requires explicitly checking for sql.ErrNoRows when scanning single rows and guaranteeing rows.Close() plus rows.Err() checks. This prevents resource leaks and unhandled errors during row iteration.

How do I manage PostgreSQL transactions and isolation levels using pgx or sqlx?

Managing PostgreSQL transactions with pgx or sqlx involves setting safe transaction isolation levels and applying SELECT ... FOR UPDATE locking. This ensures transactional correctness and prevents concurrent modification issues.

Can I use this approach for Go database access across MySQL and SQLite?

Yes, this database access approach supports PostgreSQL, MariaDB, MySQL, and SQLite using sqlx or pgx. It provides production-safe patterns for scanning, NULLable column modeling, and connection pool sizing across these drivers.

When should I use external migration tooling instead of generating schema SQL in Go?

You should use external migration tooling for schema and migration SQL because this approach explicitly refuses to generate schema-defining SQL. It focuses strictly on safe query writing, transactional correctness, and repository-layer debugging.

How do I handle NULLable columns when scanning rows in Go?

Handling NULLable columns in Go requires proper modeling using types like sql.NullString or pointer fields during row scanning. This avoids scan errors and ensures safe data mapping when database values are absent.