/
gen.go
399 lines (375 loc) · 12.5 KB
/
gen.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package dao
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
Action *action
Behavior *behavior
Bot *bot
Channel *channel
Config *config
Counter *counter
CounterRecord *counterRecord
Cycle *cycle
Dag *dag
Data *data
Fileupload *fileupload
Form *form
Instruct *instruct
Job *job
KeyResult *keyResult
KeyResultValue *keyResultValue
Message *message
OAuth *oAuth
Objective *objective
Page *page
Parameter *parameter
Pipeline *pipeline
Platform *platform
PlatformBot *platformBot
PlatformChannel *platformChannel
PlatformUser *platformUser
Review *review
ReviewEvaluation *reviewEvaluation
SchemaMigration *schemaMigration
Session *session
Step *step
Todo *todo
Topic *topic
Url *url
User *user
Workflow *workflow
WorkflowScript *workflowScript
WorkflowTrigger *workflowTrigger
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Action = &Q.Action
Behavior = &Q.Behavior
Bot = &Q.Bot
Channel = &Q.Channel
Config = &Q.Config
Counter = &Q.Counter
CounterRecord = &Q.CounterRecord
Cycle = &Q.Cycle
Dag = &Q.Dag
Data = &Q.Data
Fileupload = &Q.Fileupload
Form = &Q.Form
Instruct = &Q.Instruct
Job = &Q.Job
KeyResult = &Q.KeyResult
KeyResultValue = &Q.KeyResultValue
Message = &Q.Message
OAuth = &Q.OAuth
Objective = &Q.Objective
Page = &Q.Page
Parameter = &Q.Parameter
Pipeline = &Q.Pipeline
Platform = &Q.Platform
PlatformBot = &Q.PlatformBot
PlatformChannel = &Q.PlatformChannel
PlatformUser = &Q.PlatformUser
Review = &Q.Review
ReviewEvaluation = &Q.ReviewEvaluation
SchemaMigration = &Q.SchemaMigration
Session = &Q.Session
Step = &Q.Step
Todo = &Q.Todo
Topic = &Q.Topic
Url = &Q.Url
User = &Q.User
Workflow = &Q.Workflow
WorkflowScript = &Q.WorkflowScript
WorkflowTrigger = &Q.WorkflowTrigger
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Action: newAction(db, opts...),
Behavior: newBehavior(db, opts...),
Bot: newBot(db, opts...),
Channel: newChannel(db, opts...),
Config: newConfig(db, opts...),
Counter: newCounter(db, opts...),
CounterRecord: newCounterRecord(db, opts...),
Cycle: newCycle(db, opts...),
Dag: newDag(db, opts...),
Data: newData(db, opts...),
Fileupload: newFileupload(db, opts...),
Form: newForm(db, opts...),
Instruct: newInstruct(db, opts...),
Job: newJob(db, opts...),
KeyResult: newKeyResult(db, opts...),
KeyResultValue: newKeyResultValue(db, opts...),
Message: newMessage(db, opts...),
OAuth: newOAuth(db, opts...),
Objective: newObjective(db, opts...),
Page: newPage(db, opts...),
Parameter: newParameter(db, opts...),
Pipeline: newPipeline(db, opts...),
Platform: newPlatform(db, opts...),
PlatformBot: newPlatformBot(db, opts...),
PlatformChannel: newPlatformChannel(db, opts...),
PlatformUser: newPlatformUser(db, opts...),
Review: newReview(db, opts...),
ReviewEvaluation: newReviewEvaluation(db, opts...),
SchemaMigration: newSchemaMigration(db, opts...),
Session: newSession(db, opts...),
Step: newStep(db, opts...),
Todo: newTodo(db, opts...),
Topic: newTopic(db, opts...),
Url: newUrl(db, opts...),
User: newUser(db, opts...),
Workflow: newWorkflow(db, opts...),
WorkflowScript: newWorkflowScript(db, opts...),
WorkflowTrigger: newWorkflowTrigger(db, opts...),
}
}
type Query struct {
db *gorm.DB
Action action
Behavior behavior
Bot bot
Channel channel
Config config
Counter counter
CounterRecord counterRecord
Cycle cycle
Dag dag
Data data
Fileupload fileupload
Form form
Instruct instruct
Job job
KeyResult keyResult
KeyResultValue keyResultValue
Message message
OAuth oAuth
Objective objective
Page page
Parameter parameter
Pipeline pipeline
Platform platform
PlatformBot platformBot
PlatformChannel platformChannel
PlatformUser platformUser
Review review
ReviewEvaluation reviewEvaluation
SchemaMigration schemaMigration
Session session
Step step
Todo todo
Topic topic
Url url
User user
Workflow workflow
WorkflowScript workflowScript
WorkflowTrigger workflowTrigger
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Action: q.Action.clone(db),
Behavior: q.Behavior.clone(db),
Bot: q.Bot.clone(db),
Channel: q.Channel.clone(db),
Config: q.Config.clone(db),
Counter: q.Counter.clone(db),
CounterRecord: q.CounterRecord.clone(db),
Cycle: q.Cycle.clone(db),
Dag: q.Dag.clone(db),
Data: q.Data.clone(db),
Fileupload: q.Fileupload.clone(db),
Form: q.Form.clone(db),
Instruct: q.Instruct.clone(db),
Job: q.Job.clone(db),
KeyResult: q.KeyResult.clone(db),
KeyResultValue: q.KeyResultValue.clone(db),
Message: q.Message.clone(db),
OAuth: q.OAuth.clone(db),
Objective: q.Objective.clone(db),
Page: q.Page.clone(db),
Parameter: q.Parameter.clone(db),
Pipeline: q.Pipeline.clone(db),
Platform: q.Platform.clone(db),
PlatformBot: q.PlatformBot.clone(db),
PlatformChannel: q.PlatformChannel.clone(db),
PlatformUser: q.PlatformUser.clone(db),
Review: q.Review.clone(db),
ReviewEvaluation: q.ReviewEvaluation.clone(db),
SchemaMigration: q.SchemaMigration.clone(db),
Session: q.Session.clone(db),
Step: q.Step.clone(db),
Todo: q.Todo.clone(db),
Topic: q.Topic.clone(db),
Url: q.Url.clone(db),
User: q.User.clone(db),
Workflow: q.Workflow.clone(db),
WorkflowScript: q.WorkflowScript.clone(db),
WorkflowTrigger: q.WorkflowTrigger.clone(db),
}
}
func (q *Query) ReadDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Action: q.Action.replaceDB(db),
Behavior: q.Behavior.replaceDB(db),
Bot: q.Bot.replaceDB(db),
Channel: q.Channel.replaceDB(db),
Config: q.Config.replaceDB(db),
Counter: q.Counter.replaceDB(db),
CounterRecord: q.CounterRecord.replaceDB(db),
Cycle: q.Cycle.replaceDB(db),
Dag: q.Dag.replaceDB(db),
Data: q.Data.replaceDB(db),
Fileupload: q.Fileupload.replaceDB(db),
Form: q.Form.replaceDB(db),
Instruct: q.Instruct.replaceDB(db),
Job: q.Job.replaceDB(db),
KeyResult: q.KeyResult.replaceDB(db),
KeyResultValue: q.KeyResultValue.replaceDB(db),
Message: q.Message.replaceDB(db),
OAuth: q.OAuth.replaceDB(db),
Objective: q.Objective.replaceDB(db),
Page: q.Page.replaceDB(db),
Parameter: q.Parameter.replaceDB(db),
Pipeline: q.Pipeline.replaceDB(db),
Platform: q.Platform.replaceDB(db),
PlatformBot: q.PlatformBot.replaceDB(db),
PlatformChannel: q.PlatformChannel.replaceDB(db),
PlatformUser: q.PlatformUser.replaceDB(db),
Review: q.Review.replaceDB(db),
ReviewEvaluation: q.ReviewEvaluation.replaceDB(db),
SchemaMigration: q.SchemaMigration.replaceDB(db),
Session: q.Session.replaceDB(db),
Step: q.Step.replaceDB(db),
Todo: q.Todo.replaceDB(db),
Topic: q.Topic.replaceDB(db),
Url: q.Url.replaceDB(db),
User: q.User.replaceDB(db),
Workflow: q.Workflow.replaceDB(db),
WorkflowScript: q.WorkflowScript.replaceDB(db),
WorkflowTrigger: q.WorkflowTrigger.replaceDB(db),
}
}
type queryCtx struct {
Action *actionDo
Behavior *behaviorDo
Bot *botDo
Channel *channelDo
Config *configDo
Counter *counterDo
CounterRecord *counterRecordDo
Cycle *cycleDo
Dag *dagDo
Data *dataDo
Fileupload *fileuploadDo
Form *formDo
Instruct *instructDo
Job *jobDo
KeyResult *keyResultDo
KeyResultValue *keyResultValueDo
Message *messageDo
OAuth *oAuthDo
Objective *objectiveDo
Page *pageDo
Parameter *parameterDo
Pipeline *pipelineDo
Platform *platformDo
PlatformBot *platformBotDo
PlatformChannel *platformChannelDo
PlatformUser *platformUserDo
Review *reviewDo
ReviewEvaluation *reviewEvaluationDo
SchemaMigration *schemaMigrationDo
Session *sessionDo
Step *stepDo
Todo *todoDo
Topic *topicDo
Url *urlDo
User *userDo
Workflow *workflowDo
WorkflowScript *workflowScriptDo
WorkflowTrigger *workflowTriggerDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Action: q.Action.WithContext(ctx),
Behavior: q.Behavior.WithContext(ctx),
Bot: q.Bot.WithContext(ctx),
Channel: q.Channel.WithContext(ctx),
Config: q.Config.WithContext(ctx),
Counter: q.Counter.WithContext(ctx),
CounterRecord: q.CounterRecord.WithContext(ctx),
Cycle: q.Cycle.WithContext(ctx),
Dag: q.Dag.WithContext(ctx),
Data: q.Data.WithContext(ctx),
Fileupload: q.Fileupload.WithContext(ctx),
Form: q.Form.WithContext(ctx),
Instruct: q.Instruct.WithContext(ctx),
Job: q.Job.WithContext(ctx),
KeyResult: q.KeyResult.WithContext(ctx),
KeyResultValue: q.KeyResultValue.WithContext(ctx),
Message: q.Message.WithContext(ctx),
OAuth: q.OAuth.WithContext(ctx),
Objective: q.Objective.WithContext(ctx),
Page: q.Page.WithContext(ctx),
Parameter: q.Parameter.WithContext(ctx),
Pipeline: q.Pipeline.WithContext(ctx),
Platform: q.Platform.WithContext(ctx),
PlatformBot: q.PlatformBot.WithContext(ctx),
PlatformChannel: q.PlatformChannel.WithContext(ctx),
PlatformUser: q.PlatformUser.WithContext(ctx),
Review: q.Review.WithContext(ctx),
ReviewEvaluation: q.ReviewEvaluation.WithContext(ctx),
SchemaMigration: q.SchemaMigration.WithContext(ctx),
Session: q.Session.WithContext(ctx),
Step: q.Step.WithContext(ctx),
Todo: q.Todo.WithContext(ctx),
Topic: q.Topic.WithContext(ctx),
Url: q.Url.WithContext(ctx),
User: q.User.WithContext(ctx),
Workflow: q.Workflow.WithContext(ctx),
WorkflowScript: q.WorkflowScript.WithContext(ctx),
WorkflowTrigger: q.WorkflowTrigger.WithContext(ctx),
}
}
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
tx := q.db.Begin(opts...)
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
}
type QueryTx struct {
*Query
Error error
}
func (q *QueryTx) Commit() error {
return q.db.Commit().Error
}
func (q *QueryTx) Rollback() error {
return q.db.Rollback().Error
}
func (q *QueryTx) SavePoint(name string) error {
return q.db.SavePoint(name).Error
}
func (q *QueryTx) RollbackTo(name string) error {
return q.db.RollbackTo(name).Error
}