-
Notifications
You must be signed in to change notification settings - Fork 1
/
intercept.go
869 lines (727 loc) · 33.1 KB
/
intercept.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
// Code generated by ent, DO NOT EDIT.
package intercept
import (
"context"
"fmt"
"entgo.io/ent/dialect/sql"
"github.com/woocoos/knockout/ent"
"github.com/woocoos/knockout/ent/app"
"github.com/woocoos/knockout/ent/appaction"
"github.com/woocoos/knockout/ent/appdict"
"github.com/woocoos/knockout/ent/appdictitem"
"github.com/woocoos/knockout/ent/appmenu"
"github.com/woocoos/knockout/ent/apppolicy"
"github.com/woocoos/knockout/ent/appres"
"github.com/woocoos/knockout/ent/approle"
"github.com/woocoos/knockout/ent/approlepolicy"
"github.com/woocoos/knockout/ent/file"
"github.com/woocoos/knockout/ent/filesource"
"github.com/woocoos/knockout/ent/oauthclient"
"github.com/woocoos/knockout/ent/org"
"github.com/woocoos/knockout/ent/orgapp"
"github.com/woocoos/knockout/ent/orgpolicy"
"github.com/woocoos/knockout/ent/orgrole"
"github.com/woocoos/knockout/ent/orgroleuser"
"github.com/woocoos/knockout/ent/orguser"
"github.com/woocoos/knockout/ent/orguserpreference"
"github.com/woocoos/knockout/ent/permission"
"github.com/woocoos/knockout/ent/predicate"
"github.com/woocoos/knockout/ent/user"
"github.com/woocoos/knockout/ent/userdevice"
"github.com/woocoos/knockout/ent/useridentity"
"github.com/woocoos/knockout/ent/userloginprofile"
"github.com/woocoos/knockout/ent/userpassword"
)
// The Query interface represents an operation that queries a graph.
// By using this interface, users can write generic code that manipulates
// query builders of different types.
type Query interface {
// Type returns the string representation of the query type.
Type() string
// Limit the number of records to be returned by this query.
Limit(int)
// Offset to start from.
Offset(int)
// Unique configures the query builder to filter duplicate records.
Unique(bool)
// Order specifies how the records should be ordered.
Order(...func(*sql.Selector))
// WhereP appends storage-level predicates to the query builder. Using this method, users
// can use type-assertion to append predicates that do not depend on any generated package.
WhereP(...func(*sql.Selector))
}
// The Func type is an adapter that allows ordinary functions to be used as interceptors.
// Unlike traversal functions, interceptors are skipped during graph traversals. Note that the
// implementation of Func is different from the one defined in entgo.io/ent.InterceptFunc.
type Func func(context.Context, Query) error
// Intercept calls f(ctx, q) and then applied the next Querier.
func (f Func) Intercept(next ent.Querier) ent.Querier {
return ent.QuerierFunc(func(ctx context.Context, q ent.Query) (ent.Value, error) {
query, err := NewQuery(q)
if err != nil {
return nil, err
}
if err := f(ctx, query); err != nil {
return nil, err
}
return next.Query(ctx, q)
})
}
// The TraverseFunc type is an adapter to allow the use of ordinary function as Traverser.
// If f is a function with the appropriate signature, TraverseFunc(f) is a Traverser that calls f.
type TraverseFunc func(context.Context, Query) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseFunc) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
query, err := NewQuery(q)
if err != nil {
return err
}
return f(ctx, query)
}
// The AppFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppFunc func(context.Context, *ent.AppQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppQuery", q)
}
// The TraverseApp type is an adapter to allow the use of ordinary function as Traverser.
type TraverseApp func(context.Context, *ent.AppQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseApp) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseApp) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppQuery", q)
}
// The AppActionFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppActionFunc func(context.Context, *ent.AppActionQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppActionFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppActionQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppActionQuery", q)
}
// The TraverseAppAction type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAppAction func(context.Context, *ent.AppActionQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAppAction) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAppAction) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppActionQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppActionQuery", q)
}
// The AppDictFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppDictFunc func(context.Context, *ent.AppDictQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppDictFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppDictQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppDictQuery", q)
}
// The TraverseAppDict type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAppDict func(context.Context, *ent.AppDictQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAppDict) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAppDict) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppDictQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppDictQuery", q)
}
// The AppDictItemFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppDictItemFunc func(context.Context, *ent.AppDictItemQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppDictItemFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppDictItemQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppDictItemQuery", q)
}
// The TraverseAppDictItem type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAppDictItem func(context.Context, *ent.AppDictItemQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAppDictItem) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAppDictItem) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppDictItemQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppDictItemQuery", q)
}
// The AppMenuFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppMenuFunc func(context.Context, *ent.AppMenuQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppMenuFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppMenuQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppMenuQuery", q)
}
// The TraverseAppMenu type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAppMenu func(context.Context, *ent.AppMenuQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAppMenu) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAppMenu) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppMenuQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppMenuQuery", q)
}
// The AppPolicyFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppPolicyFunc func(context.Context, *ent.AppPolicyQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppPolicyFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppPolicyQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppPolicyQuery", q)
}
// The TraverseAppPolicy type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAppPolicy func(context.Context, *ent.AppPolicyQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAppPolicy) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAppPolicy) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppPolicyQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppPolicyQuery", q)
}
// The AppResFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppResFunc func(context.Context, *ent.AppResQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppResFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppResQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppResQuery", q)
}
// The TraverseAppRes type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAppRes func(context.Context, *ent.AppResQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAppRes) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAppRes) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppResQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppResQuery", q)
}
// The AppRoleFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppRoleFunc func(context.Context, *ent.AppRoleQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppRoleFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppRoleQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppRoleQuery", q)
}
// The TraverseAppRole type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAppRole func(context.Context, *ent.AppRoleQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAppRole) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAppRole) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppRoleQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppRoleQuery", q)
}
// The AppRolePolicyFunc type is an adapter to allow the use of ordinary function as a Querier.
type AppRolePolicyFunc func(context.Context, *ent.AppRolePolicyQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AppRolePolicyFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AppRolePolicyQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AppRolePolicyQuery", q)
}
// The TraverseAppRolePolicy type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAppRolePolicy func(context.Context, *ent.AppRolePolicyQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAppRolePolicy) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAppRolePolicy) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AppRolePolicyQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AppRolePolicyQuery", q)
}
// The FileFunc type is an adapter to allow the use of ordinary function as a Querier.
type FileFunc func(context.Context, *ent.FileQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f FileFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.FileQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.FileQuery", q)
}
// The TraverseFile type is an adapter to allow the use of ordinary function as Traverser.
type TraverseFile func(context.Context, *ent.FileQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseFile) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseFile) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.FileQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.FileQuery", q)
}
// The FileSourceFunc type is an adapter to allow the use of ordinary function as a Querier.
type FileSourceFunc func(context.Context, *ent.FileSourceQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f FileSourceFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.FileSourceQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.FileSourceQuery", q)
}
// The TraverseFileSource type is an adapter to allow the use of ordinary function as Traverser.
type TraverseFileSource func(context.Context, *ent.FileSourceQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseFileSource) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseFileSource) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.FileSourceQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.FileSourceQuery", q)
}
// The OauthClientFunc type is an adapter to allow the use of ordinary function as a Querier.
type OauthClientFunc func(context.Context, *ent.OauthClientQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f OauthClientFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.OauthClientQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.OauthClientQuery", q)
}
// The TraverseOauthClient type is an adapter to allow the use of ordinary function as Traverser.
type TraverseOauthClient func(context.Context, *ent.OauthClientQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseOauthClient) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseOauthClient) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.OauthClientQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.OauthClientQuery", q)
}
// The OrgFunc type is an adapter to allow the use of ordinary function as a Querier.
type OrgFunc func(context.Context, *ent.OrgQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f OrgFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.OrgQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.OrgQuery", q)
}
// The TraverseOrg type is an adapter to allow the use of ordinary function as Traverser.
type TraverseOrg func(context.Context, *ent.OrgQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseOrg) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseOrg) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.OrgQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.OrgQuery", q)
}
// The OrgAppFunc type is an adapter to allow the use of ordinary function as a Querier.
type OrgAppFunc func(context.Context, *ent.OrgAppQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f OrgAppFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.OrgAppQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.OrgAppQuery", q)
}
// The TraverseOrgApp type is an adapter to allow the use of ordinary function as Traverser.
type TraverseOrgApp func(context.Context, *ent.OrgAppQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseOrgApp) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseOrgApp) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.OrgAppQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.OrgAppQuery", q)
}
// The OrgPolicyFunc type is an adapter to allow the use of ordinary function as a Querier.
type OrgPolicyFunc func(context.Context, *ent.OrgPolicyQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f OrgPolicyFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.OrgPolicyQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.OrgPolicyQuery", q)
}
// The TraverseOrgPolicy type is an adapter to allow the use of ordinary function as Traverser.
type TraverseOrgPolicy func(context.Context, *ent.OrgPolicyQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseOrgPolicy) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseOrgPolicy) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.OrgPolicyQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.OrgPolicyQuery", q)
}
// The OrgRoleFunc type is an adapter to allow the use of ordinary function as a Querier.
type OrgRoleFunc func(context.Context, *ent.OrgRoleQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f OrgRoleFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.OrgRoleQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.OrgRoleQuery", q)
}
// The TraverseOrgRole type is an adapter to allow the use of ordinary function as Traverser.
type TraverseOrgRole func(context.Context, *ent.OrgRoleQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseOrgRole) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseOrgRole) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.OrgRoleQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.OrgRoleQuery", q)
}
// The OrgRoleUserFunc type is an adapter to allow the use of ordinary function as a Querier.
type OrgRoleUserFunc func(context.Context, *ent.OrgRoleUserQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f OrgRoleUserFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.OrgRoleUserQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.OrgRoleUserQuery", q)
}
// The TraverseOrgRoleUser type is an adapter to allow the use of ordinary function as Traverser.
type TraverseOrgRoleUser func(context.Context, *ent.OrgRoleUserQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseOrgRoleUser) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseOrgRoleUser) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.OrgRoleUserQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.OrgRoleUserQuery", q)
}
// The OrgUserFunc type is an adapter to allow the use of ordinary function as a Querier.
type OrgUserFunc func(context.Context, *ent.OrgUserQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f OrgUserFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.OrgUserQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.OrgUserQuery", q)
}
// The TraverseOrgUser type is an adapter to allow the use of ordinary function as Traverser.
type TraverseOrgUser func(context.Context, *ent.OrgUserQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseOrgUser) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseOrgUser) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.OrgUserQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.OrgUserQuery", q)
}
// The OrgUserPreferenceFunc type is an adapter to allow the use of ordinary function as a Querier.
type OrgUserPreferenceFunc func(context.Context, *ent.OrgUserPreferenceQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f OrgUserPreferenceFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.OrgUserPreferenceQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.OrgUserPreferenceQuery", q)
}
// The TraverseOrgUserPreference type is an adapter to allow the use of ordinary function as Traverser.
type TraverseOrgUserPreference func(context.Context, *ent.OrgUserPreferenceQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseOrgUserPreference) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseOrgUserPreference) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.OrgUserPreferenceQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.OrgUserPreferenceQuery", q)
}
// The PermissionFunc type is an adapter to allow the use of ordinary function as a Querier.
type PermissionFunc func(context.Context, *ent.PermissionQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f PermissionFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.PermissionQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.PermissionQuery", q)
}
// The TraversePermission type is an adapter to allow the use of ordinary function as Traverser.
type TraversePermission func(context.Context, *ent.PermissionQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraversePermission) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraversePermission) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.PermissionQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.PermissionQuery", q)
}
// The UserFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserFunc func(context.Context, *ent.UserQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UserFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UserQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserQuery", q)
}
// The TraverseUser type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUser func(context.Context, *ent.UserQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUser) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUser) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UserQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UserQuery", q)
}
// The UserDeviceFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserDeviceFunc func(context.Context, *ent.UserDeviceQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UserDeviceFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UserDeviceQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserDeviceQuery", q)
}
// The TraverseUserDevice type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserDevice func(context.Context, *ent.UserDeviceQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserDevice) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUserDevice) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UserDeviceQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UserDeviceQuery", q)
}
// The UserIdentityFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserIdentityFunc func(context.Context, *ent.UserIdentityQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UserIdentityFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UserIdentityQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserIdentityQuery", q)
}
// The TraverseUserIdentity type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserIdentity func(context.Context, *ent.UserIdentityQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserIdentity) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUserIdentity) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UserIdentityQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UserIdentityQuery", q)
}
// The UserLoginProfileFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserLoginProfileFunc func(context.Context, *ent.UserLoginProfileQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UserLoginProfileFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UserLoginProfileQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserLoginProfileQuery", q)
}
// The TraverseUserLoginProfile type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserLoginProfile func(context.Context, *ent.UserLoginProfileQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserLoginProfile) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUserLoginProfile) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UserLoginProfileQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UserLoginProfileQuery", q)
}
// The UserPasswordFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserPasswordFunc func(context.Context, *ent.UserPasswordQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UserPasswordFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UserPasswordQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserPasswordQuery", q)
}
// The TraverseUserPassword type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserPassword func(context.Context, *ent.UserPasswordQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserPassword) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUserPassword) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UserPasswordQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UserPasswordQuery", q)
}
// NewQuery returns the generic Query interface for the given typed query.
func NewQuery(q ent.Query) (Query, error) {
switch q := q.(type) {
case *ent.AppQuery:
return &query[*ent.AppQuery, predicate.App, app.OrderOption]{typ: ent.TypeApp, tq: q}, nil
case *ent.AppActionQuery:
return &query[*ent.AppActionQuery, predicate.AppAction, appaction.OrderOption]{typ: ent.TypeAppAction, tq: q}, nil
case *ent.AppDictQuery:
return &query[*ent.AppDictQuery, predicate.AppDict, appdict.OrderOption]{typ: ent.TypeAppDict, tq: q}, nil
case *ent.AppDictItemQuery:
return &query[*ent.AppDictItemQuery, predicate.AppDictItem, appdictitem.OrderOption]{typ: ent.TypeAppDictItem, tq: q}, nil
case *ent.AppMenuQuery:
return &query[*ent.AppMenuQuery, predicate.AppMenu, appmenu.OrderOption]{typ: ent.TypeAppMenu, tq: q}, nil
case *ent.AppPolicyQuery:
return &query[*ent.AppPolicyQuery, predicate.AppPolicy, apppolicy.OrderOption]{typ: ent.TypeAppPolicy, tq: q}, nil
case *ent.AppResQuery:
return &query[*ent.AppResQuery, predicate.AppRes, appres.OrderOption]{typ: ent.TypeAppRes, tq: q}, nil
case *ent.AppRoleQuery:
return &query[*ent.AppRoleQuery, predicate.AppRole, approle.OrderOption]{typ: ent.TypeAppRole, tq: q}, nil
case *ent.AppRolePolicyQuery:
return &query[*ent.AppRolePolicyQuery, predicate.AppRolePolicy, approlepolicy.OrderOption]{typ: ent.TypeAppRolePolicy, tq: q}, nil
case *ent.FileQuery:
return &query[*ent.FileQuery, predicate.File, file.OrderOption]{typ: ent.TypeFile, tq: q}, nil
case *ent.FileSourceQuery:
return &query[*ent.FileSourceQuery, predicate.FileSource, filesource.OrderOption]{typ: ent.TypeFileSource, tq: q}, nil
case *ent.OauthClientQuery:
return &query[*ent.OauthClientQuery, predicate.OauthClient, oauthclient.OrderOption]{typ: ent.TypeOauthClient, tq: q}, nil
case *ent.OrgQuery:
return &query[*ent.OrgQuery, predicate.Org, org.OrderOption]{typ: ent.TypeOrg, tq: q}, nil
case *ent.OrgAppQuery:
return &query[*ent.OrgAppQuery, predicate.OrgApp, orgapp.OrderOption]{typ: ent.TypeOrgApp, tq: q}, nil
case *ent.OrgPolicyQuery:
return &query[*ent.OrgPolicyQuery, predicate.OrgPolicy, orgpolicy.OrderOption]{typ: ent.TypeOrgPolicy, tq: q}, nil
case *ent.OrgRoleQuery:
return &query[*ent.OrgRoleQuery, predicate.OrgRole, orgrole.OrderOption]{typ: ent.TypeOrgRole, tq: q}, nil
case *ent.OrgRoleUserQuery:
return &query[*ent.OrgRoleUserQuery, predicate.OrgRoleUser, orgroleuser.OrderOption]{typ: ent.TypeOrgRoleUser, tq: q}, nil
case *ent.OrgUserQuery:
return &query[*ent.OrgUserQuery, predicate.OrgUser, orguser.OrderOption]{typ: ent.TypeOrgUser, tq: q}, nil
case *ent.OrgUserPreferenceQuery:
return &query[*ent.OrgUserPreferenceQuery, predicate.OrgUserPreference, orguserpreference.OrderOption]{typ: ent.TypeOrgUserPreference, tq: q}, nil
case *ent.PermissionQuery:
return &query[*ent.PermissionQuery, predicate.Permission, permission.OrderOption]{typ: ent.TypePermission, tq: q}, nil
case *ent.UserQuery:
return &query[*ent.UserQuery, predicate.User, user.OrderOption]{typ: ent.TypeUser, tq: q}, nil
case *ent.UserDeviceQuery:
return &query[*ent.UserDeviceQuery, predicate.UserDevice, userdevice.OrderOption]{typ: ent.TypeUserDevice, tq: q}, nil
case *ent.UserIdentityQuery:
return &query[*ent.UserIdentityQuery, predicate.UserIdentity, useridentity.OrderOption]{typ: ent.TypeUserIdentity, tq: q}, nil
case *ent.UserLoginProfileQuery:
return &query[*ent.UserLoginProfileQuery, predicate.UserLoginProfile, userloginprofile.OrderOption]{typ: ent.TypeUserLoginProfile, tq: q}, nil
case *ent.UserPasswordQuery:
return &query[*ent.UserPasswordQuery, predicate.UserPassword, userpassword.OrderOption]{typ: ent.TypeUserPassword, tq: q}, nil
default:
return nil, fmt.Errorf("unknown query type %T", q)
}
}
type query[T any, P ~func(*sql.Selector), R ~func(*sql.Selector)] struct {
typ string
tq interface {
Limit(int) T
Offset(int) T
Unique(bool) T
Order(...R) T
Where(...P) T
}
}
func (q query[T, P, R]) Type() string {
return q.typ
}
func (q query[T, P, R]) Limit(limit int) {
q.tq.Limit(limit)
}
func (q query[T, P, R]) Offset(offset int) {
q.tq.Offset(offset)
}
func (q query[T, P, R]) Unique(unique bool) {
q.tq.Unique(unique)
}
func (q query[T, P, R]) Order(orders ...func(*sql.Selector)) {
rs := make([]R, len(orders))
for i := range orders {
rs[i] = orders[i]
}
q.tq.Order(rs...)
}
func (q query[T, P, R]) WhereP(ps ...func(*sql.Selector)) {
p := make([]P, len(ps))
for i := range ps {
p[i] = ps[i]
}
q.tq.Where(p...)
}