/
task.go
280 lines (259 loc) · 9.04 KB
/
task.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// Code generated by entc, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"github.com/DanielTitkov/tinig-demo-server/internal/domain"
"github.com/DanielTitkov/tinig-demo-server/internal/repository/entgo/ent/task"
"github.com/DanielTitkov/tinig-demo-server/internal/repository/entgo/ent/tasktype"
"github.com/DanielTitkov/tinig-demo-server/internal/repository/entgo/ent/user"
"github.com/facebook/ent/dialect/sql"
)
// Task is the model entity for the Task schema.
type Task struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// CreateTime holds the value of the "create_time" field.
CreateTime time.Time `json:"create_time,omitempty"`
// UpdateTime holds the value of the "update_time" field.
UpdateTime time.Time `json:"update_time,omitempty"`
// Slug holds the value of the "slug" field.
Slug string `json:"slug,omitempty"`
// Title holds the value of the "title" field.
Title string `json:"title,omitempty"`
// Description holds the value of the "description" field.
Description string `json:"description,omitempty"`
// Code holds the value of the "code" field.
Code string `json:"code,omitempty"`
// Active holds the value of the "active" field.
Active bool `json:"active,omitempty"`
// DeleteTime holds the value of the "delete_time" field.
DeleteTime time.Time `json:"delete_time,omitempty"`
// Params holds the value of the "params" field.
Params domain.TaskParams `json:"params,omitempty"`
// Meta holds the value of the "meta" field.
Meta domain.TaskMeta `json:"meta,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the TaskQuery when eager-loading is set.
Edges TaskEdges `json:"edges"`
task_type_tasks *int
user_tasks *int
}
// TaskEdges holds the relations/edges for other nodes in the graph.
type TaskEdges struct {
// Items holds the value of the items edge.
Items []*Item
// User holds the value of the user edge.
User *User
// Type holds the value of the type edge.
Type *TaskType
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
}
// ItemsOrErr returns the Items value or an error if the edge
// was not loaded in eager-loading.
func (e TaskEdges) ItemsOrErr() ([]*Item, error) {
if e.loadedTypes[0] {
return e.Items, nil
}
return nil, &NotLoadedError{edge: "items"}
}
// UserOrErr returns the User value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TaskEdges) UserOrErr() (*User, error) {
if e.loadedTypes[1] {
if e.User == nil {
// The edge user was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: user.Label}
}
return e.User, nil
}
return nil, &NotLoadedError{edge: "user"}
}
// TypeOrErr returns the Type value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TaskEdges) TypeOrErr() (*TaskType, error) {
if e.loadedTypes[2] {
if e.Type == nil {
// The edge type was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: tasktype.Label}
}
return e.Type, nil
}
return nil, &NotLoadedError{edge: "type"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Task) scanValues() []interface{} {
return []interface{}{
&sql.NullInt64{}, // id
&sql.NullTime{}, // create_time
&sql.NullTime{}, // update_time
&sql.NullString{}, // slug
&sql.NullString{}, // title
&sql.NullString{}, // description
&sql.NullString{}, // code
&sql.NullBool{}, // active
&sql.NullTime{}, // delete_time
&[]byte{}, // params
&[]byte{}, // meta
}
}
// fkValues returns the types for scanning foreign-keys values from sql.Rows.
func (*Task) fkValues() []interface{} {
return []interface{}{
&sql.NullInt64{}, // task_type_tasks
&sql.NullInt64{}, // user_tasks
}
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Task fields.
func (t *Task) assignValues(values ...interface{}) error {
if m, n := len(values), len(task.Columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
value, ok := values[0].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
t.ID = int(value.Int64)
values = values[1:]
if value, ok := values[0].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field create_time", values[0])
} else if value.Valid {
t.CreateTime = value.Time
}
if value, ok := values[1].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field update_time", values[1])
} else if value.Valid {
t.UpdateTime = value.Time
}
if value, ok := values[2].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field slug", values[2])
} else if value.Valid {
t.Slug = value.String
}
if value, ok := values[3].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[3])
} else if value.Valid {
t.Title = value.String
}
if value, ok := values[4].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[4])
} else if value.Valid {
t.Description = value.String
}
if value, ok := values[5].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field code", values[5])
} else if value.Valid {
t.Code = value.String
}
if value, ok := values[6].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field active", values[6])
} else if value.Valid {
t.Active = value.Bool
}
if value, ok := values[7].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field delete_time", values[7])
} else if value.Valid {
t.DeleteTime = value.Time
}
if value, ok := values[8].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field params", values[8])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &t.Params); err != nil {
return fmt.Errorf("unmarshal field params: %v", err)
}
}
if value, ok := values[9].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field meta", values[9])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &t.Meta); err != nil {
return fmt.Errorf("unmarshal field meta: %v", err)
}
}
values = values[10:]
if len(values) == len(task.ForeignKeys) {
if value, ok := values[0].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field task_type_tasks", value)
} else if value.Valid {
t.task_type_tasks = new(int)
*t.task_type_tasks = int(value.Int64)
}
if value, ok := values[1].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field user_tasks", value)
} else if value.Valid {
t.user_tasks = new(int)
*t.user_tasks = int(value.Int64)
}
}
return nil
}
// QueryItems queries the items edge of the Task.
func (t *Task) QueryItems() *ItemQuery {
return (&TaskClient{config: t.config}).QueryItems(t)
}
// QueryUser queries the user edge of the Task.
func (t *Task) QueryUser() *UserQuery {
return (&TaskClient{config: t.config}).QueryUser(t)
}
// QueryType queries the type edge of the Task.
func (t *Task) QueryType() *TaskTypeQuery {
return (&TaskClient{config: t.config}).QueryType(t)
}
// Update returns a builder for updating this Task.
// Note that, you need to call Task.Unwrap() before calling this method, if this Task
// was returned from a transaction, and the transaction was committed or rolled back.
func (t *Task) Update() *TaskUpdateOne {
return (&TaskClient{config: t.config}).UpdateOne(t)
}
// 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 (t *Task) Unwrap() *Task {
tx, ok := t.config.driver.(*txDriver)
if !ok {
panic("ent: Task is not a transactional entity")
}
t.config.driver = tx.drv
return t
}
// String implements the fmt.Stringer.
func (t *Task) String() string {
var builder strings.Builder
builder.WriteString("Task(")
builder.WriteString(fmt.Sprintf("id=%v", t.ID))
builder.WriteString(", create_time=")
builder.WriteString(t.CreateTime.Format(time.ANSIC))
builder.WriteString(", update_time=")
builder.WriteString(t.UpdateTime.Format(time.ANSIC))
builder.WriteString(", slug=")
builder.WriteString(t.Slug)
builder.WriteString(", title=")
builder.WriteString(t.Title)
builder.WriteString(", description=")
builder.WriteString(t.Description)
builder.WriteString(", code=")
builder.WriteString(t.Code)
builder.WriteString(", active=")
builder.WriteString(fmt.Sprintf("%v", t.Active))
builder.WriteString(", delete_time=")
builder.WriteString(t.DeleteTime.Format(time.ANSIC))
builder.WriteString(", params=")
builder.WriteString(fmt.Sprintf("%v", t.Params))
builder.WriteString(", meta=")
builder.WriteString(fmt.Sprintf("%v", t.Meta))
builder.WriteByte(')')
return builder.String()
}
// Tasks is a parsable slice of Task.
type Tasks []*Task
func (t Tasks) config(cfg config) {
for _i := range t {
t[_i].config = cfg
}
}