Files
go-utils/entgo/mixin/string_id.go
2023-11-01 18:23:12 +08:00

34 lines
550 B
Go

package mixin
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"entgo.io/ent/schema/mixin"
"regexp"
)
type StringId struct {
mixin.Schema
}
func (StringId) Fields() []ent.Field {
return []ent.Field{
field.String("id").
Comment("id").
MaxLen(25).
NotEmpty().
Unique().
Immutable().
Match(regexp.MustCompile("^[0-9a-zA-Z_\\-]+$")).
StructTag(`json:"id,omitempty"`),
}
}
// Indexes of the StringId.
func (StringId) Indexes() []ent.Index {
return []ent.Index{
index.Fields("id"),
}
}