-
Notifications
You must be signed in to change notification settings - Fork 938
/
custom_commands.go
1144 lines (959 loc) · 41.3 KB
/
custom_commands.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 (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/pkg/errors"
"github.com/volatiletech/null"
"github.com/volatiletech/sqlboiler/boil"
"github.com/volatiletech/sqlboiler/queries"
"github.com/volatiletech/sqlboiler/queries/qm"
"github.com/volatiletech/sqlboiler/queries/qmhelper"
"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/sqlboiler/types"
)
// CustomCommand is an object representing the database table.
type CustomCommand struct {
LocalID int64 `boil:"local_id" json:"local_id" toml:"local_id" yaml:"local_id"`
GuildID int64 `boil:"guild_id" json:"guild_id" toml:"guild_id" yaml:"guild_id"`
GroupID null.Int64 `boil:"group_id" json:"group_id,omitempty" toml:"group_id" yaml:"group_id,omitempty"`
TriggerType int `boil:"trigger_type" json:"trigger_type" toml:"trigger_type" yaml:"trigger_type"`
TextTrigger string `boil:"text_trigger" json:"text_trigger" toml:"text_trigger" yaml:"text_trigger"`
TextTriggerCaseSensitive bool `boil:"text_trigger_case_sensitive" json:"text_trigger_case_sensitive" toml:"text_trigger_case_sensitive" yaml:"text_trigger_case_sensitive"`
TimeTriggerInterval int `boil:"time_trigger_interval" json:"time_trigger_interval" toml:"time_trigger_interval" yaml:"time_trigger_interval"`
TimeTriggerExcludingDays types.Int64Array `boil:"time_trigger_excluding_days" json:"time_trigger_excluding_days" toml:"time_trigger_excluding_days" yaml:"time_trigger_excluding_days"`
TimeTriggerExcludingHours types.Int64Array `boil:"time_trigger_excluding_hours" json:"time_trigger_excluding_hours" toml:"time_trigger_excluding_hours" yaml:"time_trigger_excluding_hours"`
LastRun null.Time `boil:"last_run" json:"last_run,omitempty" toml:"last_run" yaml:"last_run,omitempty"`
NextRun null.Time `boil:"next_run" json:"next_run,omitempty" toml:"next_run" yaml:"next_run,omitempty"`
Responses types.StringArray `boil:"responses" json:"responses" toml:"responses" yaml:"responses"`
Channels types.Int64Array `boil:"channels" json:"channels,omitempty" toml:"channels" yaml:"channels,omitempty"`
ChannelsWhitelistMode bool `boil:"channels_whitelist_mode" json:"channels_whitelist_mode" toml:"channels_whitelist_mode" yaml:"channels_whitelist_mode"`
Roles types.Int64Array `boil:"roles" json:"roles,omitempty" toml:"roles" yaml:"roles,omitempty"`
RolesWhitelistMode bool `boil:"roles_whitelist_mode" json:"roles_whitelist_mode" toml:"roles_whitelist_mode" yaml:"roles_whitelist_mode"`
ContextChannel int64 `boil:"context_channel" json:"context_channel" toml:"context_channel" yaml:"context_channel"`
ReactionTriggerMode int16 `boil:"reaction_trigger_mode" json:"reaction_trigger_mode" toml:"reaction_trigger_mode" yaml:"reaction_trigger_mode"`
Disabled bool `boil:"disabled" json:"disabled" toml:"disabled" yaml:"disabled"`
LastError string `boil:"last_error" json:"last_error" toml:"last_error" yaml:"last_error"`
LastErrorTime null.Time `boil:"last_error_time" json:"last_error_time,omitempty" toml:"last_error_time" yaml:"last_error_time,omitempty"`
RunCount int `boil:"run_count" json:"run_count" toml:"run_count" yaml:"run_count"`
ShowErrors bool `boil:"show_errors" json:"show_errors" toml:"show_errors" yaml:"show_errors"`
R *customCommandR `boil:"-" json:"-" toml:"-" yaml:"-"`
L customCommandL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var CustomCommandColumns = struct {
LocalID string
GuildID string
GroupID string
TriggerType string
TextTrigger string
TextTriggerCaseSensitive string
TimeTriggerInterval string
TimeTriggerExcludingDays string
TimeTriggerExcludingHours string
LastRun string
NextRun string
Responses string
Channels string
ChannelsWhitelistMode string
Roles string
RolesWhitelistMode string
ContextChannel string
ReactionTriggerMode string
Disabled string
LastError string
LastErrorTime string
RunCount string
ShowErrors string
}{
LocalID: "local_id",
GuildID: "guild_id",
GroupID: "group_id",
TriggerType: "trigger_type",
TextTrigger: "text_trigger",
TextTriggerCaseSensitive: "text_trigger_case_sensitive",
TimeTriggerInterval: "time_trigger_interval",
TimeTriggerExcludingDays: "time_trigger_excluding_days",
TimeTriggerExcludingHours: "time_trigger_excluding_hours",
LastRun: "last_run",
NextRun: "next_run",
Responses: "responses",
Channels: "channels",
ChannelsWhitelistMode: "channels_whitelist_mode",
Roles: "roles",
RolesWhitelistMode: "roles_whitelist_mode",
ContextChannel: "context_channel",
ReactionTriggerMode: "reaction_trigger_mode",
Disabled: "disabled",
LastError: "last_error",
LastErrorTime: "last_error_time",
RunCount: "run_count",
ShowErrors: "show_errors",
}
// Generated where
type whereHelpernull_Int64 struct{ field string }
func (w whereHelpernull_Int64) EQ(x null.Int64) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, false, x)
}
func (w whereHelpernull_Int64) NEQ(x null.Int64) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, true, x)
}
func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) }
func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) }
func (w whereHelpernull_Int64) LT(x null.Int64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LT, x)
}
func (w whereHelpernull_Int64) LTE(x null.Int64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelpernull_Int64) GT(x null.Int64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GT, x)
}
func (w whereHelpernull_Int64) GTE(x null.Int64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
type whereHelperint struct{ field string }
func (w whereHelperint) EQ(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
func (w whereHelperint) NEQ(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) }
func (w whereHelperint) LT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
func (w whereHelperint) LTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) }
func (w whereHelperint) GT(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
func (w whereHelperint) GTE(x int) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) }
type whereHelperbool struct{ field string }
func (w whereHelperbool) EQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
func (w whereHelperbool) NEQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) }
func (w whereHelperbool) LT(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
func (w whereHelperbool) LTE(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) }
func (w whereHelperbool) GT(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
func (w whereHelperbool) GTE(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) }
type whereHelpernull_Time struct{ field string }
func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, false, x)
}
func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, true, x)
}
func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) }
func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) }
func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LT, x)
}
func (w whereHelpernull_Time) LTE(x null.Time) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelpernull_Time) GT(x null.Time) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GT, x)
}
func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
type whereHelpertypes_StringArray struct{ field string }
func (w whereHelpertypes_StringArray) EQ(x types.StringArray) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.EQ, x)
}
func (w whereHelpertypes_StringArray) NEQ(x types.StringArray) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.NEQ, x)
}
func (w whereHelpertypes_StringArray) LT(x types.StringArray) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LT, x)
}
func (w whereHelpertypes_StringArray) LTE(x types.StringArray) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelpertypes_StringArray) GT(x types.StringArray) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GT, x)
}
func (w whereHelpertypes_StringArray) GTE(x types.StringArray) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
type whereHelperint16 struct{ field string }
func (w whereHelperint16) EQ(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
func (w whereHelperint16) NEQ(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) }
func (w whereHelperint16) LT(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
func (w whereHelperint16) LTE(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) }
func (w whereHelperint16) GT(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
func (w whereHelperint16) GTE(x int16) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) }
var CustomCommandWhere = struct {
LocalID whereHelperint64
GuildID whereHelperint64
GroupID whereHelpernull_Int64
TriggerType whereHelperint
TextTrigger whereHelperstring
TextTriggerCaseSensitive whereHelperbool
TimeTriggerInterval whereHelperint
TimeTriggerExcludingDays whereHelpertypes_Int64Array
TimeTriggerExcludingHours whereHelpertypes_Int64Array
LastRun whereHelpernull_Time
NextRun whereHelpernull_Time
Responses whereHelpertypes_StringArray
Channels whereHelpertypes_Int64Array
ChannelsWhitelistMode whereHelperbool
Roles whereHelpertypes_Int64Array
RolesWhitelistMode whereHelperbool
ContextChannel whereHelperint64
ReactionTriggerMode whereHelperint16
Disabled whereHelperbool
LastError whereHelperstring
LastErrorTime whereHelpernull_Time
RunCount whereHelperint
ShowErrors whereHelperbool
}{
LocalID: whereHelperint64{field: "\"custom_commands\".\"local_id\""},
GuildID: whereHelperint64{field: "\"custom_commands\".\"guild_id\""},
GroupID: whereHelpernull_Int64{field: "\"custom_commands\".\"group_id\""},
TriggerType: whereHelperint{field: "\"custom_commands\".\"trigger_type\""},
TextTrigger: whereHelperstring{field: "\"custom_commands\".\"text_trigger\""},
TextTriggerCaseSensitive: whereHelperbool{field: "\"custom_commands\".\"text_trigger_case_sensitive\""},
TimeTriggerInterval: whereHelperint{field: "\"custom_commands\".\"time_trigger_interval\""},
TimeTriggerExcludingDays: whereHelpertypes_Int64Array{field: "\"custom_commands\".\"time_trigger_excluding_days\""},
TimeTriggerExcludingHours: whereHelpertypes_Int64Array{field: "\"custom_commands\".\"time_trigger_excluding_hours\""},
LastRun: whereHelpernull_Time{field: "\"custom_commands\".\"last_run\""},
NextRun: whereHelpernull_Time{field: "\"custom_commands\".\"next_run\""},
Responses: whereHelpertypes_StringArray{field: "\"custom_commands\".\"responses\""},
Channels: whereHelpertypes_Int64Array{field: "\"custom_commands\".\"channels\""},
ChannelsWhitelistMode: whereHelperbool{field: "\"custom_commands\".\"channels_whitelist_mode\""},
Roles: whereHelpertypes_Int64Array{field: "\"custom_commands\".\"roles\""},
RolesWhitelistMode: whereHelperbool{field: "\"custom_commands\".\"roles_whitelist_mode\""},
ContextChannel: whereHelperint64{field: "\"custom_commands\".\"context_channel\""},
ReactionTriggerMode: whereHelperint16{field: "\"custom_commands\".\"reaction_trigger_mode\""},
Disabled: whereHelperbool{field: "\"custom_commands\".\"disabled\""},
LastError: whereHelperstring{field: "\"custom_commands\".\"last_error\""},
LastErrorTime: whereHelpernull_Time{field: "\"custom_commands\".\"last_error_time\""},
RunCount: whereHelperint{field: "\"custom_commands\".\"run_count\""},
ShowErrors: whereHelperbool{field: "\"custom_commands\".\"show_errors\""},
}
// CustomCommandRels is where relationship names are stored.
var CustomCommandRels = struct {
Group string
}{
Group: "Group",
}
// customCommandR is where relationships are stored.
type customCommandR struct {
Group *CustomCommandGroup
}
// NewStruct creates a new relationship struct
func (*customCommandR) NewStruct() *customCommandR {
return &customCommandR{}
}
// customCommandL is where Load methods for each relationship are stored.
type customCommandL struct{}
var (
customCommandAllColumns = []string{"local_id", "guild_id", "group_id", "trigger_type", "text_trigger", "text_trigger_case_sensitive", "time_trigger_interval", "time_trigger_excluding_days", "time_trigger_excluding_hours", "last_run", "next_run", "responses", "channels", "channels_whitelist_mode", "roles", "roles_whitelist_mode", "context_channel", "reaction_trigger_mode", "disabled", "last_error", "last_error_time", "run_count", "show_errors"}
customCommandColumnsWithoutDefault = []string{"local_id", "guild_id", "group_id", "trigger_type", "text_trigger", "text_trigger_case_sensitive", "time_trigger_interval", "time_trigger_excluding_days", "time_trigger_excluding_hours", "last_run", "next_run", "responses", "channels", "channels_whitelist_mode", "roles", "roles_whitelist_mode", "last_error_time"}
customCommandColumnsWithDefault = []string{"context_channel", "reaction_trigger_mode", "disabled", "last_error", "run_count", "show_errors"}
customCommandPrimaryKeyColumns = []string{"guild_id", "local_id"}
)
type (
// CustomCommandSlice is an alias for a slice of pointers to CustomCommand.
// This should generally be used opposed to []CustomCommand.
CustomCommandSlice []*CustomCommand
customCommandQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
customCommandType = reflect.TypeOf(&CustomCommand{})
customCommandMapping = queries.MakeStructMapping(customCommandType)
customCommandPrimaryKeyMapping, _ = queries.BindMapping(customCommandType, customCommandMapping, customCommandPrimaryKeyColumns)
customCommandInsertCacheMut sync.RWMutex
customCommandInsertCache = make(map[string]insertCache)
customCommandUpdateCacheMut sync.RWMutex
customCommandUpdateCache = make(map[string]updateCache)
customCommandUpsertCacheMut sync.RWMutex
customCommandUpsertCache = 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 customCommand record from the query using the global executor.
func (q customCommandQuery) OneG(ctx context.Context) (*CustomCommand, error) {
return q.One(ctx, boil.GetContextDB())
}
// One returns a single customCommand record from the query.
func (q customCommandQuery) One(ctx context.Context, exec boil.ContextExecutor) (*CustomCommand, error) {
o := &CustomCommand{}
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 custom_commands")
}
return o, nil
}
// AllG returns all CustomCommand records from the query using the global executor.
func (q customCommandQuery) AllG(ctx context.Context) (CustomCommandSlice, error) {
return q.All(ctx, boil.GetContextDB())
}
// All returns all CustomCommand records from the query.
func (q customCommandQuery) All(ctx context.Context, exec boil.ContextExecutor) (CustomCommandSlice, error) {
var o []*CustomCommand
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "models: failed to assign all query results to CustomCommand slice")
}
return o, nil
}
// CountG returns the count of all CustomCommand records in the query, and panics on error.
func (q customCommandQuery) CountG(ctx context.Context) (int64, error) {
return q.Count(ctx, boil.GetContextDB())
}
// Count returns the count of all CustomCommand records in the query.
func (q customCommandQuery) 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 custom_commands rows")
}
return count, nil
}
// ExistsG checks if the row exists in the table, and panics on error.
func (q customCommandQuery) ExistsG(ctx context.Context) (bool, error) {
return q.Exists(ctx, boil.GetContextDB())
}
// Exists checks if the row exists in the table.
func (q customCommandQuery) 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 custom_commands exists")
}
return count > 0, nil
}
// Group pointed to by the foreign key.
func (o *CustomCommand) Group(mods ...qm.QueryMod) customCommandGroupQuery {
queryMods := []qm.QueryMod{
qm.Where("id=?", o.GroupID),
}
queryMods = append(queryMods, mods...)
query := CustomCommandGroups(queryMods...)
queries.SetFrom(query.Query, "\"custom_command_groups\"")
return query
}
// LoadGroup allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (customCommandL) LoadGroup(ctx context.Context, e boil.ContextExecutor, singular bool, maybeCustomCommand interface{}, mods queries.Applicator) error {
var slice []*CustomCommand
var object *CustomCommand
if singular {
object = maybeCustomCommand.(*CustomCommand)
} else {
slice = *maybeCustomCommand.(*[]*CustomCommand)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &customCommandR{}
}
if !queries.IsNil(object.GroupID) {
args = append(args, object.GroupID)
}
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &customCommandR{}
}
for _, a := range args {
if queries.Equal(a, obj.GroupID) {
continue Outer
}
}
if !queries.IsNil(obj.GroupID) {
args = append(args, obj.GroupID)
}
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(qm.From(`custom_command_groups`), qm.WhereIn(`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 CustomCommandGroup")
}
var resultSlice []*CustomCommandGroup
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice CustomCommandGroup")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for custom_command_groups")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for custom_command_groups")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Group = foreign
if foreign.R == nil {
foreign.R = &customCommandGroupR{}
}
foreign.R.GroupCustomCommands = append(foreign.R.GroupCustomCommands, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if queries.Equal(local.GroupID, foreign.ID) {
local.R.Group = foreign
if foreign.R == nil {
foreign.R = &customCommandGroupR{}
}
foreign.R.GroupCustomCommands = append(foreign.R.GroupCustomCommands, local)
break
}
}
}
return nil
}
// SetGroupG of the customCommand to the related item.
// Sets o.R.Group to related.
// Adds o to related.R.GroupCustomCommands.
// Uses the global database handle.
func (o *CustomCommand) SetGroupG(ctx context.Context, insert bool, related *CustomCommandGroup) error {
return o.SetGroup(ctx, boil.GetContextDB(), insert, related)
}
// SetGroup of the customCommand to the related item.
// Sets o.R.Group to related.
// Adds o to related.R.GroupCustomCommands.
func (o *CustomCommand) SetGroup(ctx context.Context, exec boil.ContextExecutor, insert bool, related *CustomCommandGroup) 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 \"custom_commands\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, []string{"group_id"}),
strmangle.WhereClause("\"", "\"", 2, customCommandPrimaryKeyColumns),
)
values := []interface{}{related.ID, o.GuildID, o.LocalID}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, updateQuery)
fmt.Fprintln(boil.DebugWriter, values)
}
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update local table")
}
queries.Assign(&o.GroupID, related.ID)
if o.R == nil {
o.R = &customCommandR{
Group: related,
}
} else {
o.R.Group = related
}
if related.R == nil {
related.R = &customCommandGroupR{
GroupCustomCommands: CustomCommandSlice{o},
}
} else {
related.R.GroupCustomCommands = append(related.R.GroupCustomCommands, o)
}
return nil
}
// RemoveGroupG relationship.
// Sets o.R.Group to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle.
func (o *CustomCommand) RemoveGroupG(ctx context.Context, related *CustomCommandGroup) error {
return o.RemoveGroup(ctx, boil.GetContextDB(), related)
}
// RemoveGroup relationship.
// Sets o.R.Group to nil.
// Removes o from all passed in related items' relationships struct (Optional).
func (o *CustomCommand) RemoveGroup(ctx context.Context, exec boil.ContextExecutor, related *CustomCommandGroup) error {
var err error
queries.SetScanner(&o.GroupID, nil)
if _, err = o.Update(ctx, exec, boil.Whitelist("group_id")); err != nil {
return errors.Wrap(err, "failed to update local table")
}
o.R.Group = nil
if related == nil || related.R == nil {
return nil
}
for i, ri := range related.R.GroupCustomCommands {
if queries.Equal(o.GroupID, ri.GroupID) {
continue
}
ln := len(related.R.GroupCustomCommands)
if ln > 1 && i < ln-1 {
related.R.GroupCustomCommands[i] = related.R.GroupCustomCommands[ln-1]
}
related.R.GroupCustomCommands = related.R.GroupCustomCommands[:ln-1]
break
}
return nil
}
// CustomCommands retrieves all the records using an executor.
func CustomCommands(mods ...qm.QueryMod) customCommandQuery {
mods = append(mods, qm.From("\"custom_commands\""))
return customCommandQuery{NewQuery(mods...)}
}
// FindCustomCommandG retrieves a single record by ID.
func FindCustomCommandG(ctx context.Context, guildID int64, localID int64, selectCols ...string) (*CustomCommand, error) {
return FindCustomCommand(ctx, boil.GetContextDB(), guildID, localID, selectCols...)
}
// FindCustomCommand retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindCustomCommand(ctx context.Context, exec boil.ContextExecutor, guildID int64, localID int64, selectCols ...string) (*CustomCommand, error) {
customCommandObj := &CustomCommand{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"custom_commands\" where \"guild_id\"=$1 AND \"local_id\"=$2", sel,
)
q := queries.Raw(query, guildID, localID)
err := q.Bind(ctx, exec, customCommandObj)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: unable to select from custom_commands")
}
return customCommandObj, nil
}
// InsertG a single record. See Insert for whitelist behavior description.
func (o *CustomCommand) 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 *CustomCommand) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("models: no custom_commands provided for insertion")
}
var err error
nzDefaults := queries.NonZeroDefaultSet(customCommandColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
customCommandInsertCacheMut.RLock()
cache, cached := customCommandInsertCache[key]
customCommandInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
customCommandAllColumns,
customCommandColumnsWithDefault,
customCommandColumnsWithoutDefault,
nzDefaults,
)
cache.valueMapping, err = queries.BindMapping(customCommandType, customCommandMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(customCommandType, customCommandMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"custom_commands\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"custom_commands\" %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.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, 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 custom_commands")
}
if !cached {
customCommandInsertCacheMut.Lock()
customCommandInsertCache[key] = cache
customCommandInsertCacheMut.Unlock()
}
return nil
}
// UpdateG a single CustomCommand record using the global executor.
// See Update for more documentation.
func (o *CustomCommand) UpdateG(ctx context.Context, columns boil.Columns) (int64, error) {
return o.Update(ctx, boil.GetContextDB(), columns)
}
// Update uses an executor to update the CustomCommand.
// 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 *CustomCommand) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
key := makeCacheKey(columns, nil)
customCommandUpdateCacheMut.RLock()
cache, cached := customCommandUpdateCache[key]
customCommandUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
customCommandAllColumns,
customCommandPrimaryKeyColumns,
)
if !columns.IsWhitelist() {
wl = strmangle.SetComplement(wl, []string{"created_at"})
}
if len(wl) == 0 {
return 0, errors.New("models: unable to update custom_commands, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"custom_commands\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, wl),
strmangle.WhereClause("\"", "\"", len(wl)+1, customCommandPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(customCommandType, customCommandMapping, append(wl, customCommandPrimaryKeyColumns...))
if err != nil {
return 0, 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)
}
var result sql.Result
result, err = exec.ExecContext(ctx, cache.query, values...)
if err != nil {
return 0, errors.Wrap(err, "models: unable to update custom_commands row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by update for custom_commands")
}
if !cached {
customCommandUpdateCacheMut.Lock()
customCommandUpdateCache[key] = cache
customCommandUpdateCacheMut.Unlock()
}
return rowsAff, nil
}
// UpdateAllG updates all rows with the specified column values.
func (q customCommandQuery) UpdateAllG(ctx context.Context, cols M) (int64, error) {
return q.UpdateAll(ctx, boil.GetContextDB(), cols)
}
// UpdateAll updates all rows with the specified column values.
func (q customCommandQuery) 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 custom_commands")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for custom_commands")
}
return rowsAff, nil
}
// UpdateAllG updates all rows with the specified column values.
func (o CustomCommandSlice) UpdateAllG(ctx context.Context, cols M) (int64, error) {
return o.UpdateAll(ctx, boil.GetContextDB(), cols)
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o CustomCommandSlice) 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)), customCommandPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"custom_commands\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, customCommandPrimaryKeyColumns, len(o)))
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args...)
}
result, err := exec.ExecContext(ctx, sql, args...)
if err != nil {
return 0, errors.Wrap(err, "models: unable to update all in customCommand slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all customCommand")
}
return rowsAff, nil
}
// UpsertG attempts an insert, and does an update or ignore on conflict.
func (o *CustomCommand) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns)
}
// 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 *CustomCommand) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
if o == nil {
return errors.New("models: no custom_commands provided for upsert")
}
nzDefaults := queries.NonZeroDefaultSet(customCommandColumnsWithDefault, o)
// Build cache key in-line uglily - mysql vs psql problems
buf := strmangle.GetBuffer()
if updateOnConflict {
buf.WriteByte('t')
} else {
buf.WriteByte('f')
}
buf.WriteByte('.')
for _, c := range conflictColumns {
buf.WriteString(c)
}
buf.WriteByte('.')
buf.WriteString(strconv.Itoa(updateColumns.Kind))
for _, c := range updateColumns.Cols {
buf.WriteString(c)
}
buf.WriteByte('.')
buf.WriteString(strconv.Itoa(insertColumns.Kind))
for _, c := range insertColumns.Cols {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range nzDefaults {
buf.WriteString(c)
}
key := buf.String()
strmangle.PutBuffer(buf)
customCommandUpsertCacheMut.RLock()
cache, cached := customCommandUpsertCache[key]
customCommandUpsertCacheMut.RUnlock()
var err error
if !cached {
insert, ret := insertColumns.InsertColumnSet(
customCommandAllColumns,
customCommandColumnsWithDefault,
customCommandColumnsWithoutDefault,
nzDefaults,
)
update := updateColumns.UpdateColumnSet(
customCommandAllColumns,
customCommandPrimaryKeyColumns,
)
if updateOnConflict && len(update) == 0 {
return errors.New("models: unable to upsert custom_commands, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(customCommandPrimaryKeyColumns))
copy(conflict, customCommandPrimaryKeyColumns)
}
cache.query = buildUpsertQueryPostgres(dialect, "\"custom_commands\"", updateOnConflict, ret, update, conflict, insert)
cache.valueMapping, err = queries.BindMapping(customCommandType, customCommandMapping, insert)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(customCommandType, customCommandMapping, 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)
}
if len(cache.retMapping) != 0 {
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
if err == sql.ErrNoRows {
err = nil // Postgres doesn't return anything when there's no update
}
} else {
_, err = exec.ExecContext(ctx, cache.query, vals...)
}
if err != nil {
return errors.Wrap(err, "models: unable to upsert custom_commands")
}
if !cached {
customCommandUpsertCacheMut.Lock()
customCommandUpsertCache[key] = cache
customCommandUpsertCacheMut.Unlock()
}
return nil
}
// DeleteG deletes a single CustomCommand record.
// DeleteG will match against the primary key column to find the record to delete.
func (o *CustomCommand) DeleteG(ctx context.Context) (int64, error) {
return o.Delete(ctx, boil.GetContextDB())
}
// Delete deletes a single CustomCommand record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *CustomCommand) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("models: no CustomCommand provided for delete")
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), customCommandPrimaryKeyMapping)
sql := "DELETE FROM \"custom_commands\" WHERE \"guild_id\"=$1 AND \"local_id\"=$2"
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args...)
}
result, err := exec.ExecContext(ctx, sql, args...)
if err != nil {
return 0, errors.Wrap(err, "models: unable to delete from custom_commands")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for custom_commands")
}
return rowsAff, nil
}