forked from jirfag/go-queryset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autogenerated_models.go
525 lines (441 loc) · 14.9 KB
/
autogenerated_models.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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
// Code generated by go-queryset. DO NOT EDIT.
package models
import (
"errors"
"fmt"
"strings"
"github.com/jinzhu/gorm"
forex "github.com/zhaoshuyi-s0221/go-queryset/internal/queryset/generator/test/pkgimport/forex/v1"
)
// ===== BEGIN of all query sets
// ===== BEGIN of query set ExampleQuerySet
// ExampleQuerySet is an queryset type for Example
type ExampleQuerySet struct {
db *gorm.DB
}
// NewExampleQuerySet constructs new ExampleQuerySet
func NewExampleQuerySet(db *gorm.DB) ExampleQuerySet {
return ExampleQuerySet{
db: db.Model(&Example{}),
}
}
func (qs ExampleQuerySet) w(db *gorm.DB) ExampleQuerySet {
return NewExampleQuerySet(db)
}
func (qs ExampleQuerySet) Select(fields ...ExampleDBSchemaField) ExampleQuerySet {
names := []string{}
for _, f := range fields {
names = append(names, f.String())
}
return qs.w(qs.db.Select(strings.Join(names, ",")))
}
// Create is an autogenerated method
// nolint: dupl
func (o *Example) Create(db *gorm.DB) error {
return db.Create(o).Error
}
// Delete is an autogenerated method
// nolint: dupl
func (o *Example) Delete(db *gorm.DB) error {
return db.Delete(o).Error
}
// All is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) All(ret *[]Example) error {
return qs.db.Find(ret).Error
}
// Count is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Count() (int, error) {
var count int
err := qs.db.Count(&count).Error
return count, err
}
// Currency1Eq is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency1Eq(currency1 forex.Currency1) ExampleQuerySet {
return qs.w(qs.db.Where("currency1 = ?", currency1))
}
// Currency1Gt is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency1Gt(currency1 forex.Currency1) ExampleQuerySet {
return qs.w(qs.db.Where("currency1 > ?", currency1))
}
// Currency1Gte is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency1Gte(currency1 forex.Currency1) ExampleQuerySet {
return qs.w(qs.db.Where("currency1 >= ?", currency1))
}
// Currency1In is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency1In(currency1 ...forex.Currency1) ExampleQuerySet {
if len(currency1) == 0 {
qs.db.AddError(errors.New("must at least pass one currency1 in Currency1In"))
return qs.w(qs.db)
}
return qs.w(qs.db.Where("currency1 IN (?)", currency1))
}
// Currency1Lt is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency1Lt(currency1 forex.Currency1) ExampleQuerySet {
return qs.w(qs.db.Where("currency1 < ?", currency1))
}
// Currency1Lte is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency1Lte(currency1 forex.Currency1) ExampleQuerySet {
return qs.w(qs.db.Where("currency1 <= ?", currency1))
}
// Currency1Ne is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency1Ne(currency1 forex.Currency1) ExampleQuerySet {
return qs.w(qs.db.Where("currency1 != ?", currency1))
}
// Currency1NotIn is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency1NotIn(currency1 ...forex.Currency1) ExampleQuerySet {
if len(currency1) == 0 {
qs.db.AddError(errors.New("must at least pass one currency1 in Currency1NotIn"))
return qs.w(qs.db)
}
return qs.w(qs.db.Where("currency1 NOT IN (?)", currency1))
}
// Currency2Eq is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2Eq(currency2 forex.Currency2) ExampleQuerySet {
return qs.w(qs.db.Where("currency2 = ?", currency2))
}
// Currency2Gt is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2Gt(currency2 forex.Currency2) ExampleQuerySet {
return qs.w(qs.db.Where("currency2 > ?", currency2))
}
// Currency2Gte is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2Gte(currency2 forex.Currency2) ExampleQuerySet {
return qs.w(qs.db.Where("currency2 >= ?", currency2))
}
// Currency2In is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2In(currency2 ...forex.Currency2) ExampleQuerySet {
if len(currency2) == 0 {
qs.db.AddError(errors.New("must at least pass one currency2 in Currency2In"))
return qs.w(qs.db)
}
return qs.w(qs.db.Where("currency2 IN (?)", currency2))
}
// Currency2Like is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2Like(currency2 forex.Currency2) ExampleQuerySet {
return qs.w(qs.db.Where("currency2 LIKE ?", currency2))
}
// Currency2Lt is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2Lt(currency2 forex.Currency2) ExampleQuerySet {
return qs.w(qs.db.Where("currency2 < ?", currency2))
}
// Currency2Lte is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2Lte(currency2 forex.Currency2) ExampleQuerySet {
return qs.w(qs.db.Where("currency2 <= ?", currency2))
}
// Currency2Ne is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2Ne(currency2 forex.Currency2) ExampleQuerySet {
return qs.w(qs.db.Where("currency2 != ?", currency2))
}
// Currency2NotIn is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2NotIn(currency2 ...forex.Currency2) ExampleQuerySet {
if len(currency2) == 0 {
qs.db.AddError(errors.New("must at least pass one currency2 in Currency2NotIn"))
return qs.w(qs.db)
}
return qs.w(qs.db.Where("currency2 NOT IN (?)", currency2))
}
// Currency2Notlike is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency2Notlike(currency2 forex.Currency2) ExampleQuerySet {
return qs.w(qs.db.Where("currency2 NOT LIKE ?", currency2))
}
// Currency3Eq is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3Eq(currency3 forex.Currency3) ExampleQuerySet {
return qs.w(qs.db.Where("currency3 = ?", currency3))
}
// Currency3Gt is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3Gt(currency3 forex.Currency3) ExampleQuerySet {
return qs.w(qs.db.Where("currency3 > ?", currency3))
}
// Currency3Gte is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3Gte(currency3 forex.Currency3) ExampleQuerySet {
return qs.w(qs.db.Where("currency3 >= ?", currency3))
}
// Currency3In is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3In(currency3 ...forex.Currency3) ExampleQuerySet {
if len(currency3) == 0 {
qs.db.AddError(errors.New("must at least pass one currency3 in Currency3In"))
return qs.w(qs.db)
}
return qs.w(qs.db.Where("currency3 IN (?)", currency3))
}
// Currency3Like is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3Like(currency3 forex.Currency3) ExampleQuerySet {
return qs.w(qs.db.Where("currency3 LIKE ?", currency3))
}
// Currency3Lt is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3Lt(currency3 forex.Currency3) ExampleQuerySet {
return qs.w(qs.db.Where("currency3 < ?", currency3))
}
// Currency3Lte is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3Lte(currency3 forex.Currency3) ExampleQuerySet {
return qs.w(qs.db.Where("currency3 <= ?", currency3))
}
// Currency3Ne is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3Ne(currency3 forex.Currency3) ExampleQuerySet {
return qs.w(qs.db.Where("currency3 != ?", currency3))
}
// Currency3NotIn is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3NotIn(currency3 ...forex.Currency3) ExampleQuerySet {
if len(currency3) == 0 {
qs.db.AddError(errors.New("must at least pass one currency3 in Currency3NotIn"))
return qs.w(qs.db)
}
return qs.w(qs.db.Where("currency3 NOT IN (?)", currency3))
}
// Currency3Notlike is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Currency3Notlike(currency3 forex.Currency3) ExampleQuerySet {
return qs.w(qs.db.Where("currency3 NOT LIKE ?", currency3))
}
// Delete is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Delete() error {
return qs.db.Delete(Example{}).Error
}
// DeleteNum is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) DeleteNum() (int64, error) {
db := qs.db.Delete(Example{})
return db.RowsAffected, db.Error
}
// DeleteNumUnscoped is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) DeleteNumUnscoped() (int64, error) {
db := qs.db.Unscoped().Delete(Example{})
return db.RowsAffected, db.Error
}
// GetDB is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) GetDB() *gorm.DB {
return qs.db
}
// GetUpdater is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) GetUpdater() ExampleUpdater {
return NewExampleUpdater(qs.db)
}
// Limit is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Limit(limit int) ExampleQuerySet {
return qs.w(qs.db.Limit(limit))
}
// Offset is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) Offset(offset int) ExampleQuerySet {
return qs.w(qs.db.Offset(offset))
}
// One is used to retrieve one result. It returns gorm.ErrRecordNotFound
// if nothing was fetched
func (qs ExampleQuerySet) One(ret *Example) error {
return qs.db.First(ret).Error
}
// OrderAscByCurrency1 is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) OrderAscByCurrency1() ExampleQuerySet {
return qs.w(qs.db.Order("currency1 ASC"))
}
// OrderAscByCurrency2 is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) OrderAscByCurrency2() ExampleQuerySet {
return qs.w(qs.db.Order("currency2 ASC"))
}
// OrderAscByCurrency3 is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) OrderAscByCurrency3() ExampleQuerySet {
return qs.w(qs.db.Order("currency3 ASC"))
}
// OrderAscByPriceID is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) OrderAscByPriceID() ExampleQuerySet {
return qs.w(qs.db.Order("price_id ASC"))
}
// OrderDescByCurrency1 is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) OrderDescByCurrency1() ExampleQuerySet {
return qs.w(qs.db.Order("currency1 DESC"))
}
// OrderDescByCurrency2 is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) OrderDescByCurrency2() ExampleQuerySet {
return qs.w(qs.db.Order("currency2 DESC"))
}
// OrderDescByCurrency3 is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) OrderDescByCurrency3() ExampleQuerySet {
return qs.w(qs.db.Order("currency3 DESC"))
}
// OrderDescByPriceID is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) OrderDescByPriceID() ExampleQuerySet {
return qs.w(qs.db.Order("price_id DESC"))
}
// PriceIDEq is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) PriceIDEq(priceID int64) ExampleQuerySet {
return qs.w(qs.db.Where("price_id = ?", priceID))
}
// PriceIDGt is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) PriceIDGt(priceID int64) ExampleQuerySet {
return qs.w(qs.db.Where("price_id > ?", priceID))
}
// PriceIDGte is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) PriceIDGte(priceID int64) ExampleQuerySet {
return qs.w(qs.db.Where("price_id >= ?", priceID))
}
// PriceIDIn is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) PriceIDIn(priceID ...int64) ExampleQuerySet {
if len(priceID) == 0 {
qs.db.AddError(errors.New("must at least pass one priceID in PriceIDIn"))
return qs.w(qs.db)
}
return qs.w(qs.db.Where("price_id IN (?)", priceID))
}
// PriceIDLt is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) PriceIDLt(priceID int64) ExampleQuerySet {
return qs.w(qs.db.Where("price_id < ?", priceID))
}
// PriceIDLte is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) PriceIDLte(priceID int64) ExampleQuerySet {
return qs.w(qs.db.Where("price_id <= ?", priceID))
}
// PriceIDNe is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) PriceIDNe(priceID int64) ExampleQuerySet {
return qs.w(qs.db.Where("price_id != ?", priceID))
}
// PriceIDNotIn is an autogenerated method
// nolint: dupl
func (qs ExampleQuerySet) PriceIDNotIn(priceID ...int64) ExampleQuerySet {
if len(priceID) == 0 {
qs.db.AddError(errors.New("must at least pass one priceID in PriceIDNotIn"))
return qs.w(qs.db)
}
return qs.w(qs.db.Where("price_id NOT IN (?)", priceID))
}
// SetCurrency1 is an autogenerated method
// nolint: dupl
func (u ExampleUpdater) SetCurrency1(currency1 forex.Currency1) ExampleUpdater {
u.fields[string(ExampleDBSchema.Currency1)] = currency1
return u
}
// SetCurrency2 is an autogenerated method
// nolint: dupl
func (u ExampleUpdater) SetCurrency2(currency2 forex.Currency2) ExampleUpdater {
u.fields[string(ExampleDBSchema.Currency2)] = currency2
return u
}
// SetCurrency3 is an autogenerated method
// nolint: dupl
func (u ExampleUpdater) SetCurrency3(currency3 forex.Currency3) ExampleUpdater {
u.fields[string(ExampleDBSchema.Currency3)] = currency3
return u
}
// SetPriceID is an autogenerated method
// nolint: dupl
func (u ExampleUpdater) SetPriceID(priceID int64) ExampleUpdater {
u.fields[string(ExampleDBSchema.PriceID)] = priceID
return u
}
// Update is an autogenerated method
// nolint: dupl
func (u ExampleUpdater) Update() error {
return u.db.Updates(u.fields).Error
}
// UpdateNum is an autogenerated method
// nolint: dupl
func (u ExampleUpdater) UpdateNum() (int64, error) {
db := u.db.Updates(u.fields)
return db.RowsAffected, db.Error
}
// ===== END of query set ExampleQuerySet
// ===== BEGIN of Example modifiers
// ExampleDBSchemaField describes database schema field. It requires for method 'Update'
type ExampleDBSchemaField string
// String method returns string representation of field.
// nolint: dupl
func (f ExampleDBSchemaField) String() string {
return string(f)
}
// ExampleDBSchema stores db field names of Example
var ExampleDBSchema = struct {
PriceID ExampleDBSchemaField
Currency1 ExampleDBSchemaField
Currency2 ExampleDBSchemaField
Currency3 ExampleDBSchemaField
}{
PriceID: ExampleDBSchemaField("price_id"),
Currency1: ExampleDBSchemaField("currency1"),
Currency2: ExampleDBSchemaField("currency2"),
Currency3: ExampleDBSchemaField("currency3"),
}
// Update updates Example fields by primary key
// nolint: dupl
func (o *Example) Update(db *gorm.DB, fields ...ExampleDBSchemaField) error {
dbNameToFieldName := map[string]interface{}{
"price_id": o.PriceID,
"currency1": o.Currency1,
"currency2": o.Currency2,
"currency3": o.Currency3,
}
u := map[string]interface{}{}
for _, f := range fields {
fs := f.String()
u[fs] = dbNameToFieldName[fs]
}
if err := db.Model(o).Updates(u).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return err
}
return fmt.Errorf("can't update Example %v fields %v: %s",
o, fields, err)
}
return nil
}
// ExampleUpdater is an Example updates manager
type ExampleUpdater struct {
fields map[string]interface{}
db *gorm.DB
}
// NewExampleUpdater creates new Example updater
// nolint: dupl
func NewExampleUpdater(db *gorm.DB) ExampleUpdater {
return ExampleUpdater{
fields: map[string]interface{}{},
db: db.Model(&Example{}),
}
}
// ===== END of Example modifiers
// ===== END of all query sets