-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_permissions.go
1273 lines (1059 loc) · 37.1 KB
/
channel_permissions.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.2.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/strmangle"
)
// ChannelPermission is an object representing the database table.
type ChannelPermission struct {
ChannelID int `boil:"channel_id" json:"channel_id" toml:"channel_id" yaml:"channel_id"`
UserID int `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
Permission null.Int `boil:"permission" json:"permission,omitempty" toml:"permission" yaml:"permission,omitempty"`
CreatedAt null.Time `boil:"created_at" json:"created_at,omitempty" toml:"created_at" yaml:"created_at,omitempty"`
UpdatedAt null.Time `boil:"updated_at" json:"updated_at,omitempty" toml:"updated_at" yaml:"updated_at,omitempty"`
DeletedAt null.Time `boil:"deleted_at" json:"deleted_at,omitempty" toml:"deleted_at" yaml:"deleted_at,omitempty"`
R *channelPermissionR `boil:"-" json:"-" toml:"-" yaml:"-"`
L channelPermissionL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var ChannelPermissionColumns = struct {
ChannelID string
UserID string
Permission string
CreatedAt string
UpdatedAt string
DeletedAt string
}{
ChannelID: "channel_id",
UserID: "user_id",
Permission: "permission",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
}
// Generated where
type whereHelpernull_Int struct{ field string }
func (w whereHelpernull_Int) EQ(x null.Int) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, false, x)
}
func (w whereHelpernull_Int) NEQ(x null.Int) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, true, x)
}
func (w whereHelpernull_Int) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) }
func (w whereHelpernull_Int) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) }
func (w whereHelpernull_Int) LT(x null.Int) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LT, x)
}
func (w whereHelpernull_Int) LTE(x null.Int) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelpernull_Int) GT(x null.Int) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GT, x)
}
func (w whereHelpernull_Int) GTE(x null.Int) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
var ChannelPermissionWhere = struct {
ChannelID whereHelperint
UserID whereHelperint
Permission whereHelpernull_Int
CreatedAt whereHelpernull_Time
UpdatedAt whereHelpernull_Time
DeletedAt whereHelpernull_Time
}{
ChannelID: whereHelperint{field: "\"channel_permissions\".\"channel_id\""},
UserID: whereHelperint{field: "\"channel_permissions\".\"user_id\""},
Permission: whereHelpernull_Int{field: "\"channel_permissions\".\"permission\""},
CreatedAt: whereHelpernull_Time{field: "\"channel_permissions\".\"created_at\""},
UpdatedAt: whereHelpernull_Time{field: "\"channel_permissions\".\"updated_at\""},
DeletedAt: whereHelpernull_Time{field: "\"channel_permissions\".\"deleted_at\""},
}
// ChannelPermissionRels is where relationship names are stored.
var ChannelPermissionRels = struct {
Channel string
User string
}{
Channel: "Channel",
User: "User",
}
// channelPermissionR is where relationships are stored.
type channelPermissionR struct {
Channel *Channel `boil:"Channel" json:"Channel" toml:"Channel" yaml:"Channel"`
User *User `boil:"User" json:"User" toml:"User" yaml:"User"`
}
// NewStruct creates a new relationship struct
func (*channelPermissionR) NewStruct() *channelPermissionR {
return &channelPermissionR{}
}
// channelPermissionL is where Load methods for each relationship are stored.
type channelPermissionL struct{}
var (
channelPermissionAllColumns = []string{"channel_id", "user_id", "permission", "created_at", "updated_at", "deleted_at"}
channelPermissionColumnsWithoutDefault = []string{"channel_id", "user_id", "permission", "deleted_at"}
channelPermissionColumnsWithDefault = []string{"created_at", "updated_at"}
channelPermissionPrimaryKeyColumns = []string{"channel_id", "user_id"}
)
type (
// ChannelPermissionSlice is an alias for a slice of pointers to ChannelPermission.
// This should generally be used opposed to []ChannelPermission.
ChannelPermissionSlice []*ChannelPermission
// ChannelPermissionHook is the signature for custom ChannelPermission hook methods
ChannelPermissionHook func(context.Context, boil.ContextExecutor, *ChannelPermission) error
channelPermissionQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
channelPermissionType = reflect.TypeOf(&ChannelPermission{})
channelPermissionMapping = queries.MakeStructMapping(channelPermissionType)
channelPermissionPrimaryKeyMapping, _ = queries.BindMapping(channelPermissionType, channelPermissionMapping, channelPermissionPrimaryKeyColumns)
channelPermissionInsertCacheMut sync.RWMutex
channelPermissionInsertCache = make(map[string]insertCache)
channelPermissionUpdateCacheMut sync.RWMutex
channelPermissionUpdateCache = make(map[string]updateCache)
channelPermissionUpsertCacheMut sync.RWMutex
channelPermissionUpsertCache = 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
)
var channelPermissionBeforeInsertHooks []ChannelPermissionHook
var channelPermissionBeforeUpdateHooks []ChannelPermissionHook
var channelPermissionBeforeDeleteHooks []ChannelPermissionHook
var channelPermissionBeforeUpsertHooks []ChannelPermissionHook
var channelPermissionAfterInsertHooks []ChannelPermissionHook
var channelPermissionAfterSelectHooks []ChannelPermissionHook
var channelPermissionAfterUpdateHooks []ChannelPermissionHook
var channelPermissionAfterDeleteHooks []ChannelPermissionHook
var channelPermissionAfterUpsertHooks []ChannelPermissionHook
// doBeforeInsertHooks executes all "before insert" hooks.
func (o *ChannelPermission) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionBeforeInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpdateHooks executes all "before Update" hooks.
func (o *ChannelPermission) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionBeforeUpdateHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeDeleteHooks executes all "before Delete" hooks.
func (o *ChannelPermission) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionBeforeDeleteHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpsertHooks executes all "before Upsert" hooks.
func (o *ChannelPermission) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionBeforeUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterInsertHooks executes all "after Insert" hooks.
func (o *ChannelPermission) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionAfterInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterSelectHooks executes all "after Select" hooks.
func (o *ChannelPermission) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionAfterSelectHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpdateHooks executes all "after Update" hooks.
func (o *ChannelPermission) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionAfterUpdateHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterDeleteHooks executes all "after Delete" hooks.
func (o *ChannelPermission) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionAfterDeleteHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpsertHooks executes all "after Upsert" hooks.
func (o *ChannelPermission) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range channelPermissionAfterUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// AddChannelPermissionHook registers your hook function for all future operations.
func AddChannelPermissionHook(hookPoint boil.HookPoint, channelPermissionHook ChannelPermissionHook) {
switch hookPoint {
case boil.BeforeInsertHook:
channelPermissionBeforeInsertHooks = append(channelPermissionBeforeInsertHooks, channelPermissionHook)
case boil.BeforeUpdateHook:
channelPermissionBeforeUpdateHooks = append(channelPermissionBeforeUpdateHooks, channelPermissionHook)
case boil.BeforeDeleteHook:
channelPermissionBeforeDeleteHooks = append(channelPermissionBeforeDeleteHooks, channelPermissionHook)
case boil.BeforeUpsertHook:
channelPermissionBeforeUpsertHooks = append(channelPermissionBeforeUpsertHooks, channelPermissionHook)
case boil.AfterInsertHook:
channelPermissionAfterInsertHooks = append(channelPermissionAfterInsertHooks, channelPermissionHook)
case boil.AfterSelectHook:
channelPermissionAfterSelectHooks = append(channelPermissionAfterSelectHooks, channelPermissionHook)
case boil.AfterUpdateHook:
channelPermissionAfterUpdateHooks = append(channelPermissionAfterUpdateHooks, channelPermissionHook)
case boil.AfterDeleteHook:
channelPermissionAfterDeleteHooks = append(channelPermissionAfterDeleteHooks, channelPermissionHook)
case boil.AfterUpsertHook:
channelPermissionAfterUpsertHooks = append(channelPermissionAfterUpsertHooks, channelPermissionHook)
}
}
// One returns a single channelPermission record from the query.
func (q channelPermissionQuery) One(ctx context.Context, exec boil.ContextExecutor) (*ChannelPermission, error) {
o := &ChannelPermission{}
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 channel_permissions")
}
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
return o, nil
}
// All returns all ChannelPermission records from the query.
func (q channelPermissionQuery) All(ctx context.Context, exec boil.ContextExecutor) (ChannelPermissionSlice, error) {
var o []*ChannelPermission
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "models: failed to assign all query results to ChannelPermission slice")
}
if len(channelPermissionAfterSelectHooks) != 0 {
for _, obj := range o {
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
}
}
return o, nil
}
// Count returns the count of all ChannelPermission records in the query.
func (q channelPermissionQuery) 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 channel_permissions rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q channelPermissionQuery) 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 channel_permissions exists")
}
return count > 0, nil
}
// Channel pointed to by the foreign key.
func (o *ChannelPermission) Channel(mods ...qm.QueryMod) channelQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.ChannelID),
}
queryMods = append(queryMods, mods...)
query := Channels(queryMods...)
queries.SetFrom(query.Query, "\"channels\"")
return query
}
// User pointed to by the foreign key.
func (o *ChannelPermission) User(mods ...qm.QueryMod) userQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.UserID),
}
queryMods = append(queryMods, mods...)
query := Users(queryMods...)
queries.SetFrom(query.Query, "\"users\"")
return query
}
// LoadChannel allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (channelPermissionL) LoadChannel(ctx context.Context, e boil.ContextExecutor, singular bool, maybeChannelPermission interface{}, mods queries.Applicator) error {
var slice []*ChannelPermission
var object *ChannelPermission
if singular {
object = maybeChannelPermission.(*ChannelPermission)
} else {
slice = *maybeChannelPermission.(*[]*ChannelPermission)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &channelPermissionR{}
}
args = append(args, object.ChannelID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &channelPermissionR{}
}
for _, a := range args {
if a == obj.ChannelID {
continue Outer
}
}
args = append(args, obj.ChannelID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`channels`),
qm.WhereIn(`channels.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 Channel")
}
var resultSlice []*Channel
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Channel")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for channels")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for channels")
}
if len(channelPermissionAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
return err
}
}
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Channel = foreign
if foreign.R == nil {
foreign.R = &channelR{}
}
foreign.R.ChannelPermissions = append(foreign.R.ChannelPermissions, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.ChannelID == foreign.ID {
local.R.Channel = foreign
if foreign.R == nil {
foreign.R = &channelR{}
}
foreign.R.ChannelPermissions = append(foreign.R.ChannelPermissions, local)
break
}
}
}
return nil
}
// LoadUser allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (channelPermissionL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybeChannelPermission interface{}, mods queries.Applicator) error {
var slice []*ChannelPermission
var object *ChannelPermission
if singular {
object = maybeChannelPermission.(*ChannelPermission)
} else {
slice = *maybeChannelPermission.(*[]*ChannelPermission)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &channelPermissionR{}
}
args = append(args, object.UserID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &channelPermissionR{}
}
for _, a := range args {
if a == obj.UserID {
continue Outer
}
}
args = append(args, obj.UserID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`users`),
qm.WhereIn(`users.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 User")
}
var resultSlice []*User
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice User")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for users")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for users")
}
if len(channelPermissionAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
return err
}
}
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.User = foreign
if foreign.R == nil {
foreign.R = &userR{}
}
foreign.R.ChannelPermissions = append(foreign.R.ChannelPermissions, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.UserID == foreign.ID {
local.R.User = foreign
if foreign.R == nil {
foreign.R = &userR{}
}
foreign.R.ChannelPermissions = append(foreign.R.ChannelPermissions, local)
break
}
}
}
return nil
}
// SetChannel of the channelPermission to the related item.
// Sets o.R.Channel to related.
// Adds o to related.R.ChannelPermissions.
func (o *ChannelPermission) SetChannel(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Channel) 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 \"channel_permissions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, []string{"channel_id"}),
strmangle.WhereClause("\"", "\"", 2, channelPermissionPrimaryKeyColumns),
)
values := []interface{}{related.ID, o.ChannelID, o.UserID}
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.ChannelID = related.ID
if o.R == nil {
o.R = &channelPermissionR{
Channel: related,
}
} else {
o.R.Channel = related
}
if related.R == nil {
related.R = &channelR{
ChannelPermissions: ChannelPermissionSlice{o},
}
} else {
related.R.ChannelPermissions = append(related.R.ChannelPermissions, o)
}
return nil
}
// SetUser of the channelPermission to the related item.
// Sets o.R.User to related.
// Adds o to related.R.ChannelPermissions.
func (o *ChannelPermission) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) 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 \"channel_permissions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
strmangle.WhereClause("\"", "\"", 2, channelPermissionPrimaryKeyColumns),
)
values := []interface{}{related.ID, o.ChannelID, o.UserID}
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.UserID = related.ID
if o.R == nil {
o.R = &channelPermissionR{
User: related,
}
} else {
o.R.User = related
}
if related.R == nil {
related.R = &userR{
ChannelPermissions: ChannelPermissionSlice{o},
}
} else {
related.R.ChannelPermissions = append(related.R.ChannelPermissions, o)
}
return nil
}
// ChannelPermissions retrieves all the records using an executor.
func ChannelPermissions(mods ...qm.QueryMod) channelPermissionQuery {
mods = append(mods, qm.From("\"channel_permissions\""))
return channelPermissionQuery{NewQuery(mods...)}
}
// FindChannelPermission retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindChannelPermission(ctx context.Context, exec boil.ContextExecutor, channelID int, userID int, selectCols ...string) (*ChannelPermission, error) {
channelPermissionObj := &ChannelPermission{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"channel_permissions\" where \"channel_id\"=$1 AND \"user_id\"=$2", sel,
)
q := queries.Raw(query, channelID, userID)
err := q.Bind(ctx, exec, channelPermissionObj)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: unable to select from channel_permissions")
}
return channelPermissionObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *ChannelPermission) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("models: no channel_permissions provided for insertion")
}
var err error
if !boil.TimestampsAreSkipped(ctx) {
currTime := time.Now().In(boil.GetLocation())
if queries.MustTime(o.CreatedAt).IsZero() {
queries.SetScanner(&o.CreatedAt, currTime)
}
if queries.MustTime(o.UpdatedAt).IsZero() {
queries.SetScanner(&o.UpdatedAt, currTime)
}
}
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(channelPermissionColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
channelPermissionInsertCacheMut.RLock()
cache, cached := channelPermissionInsertCache[key]
channelPermissionInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
channelPermissionAllColumns,
channelPermissionColumnsWithDefault,
channelPermissionColumnsWithoutDefault,
nzDefaults,
)
cache.valueMapping, err = queries.BindMapping(channelPermissionType, channelPermissionMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(channelPermissionType, channelPermissionMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"channel_permissions\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"channel_permissions\" %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 channel_permissions")
}
if !cached {
channelPermissionInsertCacheMut.Lock()
channelPermissionInsertCache[key] = cache
channelPermissionInsertCacheMut.Unlock()
}
return o.doAfterInsertHooks(ctx, exec)
}
// Update uses an executor to update the ChannelPermission.
// 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 *ChannelPermission) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
if !boil.TimestampsAreSkipped(ctx) {
currTime := time.Now().In(boil.GetLocation())
queries.SetScanner(&o.UpdatedAt, currTime)
}
var err error
if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
return 0, err
}
key := makeCacheKey(columns, nil)
channelPermissionUpdateCacheMut.RLock()
cache, cached := channelPermissionUpdateCache[key]
channelPermissionUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
channelPermissionAllColumns,
channelPermissionPrimaryKeyColumns,
)
if !columns.IsWhitelist() {
wl = strmangle.SetComplement(wl, []string{"created_at"})
}
if len(wl) == 0 {
return 0, errors.New("models: unable to update channel_permissions, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"channel_permissions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, wl),
strmangle.WhereClause("\"", "\"", len(wl)+1, channelPermissionPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(channelPermissionType, channelPermissionMapping, append(wl, channelPermissionPrimaryKeyColumns...))
if err != nil {
return 0, err
}
}
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, cache.query)
fmt.Fprintln(writer, values)
}
var result sql.Result
result, err = exec.ExecContext(ctx, cache.query, values...)
if err != nil {
return 0, errors.Wrap(err, "models: unable to update channel_permissions row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by update for channel_permissions")
}
if !cached {
channelPermissionUpdateCacheMut.Lock()
channelPermissionUpdateCache[key] = cache
channelPermissionUpdateCacheMut.Unlock()
}
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
}
// UpdateAll updates all rows with the specified column values.
func (q channelPermissionQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
queries.SetUpdate(q.Query, cols)
result, err := q.Query.ExecContext(ctx, exec)
if err != nil {
return 0, errors.Wrap(err, "models: unable to update all for channel_permissions")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for channel_permissions")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o ChannelPermissionSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
ln := int64(len(o))
if ln == 0 {
return 0, nil
}
if len(cols) == 0 {
return 0, 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)), channelPermissionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"channel_permissions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, channelPermissionPrimaryKeyColumns, len(o)))
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, sql)
fmt.Fprintln(writer, args...)
}
result, err := exec.ExecContext(ctx, sql, args...)
if err != nil {
return 0, errors.Wrap(err, "models: unable to update all in channelPermission slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all channelPermission")
}
return rowsAff, nil
}
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
func (o *ChannelPermission) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
if o == nil {
return errors.New("models: no channel_permissions provided for upsert")
}
if !boil.TimestampsAreSkipped(ctx) {
currTime := time.Now().In(boil.GetLocation())
if queries.MustTime(o.CreatedAt).IsZero() {
queries.SetScanner(&o.CreatedAt, currTime)
}
queries.SetScanner(&o.UpdatedAt, currTime)
}
if err := o.doBeforeUpsertHooks(ctx, exec); err != nil {