/
quest.go
308 lines (285 loc) · 10.1 KB
/
quest.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
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"realm.pub/tavern/internal/ent/file"
"realm.pub/tavern/internal/ent/quest"
"realm.pub/tavern/internal/ent/tome"
"realm.pub/tavern/internal/ent/user"
)
// Quest is the model entity for the Quest schema.
type Quest struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Timestamp of when this ent was created
CreatedAt time.Time `json:"created_at,omitempty"`
// Timestamp of when this ent was last updated
LastModifiedAt time.Time `json:"last_modified_at,omitempty"`
// Name of the quest
Name string `json:"name,omitempty"`
// Value of parameters that were specified for the quest (as a JSON string).
Parameters string `json:"parameters,omitempty"`
// JSON string describing what parameters are used with the tome at the time of this quest creation. Requires a list of JSON objects, one for each parameter.
ParamDefsAtCreation string `json:"param_defs_at_creation,omitempty"`
// Eldritch script that was evaluated at the time of this quest creation.
EldritchAtCreation string `json:"eldritch_at_creation,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the QuestQuery when eager-loading is set.
Edges QuestEdges `json:"edges"`
quest_tome *int
quest_bundle *int
quest_creator *int
selectValues sql.SelectValues
}
// QuestEdges holds the relations/edges for other nodes in the graph.
type QuestEdges struct {
// Tome that this quest will be executing
Tome *Tome `json:"tome,omitempty"`
// Bundle file that the executing tome depends on (if any)
Bundle *File `json:"bundle,omitempty"`
// Tasks tracking the status and output of individual tome execution on targets
Tasks []*Task `json:"tasks,omitempty"`
// User that created the quest if available.
Creator *User `json:"creator,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 [4]map[string]int
namedTasks map[string][]*Task
}
// TomeOrErr returns the Tome value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e QuestEdges) TomeOrErr() (*Tome, error) {
if e.loadedTypes[0] {
if e.Tome == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: tome.Label}
}
return e.Tome, nil
}
return nil, &NotLoadedError{edge: "tome"}
}
// BundleOrErr returns the Bundle value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e QuestEdges) BundleOrErr() (*File, error) {
if e.loadedTypes[1] {
if e.Bundle == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: file.Label}
}
return e.Bundle, nil
}
return nil, &NotLoadedError{edge: "bundle"}
}
// TasksOrErr returns the Tasks value or an error if the edge
// was not loaded in eager-loading.
func (e QuestEdges) TasksOrErr() ([]*Task, error) {
if e.loadedTypes[2] {
return e.Tasks, nil
}
return nil, &NotLoadedError{edge: "tasks"}
}
// CreatorOrErr returns the Creator value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e QuestEdges) CreatorOrErr() (*User, error) {
if e.loadedTypes[3] {
if e.Creator == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: user.Label}
}
return e.Creator, nil
}
return nil, &NotLoadedError{edge: "creator"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Quest) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case quest.FieldID:
values[i] = new(sql.NullInt64)
case quest.FieldName, quest.FieldParameters, quest.FieldParamDefsAtCreation, quest.FieldEldritchAtCreation:
values[i] = new(sql.NullString)
case quest.FieldCreatedAt, quest.FieldLastModifiedAt:
values[i] = new(sql.NullTime)
case quest.ForeignKeys[0]: // quest_tome
values[i] = new(sql.NullInt64)
case quest.ForeignKeys[1]: // quest_bundle
values[i] = new(sql.NullInt64)
case quest.ForeignKeys[2]: // quest_creator
values[i] = new(sql.NullInt64)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Quest fields.
func (q *Quest) 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 quest.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
q.ID = int(value.Int64)
case quest.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 {
q.CreatedAt = value.Time
}
case quest.FieldLastModifiedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field last_modified_at", values[i])
} else if value.Valid {
q.LastModifiedAt = value.Time
}
case quest.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
q.Name = value.String
}
case quest.FieldParameters:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field parameters", values[i])
} else if value.Valid {
q.Parameters = value.String
}
case quest.FieldParamDefsAtCreation:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field param_defs_at_creation", values[i])
} else if value.Valid {
q.ParamDefsAtCreation = value.String
}
case quest.FieldEldritchAtCreation:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field eldritch_at_creation", values[i])
} else if value.Valid {
q.EldritchAtCreation = value.String
}
case quest.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field quest_tome", value)
} else if value.Valid {
q.quest_tome = new(int)
*q.quest_tome = int(value.Int64)
}
case quest.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field quest_bundle", value)
} else if value.Valid {
q.quest_bundle = new(int)
*q.quest_bundle = int(value.Int64)
}
case quest.ForeignKeys[2]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field quest_creator", value)
} else if value.Valid {
q.quest_creator = new(int)
*q.quest_creator = int(value.Int64)
}
default:
q.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Quest.
// This includes values selected through modifiers, order, etc.
func (q *Quest) Value(name string) (ent.Value, error) {
return q.selectValues.Get(name)
}
// QueryTome queries the "tome" edge of the Quest entity.
func (q *Quest) QueryTome() *TomeQuery {
return NewQuestClient(q.config).QueryTome(q)
}
// QueryBundle queries the "bundle" edge of the Quest entity.
func (q *Quest) QueryBundle() *FileQuery {
return NewQuestClient(q.config).QueryBundle(q)
}
// QueryTasks queries the "tasks" edge of the Quest entity.
func (q *Quest) QueryTasks() *TaskQuery {
return NewQuestClient(q.config).QueryTasks(q)
}
// QueryCreator queries the "creator" edge of the Quest entity.
func (q *Quest) QueryCreator() *UserQuery {
return NewQuestClient(q.config).QueryCreator(q)
}
// Update returns a builder for updating this Quest.
// Note that you need to call Quest.Unwrap() before calling this method if this Quest
// was returned from a transaction, and the transaction was committed or rolled back.
func (q *Quest) Update() *QuestUpdateOne {
return NewQuestClient(q.config).UpdateOne(q)
}
// Unwrap unwraps the Quest 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 (q *Quest) Unwrap() *Quest {
_tx, ok := q.config.driver.(*txDriver)
if !ok {
panic("ent: Quest is not a transactional entity")
}
q.config.driver = _tx.drv
return q
}
// String implements the fmt.Stringer.
func (q *Quest) String() string {
var builder strings.Builder
builder.WriteString("Quest(")
builder.WriteString(fmt.Sprintf("id=%v, ", q.ID))
builder.WriteString("created_at=")
builder.WriteString(q.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("last_modified_at=")
builder.WriteString(q.LastModifiedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(q.Name)
builder.WriteString(", ")
builder.WriteString("parameters=")
builder.WriteString(q.Parameters)
builder.WriteString(", ")
builder.WriteString("param_defs_at_creation=")
builder.WriteString(q.ParamDefsAtCreation)
builder.WriteString(", ")
builder.WriteString("eldritch_at_creation=")
builder.WriteString(q.EldritchAtCreation)
builder.WriteByte(')')
return builder.String()
}
// NamedTasks returns the Tasks named value or an error if the edge was not
// loaded in eager-loading with this name.
func (q *Quest) NamedTasks(name string) ([]*Task, error) {
if q.Edges.namedTasks == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := q.Edges.namedTasks[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (q *Quest) appendNamedTasks(name string, edges ...*Task) {
if q.Edges.namedTasks == nil {
q.Edges.namedTasks = make(map[string][]*Task)
}
if len(edges) == 0 {
q.Edges.namedTasks[name] = []*Task{}
} else {
q.Edges.namedTasks[name] = append(q.Edges.namedTasks[name], edges...)
}
}
// Quests is a parsable slice of Quest.
type Quests []*Quest