golang-database

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

1|Updated Jun 2, 2026
One-click install
npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-database-verifiedorganic
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-database
Source: https://github.com/VerifiedOrganic/onboard/tree/main/.agents/skills/golang-database
Command: npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-database-verifiedorganic

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go database code is easy to get subtly wrong: leaked connections from unclosed rows, SQL injection from string concatenation, missing context propagation, and race conditions from unlocked reads. This Skill encodes the correct patterns for database/sql, sqlx, and pgx so generated and reviewed code follows safe, explicit database practices. ## Core Features & Use Cases - Safe query patterns: Enforces parameterized queries, context propagation, explicit sql.ErrNoRows handling, and proper rows.Close() / rows.Err() discipline. - Transactions and locking: Covers BeginTxx/defer Rollback/Commit, isolation levels, and SELECT ... FOR UPDATE for read-modify-write flows like fund transfers. - Performance guidance: Connection pool sizing, batch inserts of 100–1000 rows, pgx COPY protocol for bulk loads, and cursor-based pagination instead of OFFSET. - Testing strategies: Mock-based unit tests, sqlmock query verification, and build-tagged integration tests with transaction rollback or testcontainers. - Use Case: When asked to write a TransferFunds function, the Skill produces a serializable transaction that locks rows with SELECT FOR UPDATE, defers rollback, and wraps errors with context. ## Quick Start Ask the agent to write or review a Go function that queries PostgreSQL with sqlx, such as a paginated user listing or a transactional balance transfer.

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 hide SQL, generate unpredictable queries, 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 is verbose and needs custom JSON marshaling; COALESCE in SQL is a third option.

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

Use sqlx.In to expand the placeholders for a slice of values, then call db.Rebind to adjust placeholder syntax for your driver. Pass the returned query and args to a Context method like SelectContext.

Why should I avoid OFFSET pagination on large tables?▼

OFFSET re-scans all skipped rows, making deep pages progressively slower at O(offset + limit). 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. It explicitly refuses to generate schemas because AI-generated schemas often miss indexes, use wrong types, or ignore production data volumes. Use golang-migrate, Flyway, or Atlas with human review instead.

How do I test Go repository code against a real database?▼

Gate integration tests behind a //go:build integration tag, wrap each test in a transaction that rolls back in teardown, and use testcontainers-go for a reproducible database in CI. Never test against production databases.