forked from rdeusser/contrib
/
todo.go
357 lines (334 loc) · 12 KB
/
todo.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// Copyright 2019-present Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by entc, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/contrib/entgql/internal/todo/ent/schema/customstruct"
"entgo.io/contrib/entgql/internal/todopulid/ent/category"
"entgo.io/contrib/entgql/internal/todopulid/ent/schema/pulid"
"entgo.io/contrib/entgql/internal/todopulid/ent/todo"
"entgo.io/contrib/entgql/internal/todopulid/ent/verysecret"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Todo is the model entity for the Todo schema.
type Todo struct {
config `json:"-"`
// ID of the ent.
ID pulid.ID `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// Status holds the value of the "status" field.
Status todo.Status `json:"status,omitempty"`
// Priority holds the value of the "priority" field.
Priority int `json:"priority,omitempty"`
// Text holds the value of the "text" field.
Text string `json:"text,omitempty"`
// Blob holds the value of the "blob" field.
Blob []byte `json:"blob,omitempty"`
// Init holds the value of the "init" field.
Init map[string]interface{} `json:"init,omitempty"`
// Custom holds the value of the "custom" field.
Custom []customstruct.Custom `json:"custom,omitempty"`
// Customp holds the value of the "customp" field.
Customp []*customstruct.Custom `json:"customp,omitempty"`
// CategoryID holds the value of the "category_id" field.
CategoryID pulid.ID `json:"category_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the TodoQuery when eager-loading is set.
Edges TodoEdges `json:"edges"`
todo_children *pulid.ID
todo_secret *pulid.ID
selectValues sql.SelectValues
}
// TodoEdges holds the relations/edges for other nodes in the graph.
type TodoEdges struct {
// Parent holds the value of the parent edge.
Parent *Todo `json:"parent,omitempty"`
// Children holds the value of the children edge.
Children []*Todo `json:"children,omitempty"`
// Category holds the value of the category edge.
Category *Category `json:"category,omitempty"`
// Secret holds the value of the secret edge.
Secret *VerySecret `json:"secret,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [4]bool
// totalCount holds the count of the edges above.
totalCount [3]map[string]int
namedChildren map[string][]*Todo
}
// ParentOrErr returns the Parent value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TodoEdges) ParentOrErr() (*Todo, error) {
if e.loadedTypes[0] {
if e.Parent == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: todo.Label}
}
return e.Parent, nil
}
return nil, &NotLoadedError{edge: "parent"}
}
// ChildrenOrErr returns the Children value or an error if the edge
// was not loaded in eager-loading.
func (e TodoEdges) ChildrenOrErr() ([]*Todo, error) {
if e.loadedTypes[1] {
return e.Children, nil
}
return nil, &NotLoadedError{edge: "children"}
}
// CategoryOrErr returns the Category value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TodoEdges) CategoryOrErr() (*Category, error) {
if e.loadedTypes[2] {
if e.Category == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: category.Label}
}
return e.Category, nil
}
return nil, &NotLoadedError{edge: "category"}
}
// SecretOrErr returns the Secret value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TodoEdges) SecretOrErr() (*VerySecret, error) {
if e.loadedTypes[3] {
if e.Secret == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: verysecret.Label}
}
return e.Secret, nil
}
return nil, &NotLoadedError{edge: "secret"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Todo) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case todo.FieldBlob, todo.FieldInit, todo.FieldCustom, todo.FieldCustomp:
values[i] = new([]byte)
case todo.FieldID, todo.FieldCategoryID:
values[i] = new(pulid.ID)
case todo.FieldPriority:
values[i] = new(sql.NullInt64)
case todo.FieldStatus, todo.FieldText:
values[i] = new(sql.NullString)
case todo.FieldCreatedAt:
values[i] = new(sql.NullTime)
case todo.ForeignKeys[0]: // todo_children
values[i] = &sql.NullScanner{S: new(pulid.ID)}
case todo.ForeignKeys[1]: // todo_secret
values[i] = &sql.NullScanner{S: new(pulid.ID)}
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Todo fields.
func (t *Todo) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case todo.FieldID:
if value, ok := values[i].(*pulid.ID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
t.ID = *value
}
case todo.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
t.CreatedAt = value.Time
}
case todo.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
t.Status = todo.Status(value.String)
}
case todo.FieldPriority:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field priority", values[i])
} else if value.Valid {
t.Priority = int(value.Int64)
}
case todo.FieldText:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field text", values[i])
} else if value.Valid {
t.Text = value.String
}
case todo.FieldBlob:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field blob", values[i])
} else if value != nil {
t.Blob = *value
}
case todo.FieldInit:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field init", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &t.Init); err != nil {
return fmt.Errorf("unmarshal field init: %w", err)
}
}
case todo.FieldCustom:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field custom", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &t.Custom); err != nil {
return fmt.Errorf("unmarshal field custom: %w", err)
}
}
case todo.FieldCustomp:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field customp", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &t.Customp); err != nil {
return fmt.Errorf("unmarshal field customp: %w", err)
}
}
case todo.FieldCategoryID:
if value, ok := values[i].(*pulid.ID); !ok {
return fmt.Errorf("unexpected type %T for field category_id", values[i])
} else if value != nil {
t.CategoryID = *value
}
case todo.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field todo_children", values[i])
} else if value.Valid {
t.todo_children = new(pulid.ID)
*t.todo_children = *value.S.(*pulid.ID)
}
case todo.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field todo_secret", values[i])
} else if value.Valid {
t.todo_secret = new(pulid.ID)
*t.todo_secret = *value.S.(*pulid.ID)
}
default:
t.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Todo.
// This includes values selected through modifiers, order, etc.
func (t *Todo) Value(name string) (ent.Value, error) {
return t.selectValues.Get(name)
}
// QueryParent queries the "parent" edge of the Todo entity.
func (t *Todo) QueryParent() *TodoQuery {
return NewTodoClient(t.config).QueryParent(t)
}
// QueryChildren queries the "children" edge of the Todo entity.
func (t *Todo) QueryChildren() *TodoQuery {
return NewTodoClient(t.config).QueryChildren(t)
}
// QueryCategory queries the "category" edge of the Todo entity.
func (t *Todo) QueryCategory() *CategoryQuery {
return NewTodoClient(t.config).QueryCategory(t)
}
// QuerySecret queries the "secret" edge of the Todo entity.
func (t *Todo) QuerySecret() *VerySecretQuery {
return NewTodoClient(t.config).QuerySecret(t)
}
// Update returns a builder for updating this Todo.
// Note that you need to call Todo.Unwrap() before calling this method if this Todo
// was returned from a transaction, and the transaction was committed or rolled back.
func (t *Todo) Update() *TodoUpdateOne {
return NewTodoClient(t.config).UpdateOne(t)
}
// Unwrap unwraps the Todo entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (t *Todo) Unwrap() *Todo {
_tx, ok := t.config.driver.(*txDriver)
if !ok {
panic("ent: Todo is not a transactional entity")
}
t.config.driver = _tx.drv
return t
}
// String implements the fmt.Stringer.
func (t *Todo) String() string {
var builder strings.Builder
builder.WriteString("Todo(")
builder.WriteString(fmt.Sprintf("id=%v, ", t.ID))
builder.WriteString("created_at=")
builder.WriteString(t.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", t.Status))
builder.WriteString(", ")
builder.WriteString("priority=")
builder.WriteString(fmt.Sprintf("%v", t.Priority))
builder.WriteString(", ")
builder.WriteString("text=")
builder.WriteString(t.Text)
builder.WriteString(", ")
builder.WriteString("blob=")
builder.WriteString(fmt.Sprintf("%v", t.Blob))
builder.WriteString(", ")
builder.WriteString("init=")
builder.WriteString(fmt.Sprintf("%v", t.Init))
builder.WriteString(", ")
builder.WriteString("custom=")
builder.WriteString(fmt.Sprintf("%v", t.Custom))
builder.WriteString(", ")
builder.WriteString("customp=")
builder.WriteString(fmt.Sprintf("%v", t.Customp))
builder.WriteString(", ")
builder.WriteString("category_id=")
builder.WriteString(fmt.Sprintf("%v", t.CategoryID))
builder.WriteByte(')')
return builder.String()
}
// NamedChildren returns the Children named value or an error if the edge was not
// loaded in eager-loading with this name.
func (t *Todo) NamedChildren(name string) ([]*Todo, error) {
if t.Edges.namedChildren == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := t.Edges.namedChildren[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (t *Todo) appendNamedChildren(name string, edges ...*Todo) {
if t.Edges.namedChildren == nil {
t.Edges.namedChildren = make(map[string][]*Todo)
}
if len(edges) == 0 {
t.Edges.namedChildren[name] = []*Todo{}
} else {
t.Edges.namedChildren[name] = append(t.Edges.namedChildren[name], edges...)
}
}
// Todos is a parsable slice of Todo.
type Todos []*Todo