-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
58 lines (52 loc) · 1.36 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package schema
import (
"entgo.io/contrib/entgql"
"entgo.io/contrib/entproto"
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"errors"
"github.com/shopspring/decimal"
"github.com/woocoos/entco/schemax"
"github.com/woocoos/entco/schemax/fieldx"
"time"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// annotation
func (User) Annotations() []schema.Annotation {
return []schema.Annotation{
entgql.QueryField("users"),
entgql.RelayConnection(),
entgql.Mutations(entgql.MutationCreate(), entgql.MutationUpdate()),
}
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("name").MaxLen(45).Comment("姓名"),
field.Time("created_at").Immutable().Default(time.Now).Immutable().
Annotations(entgql.OrderField("createdAt"), entgql.Skip(entgql.SkipMutationCreateInput),
entproto.Field(3)),
fieldx.Decimal("money").Precision(10, 6).Optional().
Range(decimal.NewFromInt(1), decimal.NewFromInt(100000)).
Comment("money").Nillable().Default(2).
Validate(func(d decimal.Decimal) error {
if d.Cmp(decimal.Zero) < 0 {
return errors.New("money can't be negative")
}
return nil
}),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return nil
}
func (User) Mixin() []ent.Mixin {
return []ent.Mixin{
schemax.NotifyMixin{},
}
}