|
|
|
@ -9,26 +9,52 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TimeMixin implements the ent.Mixin for sharing
|
|
|
|
|
// time fields with package schemas.
|
|
|
|
|
// all time fields with package schemas.
|
|
|
|
|
type TimeMixin struct {
|
|
|
|
|
mixin.Schema
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (TimeMixin) Fields() []ent.Field {
|
|
|
|
|
return append(
|
|
|
|
|
CreateTimeMixin{}.Fields(),
|
|
|
|
|
UpdateTimeMixin{}.Fields()...,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateTimeMixin implements the ent.Mixin for sharing
|
|
|
|
|
// time fields with package schemas.
|
|
|
|
|
type CreateTimeMixin struct {
|
|
|
|
|
mixin.Schema
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fields of the create-time mixin.
|
|
|
|
|
func (CreateTimeMixin) Fields() []ent.Field {
|
|
|
|
|
return []ent.Field{
|
|
|
|
|
field.Time("created_at").
|
|
|
|
|
Immutable().
|
|
|
|
|
Default(time.Now).
|
|
|
|
|
Immutable().
|
|
|
|
|
SchemaType(map[string]string{
|
|
|
|
|
dialect.MySQL: "datetime",
|
|
|
|
|
}).
|
|
|
|
|
Comment("创建时间"),
|
|
|
|
|
Comment("Create Time | 创建时间"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateTimeMixin implements the ent.Mixin for sharing
|
|
|
|
|
// time fields with package schemas.
|
|
|
|
|
type UpdateTimeMixin struct {
|
|
|
|
|
mixin.Schema
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fields of the update-time mixin.
|
|
|
|
|
func (UpdateTimeMixin) Fields() []ent.Field {
|
|
|
|
|
return []ent.Field{
|
|
|
|
|
field.Time("updated_at").
|
|
|
|
|
Default(time.Now).
|
|
|
|
|
UpdateDefault(time.Now).
|
|
|
|
|
SchemaType(map[string]string{
|
|
|
|
|
dialect.MySQL: "datetime",
|
|
|
|
|
}).
|
|
|
|
|
Comment("更新时间"),
|
|
|
|
|
Comment("Update Time | 更新时间"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|