golang-database

Enforce Go database best practices for sqlx and pgx repository functions.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you write Go database code that is safe and correct—avoiding SQL injection, connection leaks, NULL-handling bugs, and subtle transaction/locking issues.

Core Features & Use Cases

  • Safe parameterized queries: Ensures SQL placeholders are used instead of string concatenation to prevent injection.
  • Correct execution patterns: Guides you to use the right database/sql methods (e.g., ExecContext vs QueryContext) to avoid resource leaks.
  • Robust scanning and error handling: Recommends explicit NULL handling (pointer fields), proper rows.Close() usage, rows.Err() checks, and sql.ErrNoRows translation to domain errors.
  • Transactions and concurrency control: Covers transaction boundaries, isolation levels, and SELECT ... FOR UPDATE to prevent races.
  • Performance-minded practices: Includes connection pool configuration, batching guidance, and cursor-based pagination patterns.

Quick Start

Ask an agent to generate a Go repository function that uses sqlx with context-aware, parameterized queries and correct rows closing and sql.ErrNoRows handling for PostgreSQL.

Frequently Asked Questions about golang-database

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

FAQPage Schema
How do I handle NULL values when scanning rows in Go with sqlx or pgx?

Handle NULL values in Go by using pointer fields in your structs for explicit scanning and translating sql.ErrNoRows into domain errors. This prevents NULL-handling bugs and ensures robust data integrity when querying PostgreSQL with sqlx or pgx.

What is the best way to write safe parameterized queries in Golang for PostgreSQL?

The best way to write safe parameterized queries in Golang is to use SQL placeholders instead of string concatenation. This prevents SQL injection by ensuring untrusted input is never interpolated directly into your PostgreSQL query strings.

How do I manage transaction boundaries and SELECT FOR UPDATE locking in Go?

Manage transaction boundaries and locking in Go by defining explicit transaction scopes, configuring isolation levels, and using SELECT ... FOR UPDATE patterns. This prevents race conditions and ensures reliable concurrent data access in PostgreSQL.

Should I use an ORM or raw database SQL for my Go repository functions?

You should avoid ORMs and use explicit SQL for Go repository functions to ensure data integrity. Writing deterministic, parameterized SQL with sqlx or pgx provides safer execution patterns and prevents resource leaks compared to ORM abstraction layers.

Does this Go database approach generate schema or migration SQL for PostgreSQL?

No, this Go database approach never generates schema or migration SQL. It strictly focuses on safe data access and transaction execution, requiring dedicated migration tooling to manage PostgreSQL schema changes instead of handling it internally.

How do I prevent connection leaks when executing queries with database/sql in Go?

Prevent connection leaks in Go by using the correct database/sql methods like ExecContext versus QueryContext, ensuring proper rows.Close() execution, and always checking rows.Err() to manage the rows lifecycle effectively during PostgreSQL operations.