-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_model.go
55 lines (46 loc) · 2.07 KB
/
base_model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package g
import (
"github.com/khaosles/gtools2/utils/gen"
"gorm.io/gorm"
)
/*
@File: base_model.go
@Author: khaosles
@Time: 2023/6/11 11:10
@Desc: model 继承该类,则拥有常见基础属性,以及自动生成无分隔符的uuid
*/
type AuthMixin struct {
CreateBy string `json:"createBy,omitempty" gorm:"column:create_by;type:varchar(100);default:null;comment:创建人"` // 创建人
UpdateBy string `json:"updateBy,omitempty" gorm:"column:update_by;type:varchar(100);default:null;comment:更新人"` // 更新人
}
type PgTimeMixin struct {
CreateTime Timestamp `json:"createTime,omitempty" gorm:"autoCreateTime;column:create_time;type:timestamptz;comment:创建时间"` // 创建时间
UpdateTime Timestamp `json:"updateTime,omitempty" gorm:"autoUpdateTime;column:update_time;type:timestamptz;comment:更新时间"` // 更新时间
DeleteTime gorm.DeletedAt `json:"-" gorm:"index;column:delete_time;type:timestamptz;comment:删除时间"` // 删除标记
}
type TimeMixin struct {
CreateTime Timestamp `json:"createTime,omitempty" gorm:"autoCreateTime;column:create_time;type:datetime;comment:创建时间"` // 创建时间
UpdateTime Timestamp `json:"updateTime,omitempty" gorm:"autoUpdateTime;column:update_time;type:datetime;comment:更新时间"` // 更新时间
DeleteTime gorm.DeletedAt `json:"-" gorm:"index;column:delete_time;type:datetime;comment:删除时间"` // 删除标记
}
type IdMixin struct {
ID string `json:"id" gorm:"primaryKey;column:id;type:varchar(32);comment:主键"` // 主键ID
}
func (m *IdMixin) BeforeCreate(tx *gorm.DB) error {
//node, _ := snowflake.NewNode(0)
//m.ID = node.Generate().String()
m.ID = gen.UuidNoSeparator()
return nil
}
type BaseModel struct {
IdMixin
PgTimeMixin
AuthMixin
Remarks string `json:"remarks,omitempty" gorm:"column:remarks;default:null;comment:备注"` // 备注
}
type BaseModelNoPg struct {
IdMixin
TimeMixin
AuthMixin
Remarks string `json:"remarks,omitempty" gorm:"column:remarks;default:null;comment:备注"` // 备注
}