golang-database

Enforce parameterized SQL and context propagation in Go database code.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go applications often struggle with safe, observable database access. This skill provides a pragmatic approach to raw SQL in Go using sqlx or pgx, enforcing parameterized queries, explicit context propagation, robust error handling, and clear transaction boundaries. It also helps avoid ORM pitfalls and promotes testable, maintainable database code.

Core Features & Use Cases

  • Enforces parameterized SQL across all queries to prevent injection.
  • Encourages explicit context usage (QueryContext, ExecContext, GetContext) for deadlines and cancellations.
  • Demonstrates proper transaction patterns, row scanning, and NULL handling without ORM abstractions.
  • Use Case: when building a Go backend that talks to PostgreSQL, MariaDB, MySQL, or SQLite and needs observable, auditable data access code.

Quick Start

Install sqlx or pgx, wire a DB instance, and start writing context-aware, parameterized queries against your database.

Frequently Asked Questions about golang-database

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

FAQPage Schema
How do I write safe Go database code without an ORM?

Safe Go database code without an ORM uses parameterized SQL and explicit context propagation via methods like QueryContext and ExecContext. This approach enforces robust error handling and clear transaction boundaries using sqlx or pgx for maintainable backend services.

What is the best way to handle transactions in Go with pgx or sqlx?

Handling transactions in Go with pgx or sqlx requires explicit context propagation and clear transaction boundaries. You should use context-aware methods, manage NULL values during row scanning, and ensure rows are closed properly to maintain observable and auditable data access.

How do I handle sql.ErrNoRows when querying a PostgreSQL database in Go?

Handle sql.ErrNoRows in Go by explicitly checking the error after context-aware query methods like GetContext. Proper error handling prevents crashes when queries return no records, ensuring your PostgreSQL database access remains robust and observable without ORM abstractions.

Can I use sqlx and pgx for backend services connecting to MySQL and SQLite?

Yes, you can use sqlx and pgx for backend services interacting with PostgreSQL, MariaDB, MySQL, or SQLite. These libraries support parameterized queries, context propagation, and connection pool configuration across these database engines without requiring an ORM.

Why should I use context-aware methods like ExecContext for Go database access?

Use context-aware methods like ExecContext and QueryContext for Go database access to enforce explicit deadlines and cancellations. Propagating context ensures your PostgreSQL or MySQL queries are observable, auditable, and safely cancellable during service degradation.

What are the limitations of using raw SQL over an ORM for Go database access?

Raw SQL in Go requires manually managing row scanning, NULL handling, and connection pool configuration, which adds boilerplate compared to ORMs. However, it avoids ORM pitfalls by enforcing parameterized queries and explicit error handling for testable, maintainable code.