SoftDelete

module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2023 License: MIT

README

Soft Delete

Inspired gorm.io/plugin/soft_delete, No Mixed Mode

Go Reference

DeletedAt

  • use int64 save unix timestamp
  • support time type: nano, micro, milli, second
  • example:
import "gitlab.com/z2a-package/Go/Gorm/SoftDelete/DeletedAt"

type User struct {
  ID        uint
  Name      string
  DeletedAt DeletedAt.DeletedAt
//  DeletedAt DeletedAt.DeletedAt `gorm:"SoftDelete:Nano"`
//  DeletedAt DeletedAt.DeletedAt `gorm:"SoftDelete:Micro"`
//  DeletedAt DeletedAt.DeletedAt `gorm:"SoftDelete:Milli"`
}

// Query
SELECT * FROM users WHERE deleted_at = 0;

// Delete
UPDATE users SET deleted_at = /* current unix second */ WHERE ID = 1;

IsDeleted

  • use bool save deleted flag
  • example:
import "gitlab.com/z2a-package/Go/Gorm/SoftDelete/IsDeleted"

type User struct {
  ID        uint
  Name      string
  IsDeleted IsDeleted.IsDeleted
}

// Query
SELECT * FROM users WHERE is_deleted = 0;

// Delete
UPDATE users SET is_deleted = 1 WHERE ID = 1;

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL