-
Notifications
You must be signed in to change notification settings - Fork 0
/
oktask.go
1304 lines (1080 loc) · 35.2 KB
/
oktask.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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is generated by SQLBoiler (https://github.com/vattle/sqlboiler)
// and is meant to be re-generated in place and/or deleted at any time.
// DO NOT EDIT
package models
import (
"bytes"
"database/sql"
"fmt"
"reflect"
"strings"
"sync"
"time"
"github.com/pkg/errors"
"github.com/vattle/sqlboiler/boil"
"github.com/vattle/sqlboiler/queries"
"github.com/vattle/sqlboiler/queries/qm"
"github.com/vattle/sqlboiler/strmangle"
"gopkg.in/nullbio/null.v6"
)
// Oktask is an object representing the database table.
type Oktask struct {
IDTask int `boil:"id_task" json:"id_task" toml:"id_task" yaml:"id_task"`
TitleTask string `boil:"title_task" json:"title_task" toml:"title_task" yaml:"title_task"`
Urgency string `boil:"urgency" json:"urgency" toml:"urgency" yaml:"urgency"`
Difficulty string `boil:"difficulty" json:"difficulty" toml:"difficulty" yaml:"difficulty"`
DescTask null.String `boil:"desc_task" json:"desc_task,omitempty" toml:"desc_task" yaml:"desc_task,omitempty"`
R *oktaskR `boil:"-" json:"-" toml:"-" yaml:"-"`
L oktaskL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
// oktaskR is where relationships are stored.
type oktaskR struct {
TaskOkprojecttasks OkprojecttaskSlice
}
// oktaskL is where Load methods for each relationship are stored.
type oktaskL struct{}
var (
oktaskColumns = []string{"id_task", "title_task", "urgency", "difficulty", "desc_task"}
oktaskColumnsWithoutDefault = []string{"title_task", "urgency", "difficulty", "desc_task"}
oktaskColumnsWithDefault = []string{"id_task"}
oktaskPrimaryKeyColumns = []string{"id_task"}
)
type (
// OktaskSlice is an alias for a slice of pointers to Oktask.
// This should generally be used opposed to []Oktask.
OktaskSlice []*Oktask
// OktaskHook is the signature for custom Oktask hook methods
OktaskHook func(boil.Executor, *Oktask) error
oktaskQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
oktaskType = reflect.TypeOf(&Oktask{})
oktaskMapping = queries.MakeStructMapping(oktaskType)
oktaskPrimaryKeyMapping, _ = queries.BindMapping(oktaskType, oktaskMapping, oktaskPrimaryKeyColumns)
oktaskInsertCacheMut sync.RWMutex
oktaskInsertCache = make(map[string]insertCache)
oktaskUpdateCacheMut sync.RWMutex
oktaskUpdateCache = make(map[string]updateCache)
oktaskUpsertCacheMut sync.RWMutex
oktaskUpsertCache = make(map[string]insertCache)
)
var (
// Force time package dependency for automated UpdatedAt/CreatedAt.
_ = time.Second
// Force bytes in case of primary key column that uses []byte (for relationship compares)
_ = bytes.MinRead
)
var oktaskBeforeInsertHooks []OktaskHook
var oktaskBeforeUpdateHooks []OktaskHook
var oktaskBeforeDeleteHooks []OktaskHook
var oktaskBeforeUpsertHooks []OktaskHook
var oktaskAfterInsertHooks []OktaskHook
var oktaskAfterSelectHooks []OktaskHook
var oktaskAfterUpdateHooks []OktaskHook
var oktaskAfterDeleteHooks []OktaskHook
var oktaskAfterUpsertHooks []OktaskHook
// doBeforeInsertHooks executes all "before insert" hooks.
func (o *Oktask) doBeforeInsertHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskBeforeInsertHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpdateHooks executes all "before Update" hooks.
func (o *Oktask) doBeforeUpdateHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskBeforeUpdateHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeDeleteHooks executes all "before Delete" hooks.
func (o *Oktask) doBeforeDeleteHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskBeforeDeleteHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpsertHooks executes all "before Upsert" hooks.
func (o *Oktask) doBeforeUpsertHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskBeforeUpsertHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// doAfterInsertHooks executes all "after Insert" hooks.
func (o *Oktask) doAfterInsertHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskAfterInsertHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// doAfterSelectHooks executes all "after Select" hooks.
func (o *Oktask) doAfterSelectHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskAfterSelectHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpdateHooks executes all "after Update" hooks.
func (o *Oktask) doAfterUpdateHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskAfterUpdateHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// doAfterDeleteHooks executes all "after Delete" hooks.
func (o *Oktask) doAfterDeleteHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskAfterDeleteHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpsertHooks executes all "after Upsert" hooks.
func (o *Oktask) doAfterUpsertHooks(exec boil.Executor) (err error) {
for _, hook := range oktaskAfterUpsertHooks {
if err := hook(exec, o); err != nil {
return err
}
}
return nil
}
// AddOktaskHook registers your hook function for all future operations.
func AddOktaskHook(hookPoint boil.HookPoint, oktaskHook OktaskHook) {
switch hookPoint {
case boil.BeforeInsertHook:
oktaskBeforeInsertHooks = append(oktaskBeforeInsertHooks, oktaskHook)
case boil.BeforeUpdateHook:
oktaskBeforeUpdateHooks = append(oktaskBeforeUpdateHooks, oktaskHook)
case boil.BeforeDeleteHook:
oktaskBeforeDeleteHooks = append(oktaskBeforeDeleteHooks, oktaskHook)
case boil.BeforeUpsertHook:
oktaskBeforeUpsertHooks = append(oktaskBeforeUpsertHooks, oktaskHook)
case boil.AfterInsertHook:
oktaskAfterInsertHooks = append(oktaskAfterInsertHooks, oktaskHook)
case boil.AfterSelectHook:
oktaskAfterSelectHooks = append(oktaskAfterSelectHooks, oktaskHook)
case boil.AfterUpdateHook:
oktaskAfterUpdateHooks = append(oktaskAfterUpdateHooks, oktaskHook)
case boil.AfterDeleteHook:
oktaskAfterDeleteHooks = append(oktaskAfterDeleteHooks, oktaskHook)
case boil.AfterUpsertHook:
oktaskAfterUpsertHooks = append(oktaskAfterUpsertHooks, oktaskHook)
}
}
// OneP returns a single oktask record from the query, and panics on error.
func (q oktaskQuery) OneP() *Oktask {
o, err := q.One()
if err != nil {
panic(boil.WrapErr(err))
}
return o
}
// One returns a single oktask record from the query.
func (q oktaskQuery) One() (*Oktask, error) {
o := &Oktask{}
queries.SetLimit(q.Query, 1)
err := q.Bind(o)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: failed to execute a one query for oktask")
}
if err := o.doAfterSelectHooks(queries.GetExecutor(q.Query)); err != nil {
return o, err
}
return o, nil
}
// AllP returns all Oktask records from the query, and panics on error.
func (q oktaskQuery) AllP() OktaskSlice {
o, err := q.All()
if err != nil {
panic(boil.WrapErr(err))
}
return o
}
// All returns all Oktask records from the query.
func (q oktaskQuery) All() (OktaskSlice, error) {
var o OktaskSlice
err := q.Bind(&o)
if err != nil {
return nil, errors.Wrap(err, "models: failed to assign all query results to Oktask slice")
}
if len(oktaskAfterSelectHooks) != 0 {
for _, obj := range o {
if err := obj.doAfterSelectHooks(queries.GetExecutor(q.Query)); err != nil {
return o, err
}
}
}
return o, nil
}
// CountP returns the count of all Oktask records in the query, and panics on error.
func (q oktaskQuery) CountP() int64 {
c, err := q.Count()
if err != nil {
panic(boil.WrapErr(err))
}
return c
}
// Count returns the count of all Oktask records in the query.
func (q oktaskQuery) Count() (int64, error) {
var count int64
queries.SetSelect(q.Query, nil)
queries.SetCount(q.Query)
err := q.Query.QueryRow().Scan(&count)
if err != nil {
return 0, errors.Wrap(err, "models: failed to count oktask rows")
}
return count, nil
}
// Exists checks if the row exists in the table, and panics on error.
func (q oktaskQuery) ExistsP() bool {
e, err := q.Exists()
if err != nil {
panic(boil.WrapErr(err))
}
return e
}
// Exists checks if the row exists in the table.
func (q oktaskQuery) Exists() (bool, error) {
var count int64
queries.SetCount(q.Query)
queries.SetLimit(q.Query, 1)
err := q.Query.QueryRow().Scan(&count)
if err != nil {
return false, errors.Wrap(err, "models: failed to check if oktask exists")
}
return count > 0, nil
}
// TaskOkprojecttasksG retrieves all the okprojecttask's okprojecttask via task_id column.
func (o *Oktask) TaskOkprojecttasksG(mods ...qm.QueryMod) okprojecttaskQuery {
return o.TaskOkprojecttasks(boil.GetDB(), mods...)
}
// TaskOkprojecttasks retrieves all the okprojecttask's okprojecttask with an executor via task_id column.
func (o *Oktask) TaskOkprojecttasks(exec boil.Executor, mods ...qm.QueryMod) okprojecttaskQuery {
queryMods := []qm.QueryMod{
qm.Select("`a`.*"),
}
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("`a`.`task_id`=?", o.IDTask),
)
query := Okprojecttasks(exec, queryMods...)
queries.SetFrom(query.Query, "`okprojecttask` as `a`")
return query
}
// LoadTaskOkprojecttasks allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (oktaskL) LoadTaskOkprojecttasks(e boil.Executor, singular bool, maybeOktask interface{}) error {
var slice []*Oktask
var object *Oktask
count := 1
if singular {
object = maybeOktask.(*Oktask)
} else {
slice = *maybeOktask.(*OktaskSlice)
count = len(slice)
}
args := make([]interface{}, count)
if singular {
if object.R == nil {
object.R = &oktaskR{}
}
args[0] = object.IDTask
} else {
for i, obj := range slice {
if obj.R == nil {
obj.R = &oktaskR{}
}
args[i] = obj.IDTask
}
}
query := fmt.Sprintf(
"select * from `okprojecttask` where `task_id` in (%s)",
strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
)
if boil.DebugMode {
fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
}
results, err := e.Query(query, args...)
if err != nil {
return errors.Wrap(err, "failed to eager load okprojecttask")
}
defer results.Close()
var resultSlice []*Okprojecttask
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice okprojecttask")
}
if len(okprojecttaskAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(e); err != nil {
return err
}
}
}
if singular {
object.R.TaskOkprojecttasks = resultSlice
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.IDTask == foreign.TaskID {
local.R.TaskOkprojecttasks = append(local.R.TaskOkprojecttasks, foreign)
break
}
}
}
return nil
}
// AddTaskOkprojecttasksG adds the given related objects to the existing relationships
// of the oktask, optionally inserting them as new records.
// Appends related to o.R.TaskOkprojecttasks.
// Sets related.R.Task appropriately.
// Uses the global database handle.
func (o *Oktask) AddTaskOkprojecttasksG(insert bool, related ...*Okprojecttask) error {
return o.AddTaskOkprojecttasks(boil.GetDB(), insert, related...)
}
// AddTaskOkprojecttasksP adds the given related objects to the existing relationships
// of the oktask, optionally inserting them as new records.
// Appends related to o.R.TaskOkprojecttasks.
// Sets related.R.Task appropriately.
// Panics on error.
func (o *Oktask) AddTaskOkprojecttasksP(exec boil.Executor, insert bool, related ...*Okprojecttask) {
if err := o.AddTaskOkprojecttasks(exec, insert, related...); err != nil {
panic(boil.WrapErr(err))
}
}
// AddTaskOkprojecttasksGP adds the given related objects to the existing relationships
// of the oktask, optionally inserting them as new records.
// Appends related to o.R.TaskOkprojecttasks.
// Sets related.R.Task appropriately.
// Uses the global database handle and panics on error.
func (o *Oktask) AddTaskOkprojecttasksGP(insert bool, related ...*Okprojecttask) {
if err := o.AddTaskOkprojecttasks(boil.GetDB(), insert, related...); err != nil {
panic(boil.WrapErr(err))
}
}
// AddTaskOkprojecttasks adds the given related objects to the existing relationships
// of the oktask, optionally inserting them as new records.
// Appends related to o.R.TaskOkprojecttasks.
// Sets related.R.Task appropriately.
func (o *Oktask) AddTaskOkprojecttasks(exec boil.Executor, insert bool, related ...*Okprojecttask) error {
var err error
for _, rel := range related {
if insert {
rel.TaskID = o.IDTask
if err = rel.Insert(exec); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
} else {
updateQuery := fmt.Sprintf(
"UPDATE `okprojecttask` SET %s WHERE %s",
strmangle.SetParamNames("`", "`", 0, []string{"task_id"}),
strmangle.WhereClause("`", "`", 0, okprojecttaskPrimaryKeyColumns),
)
values := []interface{}{o.IDTask, rel.IDPTask}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, updateQuery)
fmt.Fprintln(boil.DebugWriter, values)
}
if _, err = exec.Exec(updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update foreign table")
}
rel.TaskID = o.IDTask
}
}
if o.R == nil {
o.R = &oktaskR{
TaskOkprojecttasks: related,
}
} else {
o.R.TaskOkprojecttasks = append(o.R.TaskOkprojecttasks, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &okprojecttaskR{
Task: o,
}
} else {
rel.R.Task = o
}
}
return nil
}
// OktasksG retrieves all records.
func OktasksG(mods ...qm.QueryMod) oktaskQuery {
return Oktasks(boil.GetDB(), mods...)
}
// Oktasks retrieves all the records using an executor.
func Oktasks(exec boil.Executor, mods ...qm.QueryMod) oktaskQuery {
mods = append(mods, qm.From("`oktask`"))
return oktaskQuery{NewQuery(exec, mods...)}
}
// FindOktaskG retrieves a single record by ID.
func FindOktaskG(idTask int, selectCols ...string) (*Oktask, error) {
return FindOktask(boil.GetDB(), idTask, selectCols...)
}
// FindOktaskGP retrieves a single record by ID, and panics on error.
func FindOktaskGP(idTask int, selectCols ...string) *Oktask {
retobj, err := FindOktask(boil.GetDB(), idTask, selectCols...)
if err != nil {
panic(boil.WrapErr(err))
}
return retobj
}
// FindOktask retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindOktask(exec boil.Executor, idTask int, selectCols ...string) (*Oktask, error) {
oktaskObj := &Oktask{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from `oktask` where `id_task`=?", sel,
)
q := queries.Raw(exec, query, idTask)
err := q.Bind(oktaskObj)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: unable to select from oktask")
}
return oktaskObj, nil
}
// FindOktaskP retrieves a single record by ID with an executor, and panics on error.
func FindOktaskP(exec boil.Executor, idTask int, selectCols ...string) *Oktask {
retobj, err := FindOktask(exec, idTask, selectCols...)
if err != nil {
panic(boil.WrapErr(err))
}
return retobj
}
// InsertG a single record. See Insert for whitelist behavior description.
func (o *Oktask) InsertG(whitelist ...string) error {
return o.Insert(boil.GetDB(), whitelist...)
}
// InsertGP a single record, and panics on error. See Insert for whitelist
// behavior description.
func (o *Oktask) InsertGP(whitelist ...string) {
if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// InsertP a single record using an executor, and panics on error. See Insert
// for whitelist behavior description.
func (o *Oktask) InsertP(exec boil.Executor, whitelist ...string) {
if err := o.Insert(exec, whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// Insert a single record using an executor.
// Whitelist behavior: If a whitelist is provided, only those columns supplied are inserted
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns without a default value are included (i.e. name, age)
// - All columns with a default, but non-zero are included (i.e. health = 75)
func (o *Oktask) Insert(exec boil.Executor, whitelist ...string) error {
if o == nil {
return errors.New("models: no oktask provided for insertion")
}
var err error
if err := o.doBeforeInsertHooks(exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(oktaskColumnsWithDefault, o)
key := makeCacheKey(whitelist, nzDefaults)
oktaskInsertCacheMut.RLock()
cache, cached := oktaskInsertCache[key]
oktaskInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := strmangle.InsertColumnSet(
oktaskColumns,
oktaskColumnsWithDefault,
oktaskColumnsWithoutDefault,
nzDefaults,
whitelist,
)
cache.valueMapping, err = queries.BindMapping(oktaskType, oktaskMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(oktaskType, oktaskMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO `oktask` (`%s`) VALUES (%s)", strings.Join(wl, "`,`"), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO `oktask` () VALUES ()"
}
if len(cache.retMapping) != 0 {
cache.retQuery = fmt.Sprintf("SELECT `%s` FROM `oktask` WHERE %s", strings.Join(returnColumns, "`,`"), strmangle.WhereClause("`", "`", 0, oktaskPrimaryKeyColumns))
}
}
value := reflect.Indirect(reflect.ValueOf(o))
vals := queries.ValuesFromMapping(value, cache.valueMapping)
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, vals)
}
result, err := exec.Exec(cache.query, vals...)
if err != nil {
return errors.Wrap(err, "models: unable to insert into oktask")
}
var lastID int64
var identifierCols []interface{}
if len(cache.retMapping) == 0 {
goto CacheNoHooks
}
lastID, err = result.LastInsertId()
if err != nil {
return ErrSyncFail
}
o.IDTask = int(lastID)
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == oktaskMapping["IDTask"] {
goto CacheNoHooks
}
identifierCols = []interface{}{
o.IDTask,
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
fmt.Fprintln(boil.DebugWriter, identifierCols...)
}
err = exec.QueryRow(cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
if err != nil {
return errors.Wrap(err, "models: unable to populate default values for oktask")
}
CacheNoHooks:
if !cached {
oktaskInsertCacheMut.Lock()
oktaskInsertCache[key] = cache
oktaskInsertCacheMut.Unlock()
}
return o.doAfterInsertHooks(exec)
}
// UpdateG a single Oktask record. See Update for
// whitelist behavior description.
func (o *Oktask) UpdateG(whitelist ...string) error {
return o.Update(boil.GetDB(), whitelist...)
}
// UpdateGP a single Oktask record.
// UpdateGP takes a whitelist of column names that should be updated.
// Panics on error. See Update for whitelist behavior description.
func (o *Oktask) UpdateGP(whitelist ...string) {
if err := o.Update(boil.GetDB(), whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// UpdateP uses an executor to update the Oktask, and panics on error.
// See Update for whitelist behavior description.
func (o *Oktask) UpdateP(exec boil.Executor, whitelist ...string) {
err := o.Update(exec, whitelist...)
if err != nil {
panic(boil.WrapErr(err))
}
}
// Update uses an executor to update the Oktask.
// Whitelist behavior: If a whitelist is provided, only the columns given are updated.
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns are inferred to start with
// - All primary keys are subtracted from this set
// Update does not automatically update the record in case of default values. Use .Reload()
// to refresh the records.
func (o *Oktask) Update(exec boil.Executor, whitelist ...string) error {
var err error
if err = o.doBeforeUpdateHooks(exec); err != nil {
return err
}
key := makeCacheKey(whitelist, nil)
oktaskUpdateCacheMut.RLock()
cache, cached := oktaskUpdateCache[key]
oktaskUpdateCacheMut.RUnlock()
if !cached {
wl := strmangle.UpdateColumnSet(oktaskColumns, oktaskPrimaryKeyColumns, whitelist)
if len(whitelist) == 0 {
wl = strmangle.SetComplement(wl, []string{"created_at"})
}
if len(wl) == 0 {
return errors.New("models: unable to update oktask, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE `oktask` SET %s WHERE %s",
strmangle.SetParamNames("`", "`", 0, wl),
strmangle.WhereClause("`", "`", 0, oktaskPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(oktaskType, oktaskMapping, append(wl, oktaskPrimaryKeyColumns...))
if err != nil {
return err
}
}
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, values)
}
_, err = exec.Exec(cache.query, values...)
if err != nil {
return errors.Wrap(err, "models: unable to update oktask row")
}
if !cached {
oktaskUpdateCacheMut.Lock()
oktaskUpdateCache[key] = cache
oktaskUpdateCacheMut.Unlock()
}
return o.doAfterUpdateHooks(exec)
}
// UpdateAllP updates all rows with matching column names, and panics on error.
func (q oktaskQuery) UpdateAllP(cols M) {
if err := q.UpdateAll(cols); err != nil {
panic(boil.WrapErr(err))
}
}
// UpdateAll updates all rows with the specified column values.
func (q oktaskQuery) UpdateAll(cols M) error {
queries.SetUpdate(q.Query, cols)
_, err := q.Query.Exec()
if err != nil {
return errors.Wrap(err, "models: unable to update all for oktask")
}
return nil
}
// UpdateAllG updates all rows with the specified column values.
func (o OktaskSlice) UpdateAllG(cols M) error {
return o.UpdateAll(boil.GetDB(), cols)
}
// UpdateAllGP updates all rows with the specified column values, and panics on error.
func (o OktaskSlice) UpdateAllGP(cols M) {
if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
panic(boil.WrapErr(err))
}
}
// UpdateAllP updates all rows with the specified column values, and panics on error.
func (o OktaskSlice) UpdateAllP(exec boil.Executor, cols M) {
if err := o.UpdateAll(exec, cols); err != nil {
panic(boil.WrapErr(err))
}
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o OktaskSlice) UpdateAll(exec boil.Executor, cols M) error {
ln := int64(len(o))
if ln == 0 {
return nil
}
if len(cols) == 0 {
return errors.New("models: update all requires at least one column argument")
}
colNames := make([]string, len(cols))
args := make([]interface{}, len(cols))
i := 0
for name, value := range cols {
colNames[i] = name
args[i] = value
i++
}
// Append all of the primary key values for each column
for _, obj := range o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), oktaskPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf(
"UPDATE `oktask` SET %s WHERE (`id_task`) IN (%s)",
strmangle.SetParamNames("`", "`", 0, colNames),
strmangle.Placeholders(dialect.IndexPlaceholders, len(o)*len(oktaskPrimaryKeyColumns), len(colNames)+1, len(oktaskPrimaryKeyColumns)),
)
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args...)
}
_, err := exec.Exec(sql, args...)
if err != nil {
return errors.Wrap(err, "models: unable to update all in oktask slice")
}
return nil
}
// UpsertG attempts an insert, and does an update or ignore on conflict.
func (o *Oktask) UpsertG(updateColumns []string, whitelist ...string) error {
return o.Upsert(boil.GetDB(), updateColumns, whitelist...)
}
// UpsertGP attempts an insert, and does an update or ignore on conflict. Panics on error.
func (o *Oktask) UpsertGP(updateColumns []string, whitelist ...string) {
if err := o.Upsert(boil.GetDB(), updateColumns, whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// UpsertP attempts an insert using an executor, and does an update or ignore on conflict.
// UpsertP panics on error.
func (o *Oktask) UpsertP(exec boil.Executor, updateColumns []string, whitelist ...string) {
if err := o.Upsert(exec, updateColumns, whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
func (o *Oktask) Upsert(exec boil.Executor, updateColumns []string, whitelist ...string) error {
if o == nil {
return errors.New("models: no oktask provided for upsert")
}
if err := o.doBeforeUpsertHooks(exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(oktaskColumnsWithDefault, o)
// Build cache key in-line uglily - mysql vs postgres problems
buf := strmangle.GetBuffer()
for _, c := range updateColumns {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range whitelist {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range nzDefaults {
buf.WriteString(c)
}
key := buf.String()
strmangle.PutBuffer(buf)
oktaskUpsertCacheMut.RLock()
cache, cached := oktaskUpsertCache[key]
oktaskUpsertCacheMut.RUnlock()
var err error
if !cached {
var ret []string
whitelist, ret = strmangle.InsertColumnSet(
oktaskColumns,
oktaskColumnsWithDefault,
oktaskColumnsWithoutDefault,
nzDefaults,
whitelist,
)
update := strmangle.UpdateColumnSet(
oktaskColumns,
oktaskPrimaryKeyColumns,
updateColumns,
)
if len(update) == 0 {
return errors.New("models: unable to upsert oktask, could not build update column list")
}
cache.query = queries.BuildUpsertQueryMySQL(dialect, "oktask", update, whitelist)
cache.retQuery = fmt.Sprintf(
"SELECT %s FROM `oktask` WHERE `id_task`=?",
strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, ret), ","),
)
cache.valueMapping, err = queries.BindMapping(oktaskType, oktaskMapping, whitelist)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(oktaskType, oktaskMapping, ret)
if err != nil {
return err
}
}
}
value := reflect.Indirect(reflect.ValueOf(o))
vals := queries.ValuesFromMapping(value, cache.valueMapping)
var returns []interface{}
if len(cache.retMapping) != 0 {
returns = queries.PtrsFromMapping(value, cache.retMapping)
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, vals)
}
result, err := exec.Exec(cache.query, vals...)
if err != nil {
return errors.Wrap(err, "models: unable to upsert for oktask")
}
var lastID int64
var identifierCols []interface{}
if len(cache.retMapping) == 0 {
goto CacheNoHooks
}
lastID, err = result.LastInsertId()
if err != nil {
return ErrSyncFail
}
o.IDTask = int(lastID)
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == oktaskMapping["IDTask"] {
goto CacheNoHooks
}
identifierCols = []interface{}{
o.IDTask,
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
fmt.Fprintln(boil.DebugWriter, identifierCols...)
}
err = exec.QueryRow(cache.retQuery, identifierCols...).Scan(returns...)
if err != nil {
return errors.Wrap(err, "models: unable to populate default values for oktask")
}
CacheNoHooks: