golang-gin-database

Integrate PostgreSQL into Go Gin APIs using GORM or sqlx with the repository pattern.

1|Updated Jul 4, 2026
One-click install
npx skills add https://github.com/trungenglish/SHOPWISE --skill golang-gin-database-trungenglish
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-gin-database
Source: https://github.com/trungenglish/SHOPWISE/tree/main/.agents/skills/golang-gin-database
Command: npx skills add https://github.com/trungenglish/SHOPWISE --skill golang-gin-database-trungenglish

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Adding a database to a Go Gin API involves many decisions: ORM choice, connection pooling, transactions, migrations, and keeping SQL out of handlers. This Skill provides production-oriented patterns for wiring PostgreSQL into a Gin project cleanly, so database logic stays in repositories and business logic stays testable. ## Core Features & Use Cases - Repository Pattern with GORM or sqlx: Define interfaces in the domain layer and swap GORM for sqlx implementations without touching services or handlers. - Connection Setup & Resilience: ConnectWithRetry with exponential backoff, connection pool tuning, and TLS/sslmode configuration for production. - Transactions, Pagination & Migrations: Context-based transaction propagation, cursor/keyset pagination, and golang-migrate workflows including zero-downtime patterns. - Use Case: You are building a Gin API and need a users table with CRUD endpoints. Use this Skill to scaffold the domain interface, a GORM repository with soft deletes and error mapping, migrations for the schema, and dependency injection wiring in main.go. ## Quick Start Ask the AI to add a PostgreSQL-backed user repository to your Gin project using GORM, with migrations and dependency injection in main.go.

Frequently Asked Questions about golang-gin-database

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

FAQPage Schema
How do I connect a Go Gin API to PostgreSQL?▼

Use GORM or sqlx with a DSN read from the DATABASE_URL environment variable, then configure the connection pool with MaxOpenConns, MaxIdleConns, and ConnMaxLifetime. For startup resilience, wrap the connection in a retry loop with exponential backoff since the database container may not be ready.

GORM vs sqlx: which should I use for a Go API?▼

GORM suits CRUD-heavy applications with its chainable ORM and quick setup, while sqlx gives full SQL control for complex queries via raw SQL and struct scanning. Both can implement the same repository interface, so you can swap them without changing service code.

How do I run database migrations in a Go project?▼

Use golang-migrate with versioned SQL files named like 000001_create_users_table.up.sql and a matching .down.sql file. Run migrations via the CLI or call the library on application startup, and use CONCURRENTLY for index creation in production to avoid table locks.

How do I handle transactions across repositories in GORM?▼

Store the *gorm.DB transaction in the request context with a WithTx helper, and have every repository method call txFromCtx instead of using the default connection. The service layer orchestrates the transaction while repositories participate transparently.

Why is offset pagination slow on large PostgreSQL tables?▼

OFFSET forces PostgreSQL to scan and skip rows, so performance degrades linearly at large offsets. Keyset (cursor) pagination filters on an indexed column like created_at instead, achieving O(log n) index seeks per page.

Does this skill cover authentication or API routing?▼

No, it is scoped to database integration only: repositories, queries, transactions, migrations, and Redis caching. Authentication, routing, deployment, and testing are handled by separate skills such as golang-gin-auth, golang-gin-api, and golang-gin-deploy.