golang-gin-database

Installation
SKILL.md

golang-gin-database — Database Integration

Integrate PostgreSQL with Gin APIs using the repository pattern. Keeps database logic out of handlers and services, and supports swapping GORM ↔ sqlx without touching business logic.

When to Use

  • Adding a PostgreSQL database to a Gin project
  • Implementing the repository pattern (interface + concrete implementation)
  • Writing GORM or sqlx queries
  • Setting up database connection pooling
  • Running migrations (golang-migrate)
  • Wiring repositories → services → handlers in main.go
  • Writing context-propagating transactions

Repository Interface Pattern

Define the interface in the domain layer; implement it in the repository layer. This inverts the dependency: services depend on an abstraction, not a concrete database library.

Architecture note: In clean architecture, domain entities should not carry json or binding tags. Use separate request/response DTOs in the delivery layer. See golang-gin-clean-arch Golden Rule 4.

Related skills

More from cylixlee/cortex

Installs
2
Repository
cylixlee/cortex
First Seen
Apr 16, 2026