generated from GalvinGao/gofiber-template
/
user.go
47 lines (41 loc) · 1022 Bytes
/
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
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"exusiai.dev/roguestats-backend/internal/x/entid"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("id").
StorageKey("user_id").
Unique().
DefaultFunc(entid.NewGenerator("usr")).
Immutable(),
field.String("name").MaxLen(64),
field.String("email").Unique().Immutable(),
field.String("credential").MaxLen(64),
field.JSON("attributes", map[string]any{}).Optional(),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("events", Event.Type).
// Required().
Annotations(entsql.OnDelete(entsql.NoAction)),
}
}
// Annotations of the User.
func (User) Annotations() []schema.Annotation {
return []schema.Annotation{
// entgql.Mutations(entgql.MutationCreate()),
}
}