gorm-delete

Delete GORM records by primary key, conditions, or Unscoped for hard deletes.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill covers deletion of records in GORM, including single-record deletions, deletions by primary key, batch deletions, soft deletes, and permanent deletes, with support for delete hooks.

Core Features & Use Cases

  • Delete a single record by primary key or by providing the model instance.
  • Batch delete with conditions using Where.
  • Soft delete support with DeletedAt fields and Unscoped for hard deletes.
  • Delete hooks for BeforeDelete and AfterDelete to enforce business rules.
  • Find and manage soft-deleted records to restore or permanently remove when needed.

Quick Start

Set up a model, connect to the database, and run Delete on a specific primary key or filtered query to observe the behavior.

Frequently Asked Questions about gorm-delete

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

FAQPage Schema
How do I delete a record by primary key in GORM?

To delete a record by primary key in GORM, pass the model instance or the primary key value directly to the Delete method. This removes the corresponding row from your database table.

What is soft delete in GORM and how does it work?

Soft delete in GORM marks records as deleted by setting a DeletedAt timestamp instead of removing the row. Queries automatically exclude these soft-deleted entries unless you explicitly use Unscoped.

How do I permanently delete soft-deleted records using GORM?

To permanently delete soft-deleted records, use Unscoped before calling Delete. This bypasses the soft delete mechanism and performs a hard delete, physically removing the record from the database.

Can I batch delete records with conditions in GORM?

You can batch delete records in GORM by chaining Where conditions with the Delete method. This allows you to remove multiple rows matching specific criteria in a single database operation.

Does GORM support hooks for delete operations?

GORM supports BeforeDelete and AfterDelete hooks to enforce business rules during deletion. These callbacks execute automatically before or after a delete operation, allowing custom logic validation.

Why are my soft-deleted records still appearing in GORM queries?

Soft-deleted records appear if you use Unscoped in your GORM queries. To exclude them, use standard query methods without Unscoped, which automatically filter out rows with a non-null DeletedAt value.