# Li Lance Android Seraphim Framework Golang Database

> Golang Database

- Skill: `tomevault-io/li-lance-android-seraphim-framework-golang-database` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/li-lance-android-seraphim-framework-golang-database`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/li-lance-android-seraphim-framework-golang-database/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/li-lance-android-seraphim-framework-golang-database

---


# Golang Database

## **Priority: P0 (CRITICAL)**

## Principles

- **Prefer Raw SQL/Builders over ORMs**: `sqlc` generates type-safe Go from SQL. ORMs (GORM) can
  obscure performance.
- **Repository Pattern**: Abstract DB access behind interfaces in `internal/port/`.
- **Connection Pooling**: Always configure pool settings.
- **Transactions**: ACID logic must use transactions. Pass `context.Context` everywhere.

## Implementation Workflow

1. **Choose driver** — PostgreSQL: `pgx/v5`; MySQL: `go-sql-driver/mysql`; SQLite:
   `modernc.org/sqlite`.
2. **Configure pool** — Set `MaxOpenConns`, `MaxIdleConns`, and `ConnMaxLifetime` on the connection.
3. **Define repository interface** — Abstract DB access behind an interface at the consumer side.
4. **Use context-aware queries** — Always use `QueryContext`/`ExecContext`; bare queries ignore
   timeouts.
5. **Close rows** — Always `defer rows.Close()` and check `rows.Err()` after iteration.
6. **Wrap in transactions** — Use transactions for multi-step operations requiring atomicity.

See [repository pattern and connection pool examples](references/repository-pattern.md)

## Anti-Patterns

- **No global db var**: Inject DB connection via constructor.
- **No context-less queries**: Use `QueryContext`/`ExecContext`; bare queries ignore timeouts.
- **No leaked rows**: Always `defer rows.Close()` and check `rows.Err()`.

## References

- [Repository Pattern Implementation](references/repository-pattern.md)
- [Connection Tuning](references/connection-tuning.md)

---
> Source: [li-lance/android-seraphim-framework](https://github.com/li-lance/android-seraphim-framework) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-16 -->

