gorm-settings

Pass contextual values into GORM hooks and migration statements.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provides a scoped, operation-level mechanism to pass metadata such as audit user IDs, tenant identifiers, or migration options into GORM operations and hooks so you do not rely on global state or ad-hoc context passing.

Core Features & Use Cases

  • Set and Get values that propagate into all hooks, including nested association hooks, enabling audit trails and conditional hook behavior.
  • InstanceSet and InstanceGet for statement-scoped values that do not propagate to association hooks, useful for per-model transformations or temporary values.
  • Set table options during migrations to configure database engine or table comments for MySQL/MariaDB.
  • Common uses include audit logging, tenant isolation, skipping or toggling hook logic, and passing migration configuration.

Quick Start

Set an audit_user using db.Set before creating a model so the BeforeCreate hook can read and record the audit_user.

Frequently Asked Questions about gorm-settings

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

FAQPage Schema
How do I pass context data into GORM hooks for audit trails?

To pass context data into GORM hooks for audit trails, use the Set method to propagate values like user IDs into all operations, including nested association hooks. This enables per-operation metadata without relying on global state.

What is the difference between Set and InstanceSet in GORM operations?

Set propagates contextual values into all hooks including nested associations, while InstanceSet applies statement-scoped values that do not propagate to association hooks, making it useful for temporary per-model transformations.

How do I configure table options for GORM migrations across nested associations?

To configure table options for GORM migrations across nested associations, set the gorm:table_options key with your desired string values. This allows you to specify database engines or table comments for MySQL and MariaDB.

Can I achieve tenant isolation in GORM without using global state?

Yes, you can achieve tenant isolation in GORM without global state by using Set to pass tenant identifiers into your operations. The values propagate through hooks, allowing you to enforce tenant boundaries on a per-operation basis.

Does this GORM settings approach work for skipping or toggling hook logic?

Yes, this GORM settings approach works for skipping or toggling hook logic. By passing conditional flags via Set or InstanceSet, your hooks can read these values and dynamically alter their execution behavior per statement.

When should I use statement-scoped values instead of propagated values in GORM?

Use statement-scoped values via InstanceGet when you need temporary data for per-model transformations without affecting nested association hooks. Use propagated values via Get when metadata must cascade across all related operations.