gorm-generics-api

Provide type-safe CRUD and query operations for GORM models using Go generics.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provides a type-safe, context-first alternative to the traditional GORM API to avoid SQL pollution from reused DB instances, reduce runtime type errors, and make CRUD and complex queries explicit and safer in Go projects.

Core Features & Use Cases

  • Type-safe CRUD: Create, read, update, and delete records with compile-time generics for model types.
  • Advanced queries, joins, and preload: Perform enhanced joins, nested preloads, per-record limits, and scoped queries while preserving strong typing.
  • Raw SQL and code generation: Run typed raw SQL queries and generate boilerplate query code using the GORM CLI to keep raw queries type-safe and maintainable.
  • Use Case: Migrate a codebase to generics to prevent accidental DB state reuse and to implement efficient preloads for a social app where Users have Friends and Pets.

Quick Start

Show me step-by-step how to perform create, query, update, delete, join, and preload operations for a User model using GORM generics with an active database connection.

Frequently Asked Questions about gorm-generics-api

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

FAQPage Schema
How do I perform type-safe CRUD operations with GORM in Go?

Type-safe GORM CRUD operations use Go 1.18+ generics to apply compile-time type checking to create, read, update, and delete database functions, preventing runtime type errors for your models.

How does GORM generics handle complex joins and nested preloads?

GORM generics handle complex joins and nested preloads by applying enhanced query functions that support per-record limits and scoped queries while preserving strict compile-time typing for related models.

Why does my GORM database instance cause SQL pollution from reused DB states?

SQL pollution from reused GORM database states happens when query chain contexts bleed into subsequent operations, which context-first generics APIs solve by making each CRUD operation explicit and isolated.

Can I execute raw SQL queries with compile-time type safety in GORM?

You can execute type-safe raw SQL queries in GORM by using the GORM CLI to generate typed boilerplate query code, ensuring your raw SQL statements maintain strong typing and maintainability.

What Go version is required to use generics for GORM type-safe queries?

Using generics for GORM type-safe queries requires Go 1.18 or newer for generics support, along with GORM v1.30.0 or newer and an initialized gorm DB connection.

What are the limitations of using Go generics for GORM database operations?

A key limitation is the strict dependency on Go 1.18+ and GORM v1.30.0+ environments, requiring an initialized gorm DB connection and optionally the GORM CLI to generate typed raw query code.