golang-database

Guides writing and reviewing Go database code using sqlx, pgx, and database/sql.

Updated May 9, 2026
One-click install
npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-database-luminavault
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-database
Source: https://github.com/LuminaVault/LuminaVaultShared/tree/main/.agents/skills/golang-database
Command: npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-database-luminavault

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go developers often write database code with subtle bugs: leaked connections from unclosed rows, SQL injection from string concatenation, missing context propagation, and race conditions from unlocked reads. This Skill encodes battle-tested rules for safe, explicit database access in Go. ## Core Features & Use Cases - Safe Query Patterns: Enforces parameterized queries, context propagation, explicit sql.ErrNoRows handling, and proper rows.Close() discipline. - Transactions & Locking: Covers BeginTxx/defer Rollback/Commit, isolation levels, and SELECT FOR UPDATE for race-free read-modify-write flows. - Performance Guidance: Connection pool sizing, batch inserts (100–1000 rows), pgx COPY protocol, and cursor-based pagination instead of OFFSET. - Use Case: When asked to write a funds-transfer function, the Skill produces a serializable transaction with SELECT FOR UPDATE and deferred rollback instead of naive sequential updates. ## Quick Start Ask the AI to write or review a Go repository function that queries PostgreSQL with sqlx, and it will apply parameterized queries, context propagation, and proper error handling.

Frequently Asked Questions about golang-database

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

FAQPage Schema
Should I use GORM, sqlx, or pgx for a Go PostgreSQL project?▼

Use pgx for PostgreSQL-only projects since it is 30-50% faster and supports COPY, LISTEN, and arrays; use sqlx for multi-database portability. Avoid ORMs like GORM because they generate unpredictable queries, hide N+1 problems, and make debugging harder.

How do I handle NULLable columns in Go structs with sqlx?▼

Use pointer fields like *string or *time.Time, which scan NULL values cleanly and marshal to JSON naturally. sql.NullString works but requires custom JSON marshaling, and COALESCE in SQL is a third option that moves handling into the query.

How do I write a dynamic IN clause with sqlx?▼

Use sqlx.In() to expand the placeholder list for your slice of IDs, then call db.Rebind() to convert placeholders to your driver's format ($1 for PostgreSQL). Pass the returned query and args to SelectContext or QueryContext.

Why should I avoid OFFSET pagination on large tables?▼

OFFSET re-scans all skipped rows, making deep pages progressively slower with O(offset + limit) cost. Cursor-based pagination using WHERE created_at > $1 with ORDER BY and LIMIT stays O(limit) regardless of page depth.

Can this skill generate a database schema or migration SQL?▼

No. The skill explicitly refuses to generate schemas because AI-generated schemas often miss indexes, use wrong column types, or ignore production data volumes. Use golang-migrate, Flyway, or Atlas with human review for schema design.

How do I test Go database code without a real database?▼

Mock a repository interface with testify/mock for unit tests, or use go-sqlmock to verify exact SQL. For integration tests, use a //go:build integration tag with testcontainers-go and wrap each test in a transaction that rolls back.