gorm-dbresolver

Route GORM reads to replicas and writes to primary databases.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/liurida/gorm-development-skill --skill gorm-dbresolver
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gorm-dbresolver
Source: https://github.com/liurida/gorm-development-skill/tree/main/dbresolver
Command: npx skills add https://github.com/liurida/gorm-development-skill --skill gorm-dbresolver

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

GORM applications that need to scale with multiple databases often struggle to manually manage read/write routing, connection switching, and load balancing, leading to complex and error‑prone code.

Core Features & Use Cases

  • Automatic routing: Writes automatically go to source databases while reads are distributed among replicas.
  • Manual overrides: Developers can force reads or writes on specific connections using provided clauses.
  • Transaction consistency: All operations within a transaction use the same connection, preventing accidental switching.
  • Multiple resolver configurations: Different models or tables can be assigned to distinct resolver groups for sharding or domain separation.
  • Custom load‑balancing policies: Plug in custom algorithms like round‑robin or weighted distribution for replica selection.

Quick Start

Configure GORM with the dbresolver plugin to route writes to the primary database and reads to replica databases.

Frequently Asked Questions about gorm-dbresolver

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

FAQPage Schema
How do I set up read-write splitting across multiple database replicas in GORM?

Read-write splitting in GORM is configured by registering the dbresolver plugin with primary source and replica dialectors, enabling automatic routing of writes to primary databases and reads to replicas.

Can I use custom load balancing policies for distributing reads among database replicas?

Yes, you can plug in custom load balancing policies for replica selection, allowing algorithms like round-robin or weighted distribution to control how reads are distributed across multiple database replicas.

Does GORM read-write splitting maintain transaction consistency across primary and replica connections?

Transaction consistency is maintained because all operations within a transaction use the same connection, preventing accidental connection switching between primary and replica databases during active transactions.

How do I force a read or write operation to a specific database connection in GORM?

You can manually override automatic routing by using provided clauses to force reads or writes on specific database connections, bypassing the default read-write splitting behavior when needed.

Can I assign different GORM models to separate database resolver groups for sharding?

Yes, different models or tables can be assigned to distinct resolver groups, enabling database sharding or domain separation by routing specific models to dedicated primary and replica database configurations.

Why should I use a dbresolver plugin instead of manually managing read/write routing in GORM?

Using dbresolver eliminates the complex and error-prone code required to manually manage read/write routing, connection switching, and load balancing across multiple databases in scalable GORM applications.