gorm-create

Insert and upsert database records with GORM using OnConflict clauses.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill helps Go developers reliably insert and manage database records using GORM, reducing errors and boilerplate when performing single inserts, batch imports, upserts, and association handling.

Core Features & Use Cases

  • Single record insertion with pointer-backed structs and returned primary keys.
  • Batch insertion and CreateInBatches configuration for efficient large imports.
  • Field selection and omission to control which columns are inserted.
  • Map-based creation for dynamic inserts without invoking hooks or saving associations.
  • Association handling with options to include or skip associations and hook control for performance-sensitive workflows.
  • Upsert support via OnConflict clauses to perform DoNothing, update specific columns, or update all columns on conflict. Use case: perform a bulk import of user records with batched inserts while skipping hooks for performance, or perform idempotent upserts to avoid duplicate rows.

Quick Start

Insert a new user record with name Jinzhu and age 18 and return the inserted ID and any error.

Frequently Asked Questions about gorm-create

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

FAQPage Schema
How do I insert and upsert database records reliably with GORM in Go?

Insert and upsert database records reliably with GORM by using pointer-backed structs for single inserts, CreateInBatches for bulk imports, and OnConflict clauses for idempotent upserts. This approach ensures reliable persistence while reducing boilerplate and errors.

What is the best way to perform bulk imports in GORM while skipping hooks for performance?

The best way to perform bulk imports in GORM is using CreateInBatches, which allows efficient batch insertion. You can skip hooks and associations during map-based creation to optimize performance-sensitive workflows and avoid unnecessary overhead.

How does GORM handle OnConflict upsert scenarios for avoiding duplicate rows?

GORM handles OnConflict upsert scenarios by applying clauses for conflict resolution. You can configure the upsert to DoNothing, update specific columns, or update all columns on conflict, ensuring idempotent operations that avoid duplicate rows in the database.

Can I control which columns are inserted using GORM?

Yes, you can control which columns are inserted using GORM through field selection and omission. This allows you to specify exactly which columns to include or exclude during insertion, providing precise control over the persisted data and default value handling.

Does GORM support association handling during record insertion?

Yes, GORM supports association handling during record insertion with options to include or skip associations. You can also use map-based creation for dynamic inserts without invoking hooks or saving associations, giving you control over the persistence workflow.

When should I not use hooks during GORM batch inserts?

You should skip hooks during GORM batch inserts when working with performance-sensitive workflows or performing large data imports. Map-based creation bypasses hooks entirely, making it ideal for efficient bulk operations where association saving is unnecessary.