添加软删除
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package gormx
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Common struct {
|
||||
// gorm.Model
|
||||
Id int64 `json:"id" gorm:"column:id;auto_increment;primary_key;comment:主键"`
|
||||
CreateTime int64 `json:"create_time" binding:"-" gorm:"type:bigint unsigned;column:create_time;default:0;not null;autoCreateTime:milli;comment:创建时间"`
|
||||
UpdateTime int64 `json:"update_time" binding:"-" gorm:"type:bigint unsigned;column:update_time;default:0;not null;autoCreateTime:milli;autoUpdateTime:milli;comment:更新时间"`
|
||||
// DeletedAt *time.Time `json:"delete_time" binding:"-" gorm:"index;type:bigint unsigned;column:delete_time;default:0;not null;comment:删除时间"`
|
||||
DeleteTime DeleteTime `json:"delete_time" binding:"-" gorm:"index;type:bigint unsigned;column:delete_time;default:0;not null;comment:删除时间"`
|
||||
// DeleteTime sql.NullInt64 `json:"delete_time" gorm:"index;type:bigint unsigned;column:delete_time;default:0;not null;comment:删除时间"`
|
||||
}
|
||||
|
||||
func (u *Common) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
u.CreateTime = time.Now().UnixMilli()
|
||||
u.UpdateTime = time.Now().UnixMilli()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Common) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
c.UpdateTime = time.Now().UnixMilli()
|
||||
return
|
||||
}
|
||||
|
||||
// Unscoped() 会忽略默认的软删除条件
|
||||
Reference in New Issue
Block a user