Skillshub golang-database
Standards for database interaction, connection pooling, and repository patterns in Golang. Use when implementing database access, connection pools, or repositories in Go. (triggers: internal/adapter/repository/**, database, sql, postgres, gorm, sqlc, pgx)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/golang-database" ~/.claude/skills/comeonoliver-skillshub-golang-database-1d0566 && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/golang-database/SKILL.mdsource content
Golang Database Standards
Priority: P0 (CRITICAL)
Principles
- Prefer Raw SQL/Builders over ORMs: Go structs map well to SQL. ORMs (GORM) can obscure performance. Recommended:
(type-safe SQL generation).sqlc - Repository Pattern: Abstract DB access behind interfaces in
(e.g.,internal/port/
).UserRepository - Connection Pooling: Always configure
,SetMaxOpenConns
,SetMaxIdleConns
.SetConnMaxLifetime - Transactions: Logic requiring ACID MUST use transactions. Pass
everywhere.context.Context
Drivers
- PostgreSQL:
(Preferjackc/pgx
for performance and features).pgx/v5 - MySQL:
.go-sql-driver/mysql - SQLite:
ormattn/go-sqlite3
(pure Go).modernc.org/sqlite
Anti-Patterns
- No global db var: Inject DB connection via constructor; never use
.var db *sql.DB - No bare queries: Use
/QueryContext
; bare queries ignore context timeouts.ExecContext - No leaked rows: Always
and checkdefer rows.Close()
after iteration.rows.Err()