You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
820 B
Go
35 lines
820 B
Go
1 year ago
|
package mixins
|
||
|
|
||
|
import (
|
||
|
"entgo.io/ent"
|
||
|
"entgo.io/ent/dialect"
|
||
|
"entgo.io/ent/schema/field"
|
||
|
"entgo.io/ent/schema/mixin"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// TimeMixin implements the ent.Mixin for sharing
|
||
|
// time fields with package schemas.
|
||
|
type TimeMixin struct {
|
||
|
mixin.Schema
|
||
|
}
|
||
|
|
||
|
func (TimeMixin) Fields() []ent.Field {
|
||
|
return []ent.Field{
|
||
|
field.Time("created_at").
|
||
|
Immutable().
|
||
|
Default(time.Now).
|
||
|
SchemaType(map[string]string{
|
||
|
dialect.MySQL: "datetime",
|
||
|
}).
|
||
|
Comment("创建时间"),
|
||
|
field.Time("updated_at").
|
||
|
Default(time.Now).
|
||
|
UpdateDefault(time.Now).
|
||
|
SchemaType(map[string]string{
|
||
|
dialect.MySQL: "datetime",
|
||
|
}).
|
||
|
Comment("更新时间"),
|
||
|
}
|
||
|
}
|