-
Notifications
You must be signed in to change notification settings - Fork 927
/
role_menu_options.go
1424 lines (1196 loc) · 43.9 KB
/
role_menu_options.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
// Code generated by SQLBoiler 4.5.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"database/sql"
"fmt"
"reflect"
"strconv"
"strings"
"sync"
"time"
"github.com/friendsofgo/errors"
"github.com/volatiletech/null/v8"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries"
"github.com/volatiletech/sqlboiler/v4/queries/qm"
"github.com/volatiletech/sqlboiler/v4/queries/qmhelper"
"github.com/volatiletech/sqlboiler/v4/types"
"github.com/volatiletech/strmangle"
)
// RoleMenuOption is an object representing the database table.
type RoleMenuOption struct {
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
RoleCommandID null.Int64 `boil:"role_command_id" json:"role_command_id,omitempty" toml:"role_command_id" yaml:"role_command_id,omitempty"`
EmojiID int64 `boil:"emoji_id" json:"emoji_id" toml:"emoji_id" yaml:"emoji_id"`
UnicodeEmoji string `boil:"unicode_emoji" json:"unicode_emoji" toml:"unicode_emoji" yaml:"unicode_emoji"`
RoleMenuID int64 `boil:"role_menu_id" json:"role_menu_id" toml:"role_menu_id" yaml:"role_menu_id"`
StandaloneRoleID null.Int64 `boil:"standalone_role_id" json:"standalone_role_id,omitempty" toml:"standalone_role_id" yaml:"standalone_role_id,omitempty"`
BlacklistRoles types.Int64Array `boil:"blacklist_roles" json:"blacklist_roles,omitempty" toml:"blacklist_roles" yaml:"blacklist_roles,omitempty"`
WhitelistRoles types.Int64Array `boil:"whitelist_roles" json:"whitelist_roles,omitempty" toml:"whitelist_roles" yaml:"whitelist_roles,omitempty"`
EmojiAnimated bool `boil:"emoji_animated" json:"emoji_animated" toml:"emoji_animated" yaml:"emoji_animated"`
R *roleMenuOptionR `boil:"-" json:"-" toml:"-" yaml:"-"`
L roleMenuOptionL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var RoleMenuOptionColumns = struct {
ID string
RoleCommandID string
EmojiID string
UnicodeEmoji string
RoleMenuID string
StandaloneRoleID string
BlacklistRoles string
WhitelistRoles string
EmojiAnimated string
}{
ID: "id",
RoleCommandID: "role_command_id",
EmojiID: "emoji_id",
UnicodeEmoji: "unicode_emoji",
RoleMenuID: "role_menu_id",
StandaloneRoleID: "standalone_role_id",
BlacklistRoles: "blacklist_roles",
WhitelistRoles: "whitelist_roles",
EmojiAnimated: "emoji_animated",
}
// Generated where
var RoleMenuOptionWhere = struct {
ID whereHelperint64
RoleCommandID whereHelpernull_Int64
EmojiID whereHelperint64
UnicodeEmoji whereHelperstring
RoleMenuID whereHelperint64
StandaloneRoleID whereHelpernull_Int64
BlacklistRoles whereHelpertypes_Int64Array
WhitelistRoles whereHelpertypes_Int64Array
EmojiAnimated whereHelperbool
}{
ID: whereHelperint64{field: "\"role_menu_options\".\"id\""},
RoleCommandID: whereHelpernull_Int64{field: "\"role_menu_options\".\"role_command_id\""},
EmojiID: whereHelperint64{field: "\"role_menu_options\".\"emoji_id\""},
UnicodeEmoji: whereHelperstring{field: "\"role_menu_options\".\"unicode_emoji\""},
RoleMenuID: whereHelperint64{field: "\"role_menu_options\".\"role_menu_id\""},
StandaloneRoleID: whereHelpernull_Int64{field: "\"role_menu_options\".\"standalone_role_id\""},
BlacklistRoles: whereHelpertypes_Int64Array{field: "\"role_menu_options\".\"blacklist_roles\""},
WhitelistRoles: whereHelpertypes_Int64Array{field: "\"role_menu_options\".\"whitelist_roles\""},
EmojiAnimated: whereHelperbool{field: "\"role_menu_options\".\"emoji_animated\""},
}
// RoleMenuOptionRels is where relationship names are stored.
var RoleMenuOptionRels = struct {
RoleCommand string
RoleMenu string
EditingOptionRoleMenus string
}{
RoleCommand: "RoleCommand",
RoleMenu: "RoleMenu",
EditingOptionRoleMenus: "EditingOptionRoleMenus",
}
// roleMenuOptionR is where relationships are stored.
type roleMenuOptionR struct {
RoleCommand *RoleCommand `boil:"RoleCommand" json:"RoleCommand" toml:"RoleCommand" yaml:"RoleCommand"`
RoleMenu *RoleMenu `boil:"RoleMenu" json:"RoleMenu" toml:"RoleMenu" yaml:"RoleMenu"`
EditingOptionRoleMenus RoleMenuSlice `boil:"EditingOptionRoleMenus" json:"EditingOptionRoleMenus" toml:"EditingOptionRoleMenus" yaml:"EditingOptionRoleMenus"`
}
// NewStruct creates a new relationship struct
func (*roleMenuOptionR) NewStruct() *roleMenuOptionR {
return &roleMenuOptionR{}
}
// roleMenuOptionL is where Load methods for each relationship are stored.
type roleMenuOptionL struct{}
var (
roleMenuOptionAllColumns = []string{"id", "role_command_id", "emoji_id", "unicode_emoji", "role_menu_id", "standalone_role_id", "blacklist_roles", "whitelist_roles", "emoji_animated"}
roleMenuOptionColumnsWithoutDefault = []string{"role_command_id", "emoji_id", "unicode_emoji", "role_menu_id", "standalone_role_id", "blacklist_roles", "whitelist_roles"}
roleMenuOptionColumnsWithDefault = []string{"id", "emoji_animated"}
roleMenuOptionPrimaryKeyColumns = []string{"id"}
)
type (
// RoleMenuOptionSlice is an alias for a slice of pointers to RoleMenuOption.
// This should generally be used opposed to []RoleMenuOption.
RoleMenuOptionSlice []*RoleMenuOption
roleMenuOptionQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
roleMenuOptionType = reflect.TypeOf(&RoleMenuOption{})
roleMenuOptionMapping = queries.MakeStructMapping(roleMenuOptionType)
roleMenuOptionPrimaryKeyMapping, _ = queries.BindMapping(roleMenuOptionType, roleMenuOptionMapping, roleMenuOptionPrimaryKeyColumns)
roleMenuOptionInsertCacheMut sync.RWMutex
roleMenuOptionInsertCache = make(map[string]insertCache)
roleMenuOptionUpdateCacheMut sync.RWMutex
roleMenuOptionUpdateCache = make(map[string]updateCache)
roleMenuOptionUpsertCacheMut sync.RWMutex
roleMenuOptionUpsertCache = make(map[string]insertCache)
)
var (
// Force time package dependency for automated UpdatedAt/CreatedAt.
_ = time.Second
// Force qmhelper dependency for where clause generation (which doesn't
// always happen)
_ = qmhelper.Where
)
// OneG returns a single roleMenuOption record from the query using the global executor.
func (q roleMenuOptionQuery) OneG(ctx context.Context) (*RoleMenuOption, error) {
return q.One(ctx, boil.GetContextDB())
}
// One returns a single roleMenuOption record from the query.
func (q roleMenuOptionQuery) One(ctx context.Context, exec boil.ContextExecutor) (*RoleMenuOption, error) {
o := &RoleMenuOption{}
queries.SetLimit(q.Query, 1)
err := q.Bind(ctx, exec, 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 role_menu_options")
}
return o, nil
}
// AllG returns all RoleMenuOption records from the query using the global executor.
func (q roleMenuOptionQuery) AllG(ctx context.Context) (RoleMenuOptionSlice, error) {
return q.All(ctx, boil.GetContextDB())
}
// All returns all RoleMenuOption records from the query.
func (q roleMenuOptionQuery) All(ctx context.Context, exec boil.ContextExecutor) (RoleMenuOptionSlice, error) {
var o []*RoleMenuOption
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "models: failed to assign all query results to RoleMenuOption slice")
}
return o, nil
}
// CountG returns the count of all RoleMenuOption records in the query, and panics on error.
func (q roleMenuOptionQuery) CountG(ctx context.Context) (int64, error) {
return q.Count(ctx, boil.GetContextDB())
}
// Count returns the count of all RoleMenuOption records in the query.
func (q roleMenuOptionQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
var count int64
queries.SetSelect(q.Query, nil)
queries.SetCount(q.Query)
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
if err != nil {
return 0, errors.Wrap(err, "models: failed to count role_menu_options rows")
}
return count, nil
}
// ExistsG checks if the row exists in the table, and panics on error.
func (q roleMenuOptionQuery) ExistsG(ctx context.Context) (bool, error) {
return q.Exists(ctx, boil.GetContextDB())
}
// Exists checks if the row exists in the table.
func (q roleMenuOptionQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
var count int64
queries.SetSelect(q.Query, nil)
queries.SetCount(q.Query)
queries.SetLimit(q.Query, 1)
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
if err != nil {
return false, errors.Wrap(err, "models: failed to check if role_menu_options exists")
}
return count > 0, nil
}
// RoleCommand pointed to by the foreign key.
func (o *RoleMenuOption) RoleCommand(mods ...qm.QueryMod) roleCommandQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.RoleCommandID),
}
queryMods = append(queryMods, mods...)
query := RoleCommands(queryMods...)
queries.SetFrom(query.Query, "\"role_commands\"")
return query
}
// RoleMenu pointed to by the foreign key.
func (o *RoleMenuOption) RoleMenu(mods ...qm.QueryMod) roleMenuQuery {
queryMods := []qm.QueryMod{
qm.Where("\"message_id\" = ?", o.RoleMenuID),
}
queryMods = append(queryMods, mods...)
query := RoleMenus(queryMods...)
queries.SetFrom(query.Query, "\"role_menus\"")
return query
}
// EditingOptionRoleMenus retrieves all the role_menu's RoleMenus with an executor via editing_option_id column.
func (o *RoleMenuOption) EditingOptionRoleMenus(mods ...qm.QueryMod) roleMenuQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"role_menus\".\"editing_option_id\"=?", o.ID),
)
query := RoleMenus(queryMods...)
queries.SetFrom(query.Query, "\"role_menus\"")
if len(queries.GetSelect(query.Query)) == 0 {
queries.SetSelect(query.Query, []string{"\"role_menus\".*"})
}
return query
}
// LoadRoleCommand allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (roleMenuOptionL) LoadRoleCommand(ctx context.Context, e boil.ContextExecutor, singular bool, maybeRoleMenuOption interface{}, mods queries.Applicator) error {
var slice []*RoleMenuOption
var object *RoleMenuOption
if singular {
object = maybeRoleMenuOption.(*RoleMenuOption)
} else {
slice = *maybeRoleMenuOption.(*[]*RoleMenuOption)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &roleMenuOptionR{}
}
if !queries.IsNil(object.RoleCommandID) {
args = append(args, object.RoleCommandID)
}
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &roleMenuOptionR{}
}
for _, a := range args {
if queries.Equal(a, obj.RoleCommandID) {
continue Outer
}
}
if !queries.IsNil(obj.RoleCommandID) {
args = append(args, obj.RoleCommandID)
}
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`role_commands`),
qm.WhereIn(`role_commands.id in ?`, args...),
)
if mods != nil {
mods.Apply(query)
}
results, err := query.QueryContext(ctx, e)
if err != nil {
return errors.Wrap(err, "failed to eager load RoleCommand")
}
var resultSlice []*RoleCommand
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice RoleCommand")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for role_commands")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for role_commands")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.RoleCommand = foreign
if foreign.R == nil {
foreign.R = &roleCommandR{}
}
foreign.R.RoleMenuOptions = append(foreign.R.RoleMenuOptions, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if queries.Equal(local.RoleCommandID, foreign.ID) {
local.R.RoleCommand = foreign
if foreign.R == nil {
foreign.R = &roleCommandR{}
}
foreign.R.RoleMenuOptions = append(foreign.R.RoleMenuOptions, local)
break
}
}
}
return nil
}
// LoadRoleMenu allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (roleMenuOptionL) LoadRoleMenu(ctx context.Context, e boil.ContextExecutor, singular bool, maybeRoleMenuOption interface{}, mods queries.Applicator) error {
var slice []*RoleMenuOption
var object *RoleMenuOption
if singular {
object = maybeRoleMenuOption.(*RoleMenuOption)
} else {
slice = *maybeRoleMenuOption.(*[]*RoleMenuOption)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &roleMenuOptionR{}
}
args = append(args, object.RoleMenuID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &roleMenuOptionR{}
}
for _, a := range args {
if a == obj.RoleMenuID {
continue Outer
}
}
args = append(args, obj.RoleMenuID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`role_menus`),
qm.WhereIn(`role_menus.message_id in ?`, args...),
)
if mods != nil {
mods.Apply(query)
}
results, err := query.QueryContext(ctx, e)
if err != nil {
return errors.Wrap(err, "failed to eager load RoleMenu")
}
var resultSlice []*RoleMenu
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice RoleMenu")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for role_menus")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for role_menus")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.RoleMenu = foreign
if foreign.R == nil {
foreign.R = &roleMenuR{}
}
foreign.R.RoleMenuOptions = append(foreign.R.RoleMenuOptions, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.RoleMenuID == foreign.MessageID {
local.R.RoleMenu = foreign
if foreign.R == nil {
foreign.R = &roleMenuR{}
}
foreign.R.RoleMenuOptions = append(foreign.R.RoleMenuOptions, local)
break
}
}
}
return nil
}
// LoadEditingOptionRoleMenus allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for a 1-M or N-M relationship.
func (roleMenuOptionL) LoadEditingOptionRoleMenus(ctx context.Context, e boil.ContextExecutor, singular bool, maybeRoleMenuOption interface{}, mods queries.Applicator) error {
var slice []*RoleMenuOption
var object *RoleMenuOption
if singular {
object = maybeRoleMenuOption.(*RoleMenuOption)
} else {
slice = *maybeRoleMenuOption.(*[]*RoleMenuOption)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &roleMenuOptionR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &roleMenuOptionR{}
}
for _, a := range args {
if queries.Equal(a, obj.ID) {
continue Outer
}
}
args = append(args, obj.ID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`role_menus`),
qm.WhereIn(`role_menus.editing_option_id in ?`, args...),
)
if mods != nil {
mods.Apply(query)
}
results, err := query.QueryContext(ctx, e)
if err != nil {
return errors.Wrap(err, "failed to eager load role_menus")
}
var resultSlice []*RoleMenu
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice role_menus")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on role_menus")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for role_menus")
}
if singular {
object.R.EditingOptionRoleMenus = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &roleMenuR{}
}
foreign.R.EditingOption = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if queries.Equal(local.ID, foreign.EditingOptionID) {
local.R.EditingOptionRoleMenus = append(local.R.EditingOptionRoleMenus, foreign)
if foreign.R == nil {
foreign.R = &roleMenuR{}
}
foreign.R.EditingOption = local
break
}
}
}
return nil
}
// SetRoleCommandG of the roleMenuOption to the related item.
// Sets o.R.RoleCommand to related.
// Adds o to related.R.RoleMenuOptions.
// Uses the global database handle.
func (o *RoleMenuOption) SetRoleCommandG(ctx context.Context, insert bool, related *RoleCommand) error {
return o.SetRoleCommand(ctx, boil.GetContextDB(), insert, related)
}
// SetRoleCommand of the roleMenuOption to the related item.
// Sets o.R.RoleCommand to related.
// Adds o to related.R.RoleMenuOptions.
func (o *RoleMenuOption) SetRoleCommand(ctx context.Context, exec boil.ContextExecutor, insert bool, related *RoleCommand) error {
var err error
if insert {
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
}
updateQuery := fmt.Sprintf(
"UPDATE \"role_menu_options\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, []string{"role_command_id"}),
strmangle.WhereClause("\"", "\"", 2, roleMenuOptionPrimaryKeyColumns),
)
values := []interface{}{related.ID, o.ID}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, updateQuery)
fmt.Fprintln(writer, values)
}
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update local table")
}
queries.Assign(&o.RoleCommandID, related.ID)
if o.R == nil {
o.R = &roleMenuOptionR{
RoleCommand: related,
}
} else {
o.R.RoleCommand = related
}
if related.R == nil {
related.R = &roleCommandR{
RoleMenuOptions: RoleMenuOptionSlice{o},
}
} else {
related.R.RoleMenuOptions = append(related.R.RoleMenuOptions, o)
}
return nil
}
// RemoveRoleCommandG relationship.
// Sets o.R.RoleCommand to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle.
func (o *RoleMenuOption) RemoveRoleCommandG(ctx context.Context, related *RoleCommand) error {
return o.RemoveRoleCommand(ctx, boil.GetContextDB(), related)
}
// RemoveRoleCommand relationship.
// Sets o.R.RoleCommand to nil.
// Removes o from all passed in related items' relationships struct (Optional).
func (o *RoleMenuOption) RemoveRoleCommand(ctx context.Context, exec boil.ContextExecutor, related *RoleCommand) error {
var err error
queries.SetScanner(&o.RoleCommandID, nil)
if _, err = o.Update(ctx, exec, boil.Whitelist("role_command_id")); err != nil {
return errors.Wrap(err, "failed to update local table")
}
if o.R != nil {
o.R.RoleCommand = nil
}
if related == nil || related.R == nil {
return nil
}
for i, ri := range related.R.RoleMenuOptions {
if queries.Equal(o.RoleCommandID, ri.RoleCommandID) {
continue
}
ln := len(related.R.RoleMenuOptions)
if ln > 1 && i < ln-1 {
related.R.RoleMenuOptions[i] = related.R.RoleMenuOptions[ln-1]
}
related.R.RoleMenuOptions = related.R.RoleMenuOptions[:ln-1]
break
}
return nil
}
// SetRoleMenuG of the roleMenuOption to the related item.
// Sets o.R.RoleMenu to related.
// Adds o to related.R.RoleMenuOptions.
// Uses the global database handle.
func (o *RoleMenuOption) SetRoleMenuG(ctx context.Context, insert bool, related *RoleMenu) error {
return o.SetRoleMenu(ctx, boil.GetContextDB(), insert, related)
}
// SetRoleMenu of the roleMenuOption to the related item.
// Sets o.R.RoleMenu to related.
// Adds o to related.R.RoleMenuOptions.
func (o *RoleMenuOption) SetRoleMenu(ctx context.Context, exec boil.ContextExecutor, insert bool, related *RoleMenu) error {
var err error
if insert {
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
}
updateQuery := fmt.Sprintf(
"UPDATE \"role_menu_options\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, []string{"role_menu_id"}),
strmangle.WhereClause("\"", "\"", 2, roleMenuOptionPrimaryKeyColumns),
)
values := []interface{}{related.MessageID, o.ID}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, updateQuery)
fmt.Fprintln(writer, values)
}
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update local table")
}
o.RoleMenuID = related.MessageID
if o.R == nil {
o.R = &roleMenuOptionR{
RoleMenu: related,
}
} else {
o.R.RoleMenu = related
}
if related.R == nil {
related.R = &roleMenuR{
RoleMenuOptions: RoleMenuOptionSlice{o},
}
} else {
related.R.RoleMenuOptions = append(related.R.RoleMenuOptions, o)
}
return nil
}
// AddEditingOptionRoleMenusG adds the given related objects to the existing relationships
// of the role_menu_option, optionally inserting them as new records.
// Appends related to o.R.EditingOptionRoleMenus.
// Sets related.R.EditingOption appropriately.
// Uses the global database handle.
func (o *RoleMenuOption) AddEditingOptionRoleMenusG(ctx context.Context, insert bool, related ...*RoleMenu) error {
return o.AddEditingOptionRoleMenus(ctx, boil.GetContextDB(), insert, related...)
}
// AddEditingOptionRoleMenus adds the given related objects to the existing relationships
// of the role_menu_option, optionally inserting them as new records.
// Appends related to o.R.EditingOptionRoleMenus.
// Sets related.R.EditingOption appropriately.
func (o *RoleMenuOption) AddEditingOptionRoleMenus(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*RoleMenu) error {
var err error
for _, rel := range related {
if insert {
queries.Assign(&rel.EditingOptionID, o.ID)
if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
} else {
updateQuery := fmt.Sprintf(
"UPDATE \"role_menus\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, []string{"editing_option_id"}),
strmangle.WhereClause("\"", "\"", 2, roleMenuPrimaryKeyColumns),
)
values := []interface{}{o.ID, rel.MessageID}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, updateQuery)
fmt.Fprintln(writer, values)
}
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update foreign table")
}
queries.Assign(&rel.EditingOptionID, o.ID)
}
}
if o.R == nil {
o.R = &roleMenuOptionR{
EditingOptionRoleMenus: related,
}
} else {
o.R.EditingOptionRoleMenus = append(o.R.EditingOptionRoleMenus, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &roleMenuR{
EditingOption: o,
}
} else {
rel.R.EditingOption = o
}
}
return nil
}
// SetEditingOptionRoleMenusG removes all previously related items of the
// role_menu_option replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.EditingOption's EditingOptionRoleMenus accordingly.
// Replaces o.R.EditingOptionRoleMenus with related.
// Sets related.R.EditingOption's EditingOptionRoleMenus accordingly.
// Uses the global database handle.
func (o *RoleMenuOption) SetEditingOptionRoleMenusG(ctx context.Context, insert bool, related ...*RoleMenu) error {
return o.SetEditingOptionRoleMenus(ctx, boil.GetContextDB(), insert, related...)
}
// SetEditingOptionRoleMenus removes all previously related items of the
// role_menu_option replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.EditingOption's EditingOptionRoleMenus accordingly.
// Replaces o.R.EditingOptionRoleMenus with related.
// Sets related.R.EditingOption's EditingOptionRoleMenus accordingly.
func (o *RoleMenuOption) SetEditingOptionRoleMenus(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*RoleMenu) error {
query := "update \"role_menus\" set \"editing_option_id\" = null where \"editing_option_id\" = $1"
values := []interface{}{o.ID}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, query)
fmt.Fprintln(writer, values)
}
_, err := exec.ExecContext(ctx, query, values...)
if err != nil {
return errors.Wrap(err, "failed to remove relationships before set")
}
if o.R != nil {
for _, rel := range o.R.EditingOptionRoleMenus {
queries.SetScanner(&rel.EditingOptionID, nil)
if rel.R == nil {
continue
}
rel.R.EditingOption = nil
}
o.R.EditingOptionRoleMenus = nil
}
return o.AddEditingOptionRoleMenus(ctx, exec, insert, related...)
}
// RemoveEditingOptionRoleMenusG relationships from objects passed in.
// Removes related items from R.EditingOptionRoleMenus (uses pointer comparison, removal does not keep order)
// Sets related.R.EditingOption.
// Uses the global database handle.
func (o *RoleMenuOption) RemoveEditingOptionRoleMenusG(ctx context.Context, related ...*RoleMenu) error {
return o.RemoveEditingOptionRoleMenus(ctx, boil.GetContextDB(), related...)
}
// RemoveEditingOptionRoleMenus relationships from objects passed in.
// Removes related items from R.EditingOptionRoleMenus (uses pointer comparison, removal does not keep order)
// Sets related.R.EditingOption.
func (o *RoleMenuOption) RemoveEditingOptionRoleMenus(ctx context.Context, exec boil.ContextExecutor, related ...*RoleMenu) error {
var err error
for _, rel := range related {
queries.SetScanner(&rel.EditingOptionID, nil)
if rel.R != nil {
rel.R.EditingOption = nil
}
if _, err = rel.Update(ctx, exec, boil.Whitelist("editing_option_id")); err != nil {
return err
}
}
if o.R == nil {
return nil
}
for _, rel := range related {
for i, ri := range o.R.EditingOptionRoleMenus {
if rel != ri {
continue
}
ln := len(o.R.EditingOptionRoleMenus)
if ln > 1 && i < ln-1 {
o.R.EditingOptionRoleMenus[i] = o.R.EditingOptionRoleMenus[ln-1]
}
o.R.EditingOptionRoleMenus = o.R.EditingOptionRoleMenus[:ln-1]
break
}
}
return nil
}
// RoleMenuOptions retrieves all the records using an executor.
func RoleMenuOptions(mods ...qm.QueryMod) roleMenuOptionQuery {
mods = append(mods, qm.From("\"role_menu_options\""))
return roleMenuOptionQuery{NewQuery(mods...)}
}
// FindRoleMenuOptionG retrieves a single record by ID.
func FindRoleMenuOptionG(ctx context.Context, iD int64, selectCols ...string) (*RoleMenuOption, error) {
return FindRoleMenuOption(ctx, boil.GetContextDB(), iD, selectCols...)
}
// FindRoleMenuOption retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindRoleMenuOption(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*RoleMenuOption, error) {
roleMenuOptionObj := &RoleMenuOption{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"role_menu_options\" where \"id\"=$1", sel,
)
q := queries.Raw(query, iD)
err := q.Bind(ctx, exec, roleMenuOptionObj)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: unable to select from role_menu_options")
}
return roleMenuOptionObj, nil
}
// InsertG a single record. See Insert for whitelist behavior description.
func (o *RoleMenuOption) InsertG(ctx context.Context, columns boil.Columns) error {
return o.Insert(ctx, boil.GetContextDB(), columns)
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *RoleMenuOption) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("models: no role_menu_options provided for insertion")
}
var err error
nzDefaults := queries.NonZeroDefaultSet(roleMenuOptionColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
roleMenuOptionInsertCacheMut.RLock()
cache, cached := roleMenuOptionInsertCache[key]
roleMenuOptionInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
roleMenuOptionAllColumns,
roleMenuOptionColumnsWithDefault,
roleMenuOptionColumnsWithoutDefault,
nzDefaults,
)
cache.valueMapping, err = queries.BindMapping(roleMenuOptionType, roleMenuOptionMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(roleMenuOptionType, roleMenuOptionMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"role_menu_options\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"role_menu_options\" %sDEFAULT VALUES%s"
}
var queryOutput, queryReturning string
if len(cache.retMapping) != 0 {
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
}
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
}
value := reflect.Indirect(reflect.ValueOf(o))
vals := queries.ValuesFromMapping(value, cache.valueMapping)
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, cache.query)
fmt.Fprintln(writer, vals)
}
if len(cache.retMapping) != 0 {
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
} else {
_, err = exec.ExecContext(ctx, cache.query, vals...)
}
if err != nil {
return errors.Wrap(err, "models: unable to insert into role_menu_options")
}
if !cached {
roleMenuOptionInsertCacheMut.Lock()
roleMenuOptionInsertCache[key] = cache
roleMenuOptionInsertCacheMut.Unlock()
}
return nil
}
// UpdateG a single RoleMenuOption record using the global executor.
// See Update for more documentation.
func (o *RoleMenuOption) UpdateG(ctx context.Context, columns boil.Columns) (int64, error) {
return o.Update(ctx, boil.GetContextDB(), columns)
}
// Update uses an executor to update the RoleMenuOption.
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
func (o *RoleMenuOption) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
key := makeCacheKey(columns, nil)
roleMenuOptionUpdateCacheMut.RLock()
cache, cached := roleMenuOptionUpdateCache[key]