feat: first version.
This commit is contained in:
31
entgo/mixin/uuid_id.go
Normal file
31
entgo/mixin/uuid_id.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package mixin
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
var _ ent.Mixin = (*UuidId)(nil)
|
||||
|
||||
type UuidId struct{ mixin.Schema }
|
||||
|
||||
func (UuidId) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Comment("id").
|
||||
Default(uuid.New).
|
||||
Unique().
|
||||
Immutable().
|
||||
StructTag(`json:"id,omitempty"`),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the UuidId.
|
||||
func (UuidId) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("id"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user