Agent skill
Database
Standards for database interaction, connection pooling, and repository patterns in Golang.
Stars
163
Forks
31
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/database-hoangnguyen0403-agent-skills-standar
Metadata
Additional technical details for this skill
- labels
-
golang database sql postgres repository
- triggers
-
{ "files": [ "internal/adapter/repository/**" ], "keywords": [ "database", "sql", "postgres", "gorm", "sqlc", "pgx" ] }
SKILL.md
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:
sqlc(type-safe SQL generation). - Repository Pattern: Abstract DB access behind interfaces in
internal/port/(e.g.,UserRepository). - Connection Pooling: Always configure
SetMaxOpenConns,SetMaxIdleConns,SetConnMaxLifetime. - Transactions: Logic requiring ACID MUST use transactions. Pass
context.Contexteverywhere.
Drivers
- PostgreSQL:
jackc/pgx(Preferpgx/v5for performance and features). - MySQL:
go-sql-driver/mysql. - SQLite:
mattn/go-sqlite3ormodernc.org/sqlite(pure Go).
Anti-Patterns
- Global DB Connection: Do not use global
var db *sql.DB. Inject it. - Ignoring Context: Always use
db.QueryContextordb.ExecContextto handle timeouts. - Leaking Rows: ALWAYS
defer rows.Close()and checkrows.Err().
References
Didn't find tool you were looking for?