What problem does it solve?
Reusable query conditions in GORM often get duplicated across handlers and models, making maintenance error-prone and inconsistent; this Skill consolidates query logic into composable scope functions to enforce consistent filtering, pagination, and routing across an application.
Core Features & Use Cases
- Reusable Scopes: Define functions that accept and return *gorm.DB to encapsulate common WHERE, JOIN, and ORDER conditions for reuse.
- Parameterized Scopes: Create closure-based scopes to accept dynamic values for statuses, amounts, tenant IDs, and date ranges.
- Pagination & Composition: Provide a single pagination pattern and combine multiple scopes to build complex queries without duplicating logic.
- Dynamic Table Routing & Multi-Tenancy: Swap table names or schemas at runtime for sharding or multi-org data separation.
- Update/Delete Safety: Apply row-level constraints as scopes to safely restrict update and delete operations by organization or tenant.
Quick Start
Create parameterized GORM scopes for pagination and tenant isolation and show example usage combining them with db.Scopes to query orders.