-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_session.go
49 lines (41 loc) · 996 Bytes
/
user_session.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
package schema
import (
"time"
"entgo.io/ent/schema/index"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
)
// UserSession holds the schema definition for the UserSession entity.
type UserSession struct {
ent.Schema
}
// Fields of the UserSession.
func (UserSession) Fields() []ent.Field {
return []ent.Field{
field.String("sid").NotEmpty().Unique().Immutable(),
field.String("ip"),
field.String("user_agent"),
field.Time("last_activity").Default(time.Now),
field.Bool("active").Default(false),
field.JSON("meta", make(map[string]interface{})).Optional(),
}
}
// Edges of the UserSession.
func (UserSession) Edges() []ent.Edge {
return []ent.Edge{
// belongs to
edge.From("user", User.Type).Ref("sessions").Unique().Required(),
}
}
func (UserSession) Indexes() []ent.Index {
return []ent.Index{
index.Fields("active"),
}
}
func (UserSession) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Time{},
}
}