From e3541ac9ea0d8c461cee782600e68137e78f39d7 Mon Sep 17 00:00:00 2001 From: molon <3739161+molon@users.noreply.github.com> Date: Thu, 20 Nov 2025 23:18:56 +0800 Subject: [PATCH] gormx: Add HardDeleteModel with BeforeCreate hook for UUID generation --- gormx/model.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gormx/model.go b/gormx/model.go index 77a19b6b..832021ad 100644 --- a/gormx/model.go +++ b/gormx/model.go @@ -22,3 +22,16 @@ func (m *Model) BeforeCreate(_ *gorm.DB) error { } return nil } + +type HardDeleteModel struct { + ID string `gorm:"size:36;primaryKey" json:"id"` + CreatedAt time.Time `gorm:"not null" json:"createdAt"` + UpdatedAt time.Time `gorm:"not null" json:"updatedAt"` +} + +func (m *HardDeleteModel) BeforeCreate(_ *gorm.DB) error { + if m.ID == "" { + m.ID = uuid.NewString() + } + return nil +}