package mixins import ( "entgo.io/ent" "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema/field" "entgo.io/ent/schema/mixin" "git.noahlan.cn/noahlan/ntool/nstd/tea" ) // DistributedIDMixin implements the ent.Mixin for sharing // Distributed ID field with package schemas. type DistributedIDMixin struct { mixin.Schema idFn func() int64 } func NewDistributedIDMixin(defaultIDFunc func() int64) DistributedIDMixin { return DistributedIDMixin{ idFn: defaultIDFunc, } } func (d DistributedIDMixin) Fields() []ent.Field { return []ent.Field{ field.Int64("id"). Annotations(entsql.Annotation{Incremental: tea.Bool(false)}). DefaultFunc(d.idFn). Comment("Primary Key | 主键"), } } // DefaultIDMixin implements the ent.Mixin for sharing // ID field with package schemas. type DefaultIDMixin struct { mixin.Schema } func (DefaultIDMixin) Fields() []ent.Field { return []ent.Field{ field.Int64("id"). Default(1). Comment("Primary Key | 主键"), } }