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.

53 lines
1.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/mixins"
"git.noahlan.cn/noahlan/ntool/nrandom"
)
type Dictionary struct {
ent.Schema
}
func (Dictionary) Fields() []ent.Field {
return []ent.Field{
field.String("title").
Comment("The title shown in the ui | 展示名称 建议配合i18n"),
field.String("name").Unique().
Comment("The name of dictionary for search | 字典搜索名称"),
field.String("description").
Comment("The description of dictionary | 字典的描述").
Optional(),
}
}
func (Dictionary) Mixin() []ent.Mixin {
return []ent.Mixin{
mixins.NewDistributedIDMixin(func() int64 { return nrandom.SnowflakeId() }),
mixins.TimeMixin{},
mixins.StatusMixin{},
mixins.OptimisticLockMixin{},
}
}
func (Dictionary) Edges() []ent.Edge {
return []ent.Edge{
// one to many
edge.To("details", DictionaryDetail.Type).
Annotations(entsql.OnDelete(entsql.Cascade)),
}
}
func (Dictionary) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.WithComments(true),
entsql.Annotation{Table: "sys_dictionary"},
schema.Comment("字典表"),
}
}