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.
ntool-biz/core/orm/nent/mixins/uuid.go

26 lines
542 B
Go

1 year ago
package mixins
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
"git.noahlan.cn/noahlan/ntool/nrandom"
"github.com/gofrs/uuid/v5"
)
// UUIDMixin implements the ent.Mixin for sharing
// UUID fields with package schemas.
type UUIDMixin struct {
// We embed the `mixin.Schema` to avoid
// implementing the rest of the methods.
mixin.Schema
}
func (UUIDMixin) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(nrandom.NewUUIDV7).
Comment("唯一IDUUID"),
}
}