/
session.go
177 lines (163 loc) · 5.8 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Code generated by entc, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"github.com/blushft/strana/modules/sink/reporter/store/ent/session"
"github.com/facebook/ent/dialect/sql"
"github.com/google/uuid"
)
// Session is the model entity for the Session schema.
type Session struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// NewUser holds the value of the "new_user" field.
NewUser bool `json:"new_user,omitempty"`
// IsUnique holds the value of the "is_unique" field.
IsUnique bool `json:"is_unique,omitempty"`
// IsBounce holds the value of the "is_bounce" field.
IsBounce bool `json:"is_bounce,omitempty"`
// IsFinished holds the value of the "is_finished" field.
IsFinished bool `json:"is_finished,omitempty"`
// Duration holds the value of the "duration" field.
Duration int `json:"duration,omitempty"`
// StartedAt holds the value of the "started_at" field.
StartedAt time.Time `json:"started_at,omitempty"`
// FinishedAt holds the value of the "finished_at" field.
FinishedAt *time.Time `json:"finished_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the SessionQuery when eager-loading is set.
Edges SessionEdges `json:"edges"`
}
// SessionEdges holds the relations/edges for other nodes in the graph.
type SessionEdges struct {
// Events holds the value of the events edge.
Events []*Event
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// EventsOrErr returns the Events value or an error if the edge
// was not loaded in eager-loading.
func (e SessionEdges) EventsOrErr() ([]*Event, error) {
if e.loadedTypes[0] {
return e.Events, nil
}
return nil, &NotLoadedError{edge: "events"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Session) scanValues() []interface{} {
return []interface{}{
&uuid.UUID{}, // id
&sql.NullBool{}, // new_user
&sql.NullBool{}, // is_unique
&sql.NullBool{}, // is_bounce
&sql.NullBool{}, // is_finished
&sql.NullInt64{}, // duration
&sql.NullTime{}, // started_at
&sql.NullTime{}, // finished_at
}
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Session fields.
func (s *Session) assignValues(values ...interface{}) error {
if m, n := len(values), len(session.Columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
if value, ok := values[0].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[0])
} else if value != nil {
s.ID = *value
}
values = values[1:]
if value, ok := values[0].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field new_user", values[0])
} else if value.Valid {
s.NewUser = value.Bool
}
if value, ok := values[1].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_unique", values[1])
} else if value.Valid {
s.IsUnique = value.Bool
}
if value, ok := values[2].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_bounce", values[2])
} else if value.Valid {
s.IsBounce = value.Bool
}
if value, ok := values[3].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_finished", values[3])
} else if value.Valid {
s.IsFinished = value.Bool
}
if value, ok := values[4].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field duration", values[4])
} else if value.Valid {
s.Duration = int(value.Int64)
}
if value, ok := values[5].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field started_at", values[5])
} else if value.Valid {
s.StartedAt = value.Time
}
if value, ok := values[6].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field finished_at", values[6])
} else if value.Valid {
s.FinishedAt = new(time.Time)
*s.FinishedAt = value.Time
}
return nil
}
// QueryEvents queries the events edge of the Session.
func (s *Session) QueryEvents() *EventQuery {
return (&SessionClient{config: s.config}).QueryEvents(s)
}
// Update returns a builder for updating this Session.
// Note that, you need to call Session.Unwrap() before calling this method, if this Session
// was returned from a transaction, and the transaction was committed or rolled back.
func (s *Session) Update() *SessionUpdateOne {
return (&SessionClient{config: s.config}).UpdateOne(s)
}
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
// so that all next queries will be executed through the driver which created the transaction.
func (s *Session) Unwrap() *Session {
tx, ok := s.config.driver.(*txDriver)
if !ok {
panic("ent: Session is not a transactional entity")
}
s.config.driver = tx.drv
return s
}
// String implements the fmt.Stringer.
func (s *Session) String() string {
var builder strings.Builder
builder.WriteString("Session(")
builder.WriteString(fmt.Sprintf("id=%v", s.ID))
builder.WriteString(", new_user=")
builder.WriteString(fmt.Sprintf("%v", s.NewUser))
builder.WriteString(", is_unique=")
builder.WriteString(fmt.Sprintf("%v", s.IsUnique))
builder.WriteString(", is_bounce=")
builder.WriteString(fmt.Sprintf("%v", s.IsBounce))
builder.WriteString(", is_finished=")
builder.WriteString(fmt.Sprintf("%v", s.IsFinished))
builder.WriteString(", duration=")
builder.WriteString(fmt.Sprintf("%v", s.Duration))
builder.WriteString(", started_at=")
builder.WriteString(s.StartedAt.Format(time.ANSIC))
if v := s.FinishedAt; v != nil {
builder.WriteString(", finished_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteByte(')')
return builder.String()
}
// Sessions is a parsable slice of Session.
type Sessions []*Session
func (s Sessions) config(cfg config) {
for _i := range s {
s[_i].config = cfg
}
}