golang-database

Implement safe database access patterns in Go using database/sql with sqlx or pgx.

Updated Apr 24, 2026
One-click install
npx skills add https://github.com/Utchash007/TermTales --skill golang-database-utchash007
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-database
Source: https://github.com/Utchash007/TermTales/tree/main/.agents/skills/golang-database
Command: npx skills add https://github.com/Utchash007/TermTales --skill golang-database-utchash007

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go apps building database access patterns face the risk of untrusted SQL, hidden ORM abstractions, and context-tethered queries. This Skill provides safe, explicit database practices in Go using standard libraries and popular helpers (sqlx/pgx) to keep SQL visible and testable.

Core Features & Use Cases

  • Parameterized queries for all statements to prevent SQL injection and to ensure database correctness.
  • Context propagation across all operations (QueryContext, ExecContext, GetContext) for cancellation and deadlines.
  • Explicit error handling patterns (including sql.ErrNoRows) and observable behavior with close of rows.
  • Transaction patterns (BeginTx/Commit/Rollback) and isolation level guidance for multi-statement operations.
  • NULLable column handling and struct scanning guidance for sqlx/pgx, with guidance on scanning and JSON marshaling.

Quick Start

Create a context-aware Go function that uses GetContext with a parameterized query to fetch a user by ID.

Frequently Asked Questions about golang-database

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

FAQPage Schema
How do I handle SQL transactions and context propagation in Go without an ORM?

Use database/sql with sqlx or pgx wrappers to manage transactions via BeginTx, Commit, and Rollback. Propagate context across all operations using QueryContext, ExecContext, and GetContext to enforce cancellation and deadlines safely.

What is the best way to handle NULL values and struct scanning in Go database queries?

Handle NULL values explicitly using sqlx or pgx struct scanning guidance. This Skill provides patterns for nullable columns and JSON marshaling, ensuring safe, explicit data extraction without relying on hidden ORM abstractions.

Can I use this explicit database access approach with SQLite, MariaDB, and MySQL?

Yes, this explicit database access approach applies across PostgreSQL, MariaDB, MySQL, and SQLite. It standardizes parameterized queries and proper rows handling to ensure database correctness and prevent SQL injection.

How do I prevent SQL injection and ensure context-tethered queries in Go applications?

Prevent SQL injection by using parameterized queries for all statements. Ensure context-tethered queries by propagating context through operations like QueryContext and ExecContext, keeping SQL visible and testable without ORM abstractions.

Why should I avoid schema generation in code and use explicit database/sql patterns instead?

Avoiding schema generation in code keeps SQL visible, explicit, and testable. Using database/sql with sqlx or pgx wrappers enforces proper rows handling and observable error patterns, including explicit handling of sql.ErrNoRows.