feat(schema): 添加基础混入定义公共时间字段
This commit is contained in:
1 parent
5281459fcb
commit
fe86c081f4
16 files changed
+1715
-14
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
)
|
||||
|
||||
// BaseMixin 定义公共的基础混入
|
||||
type BaseMixin struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
// Fields 定义所有表都拥有的公共字段
|
||||
func (BaseMixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
// 创建时间:默认当前时间,不可修改(Immutable)
|
||||
field.Time("created_at").
|
||||
Default(time.Now).
|
||||
Immutable(),
|
||||
|
||||
// 更新时间:默认当前时间,并且在每次数据 Update 时自动更新为当前时间
|
||||
field.Time("updated_at").
|
||||
Default(time.Now).
|
||||
UpdateDefault(time.Now),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user