generated from cloudwego/.github
/
mutation.go
1217 lines (1111 loc) · 35.3 KB
/
mutation.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 ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"github.com/cloudwego/biz-demo/open-payment-platform/internal/payment/infrastructure/ent/order"
"github.com/cloudwego/biz-demo/open-payment-platform/internal/payment/infrastructure/ent/predicate"
"entgo.io/ent"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeOrder = "Order"
)
// OrderMutation represents an operation that mutates the Order nodes in the graph.
type OrderMutation struct {
config
op Op
typ string
id *int
merchant_id *string
channel *string
pay_way *string
out_order_no *string
total_amount *uint64
addtotal_amount *int64
body *string
order_status *int8
addorder_status *int8
auth_code *string
wx_appid *string
sub_openid *string
jump_url *string
notify_url *string
client_ip *string
attach *string
order_expiration *string
extend_params *string
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*Order, error)
predicates []predicate.Order
}
var _ ent.Mutation = (*OrderMutation)(nil)
// orderOption allows management of the mutation configuration using functional options.
type orderOption func(*OrderMutation)
// newOrderMutation creates new mutation for the Order entity.
func newOrderMutation(c config, op Op, opts ...orderOption) *OrderMutation {
m := &OrderMutation{
config: c,
op: op,
typ: TypeOrder,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withOrderID sets the ID field of the mutation.
func withOrderID(id int) orderOption {
return func(m *OrderMutation) {
var (
err error
once sync.Once
value *Order
)
m.oldValue = func(ctx context.Context) (*Order, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Order.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withOrder sets the old Order of the mutation.
func withOrder(node *Order) orderOption {
return func(m *OrderMutation) {
m.oldValue = func(context.Context) (*Order, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m OrderMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m OrderMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *OrderMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *OrderMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Order.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetMerchantID sets the "merchant_id" field.
func (m *OrderMutation) SetMerchantID(s string) {
m.merchant_id = &s
}
// MerchantID returns the value of the "merchant_id" field in the mutation.
func (m *OrderMutation) MerchantID() (r string, exists bool) {
v := m.merchant_id
if v == nil {
return
}
return *v, true
}
// OldMerchantID returns the old "merchant_id" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldMerchantID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMerchantID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMerchantID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMerchantID: %w", err)
}
return oldValue.MerchantID, nil
}
// ResetMerchantID resets all changes to the "merchant_id" field.
func (m *OrderMutation) ResetMerchantID() {
m.merchant_id = nil
}
// SetChannel sets the "channel" field.
func (m *OrderMutation) SetChannel(s string) {
m.channel = &s
}
// Channel returns the value of the "channel" field in the mutation.
func (m *OrderMutation) Channel() (r string, exists bool) {
v := m.channel
if v == nil {
return
}
return *v, true
}
// OldChannel returns the old "channel" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldChannel(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldChannel is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldChannel requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldChannel: %w", err)
}
return oldValue.Channel, nil
}
// ResetChannel resets all changes to the "channel" field.
func (m *OrderMutation) ResetChannel() {
m.channel = nil
}
// SetPayWay sets the "pay_way" field.
func (m *OrderMutation) SetPayWay(s string) {
m.pay_way = &s
}
// PayWay returns the value of the "pay_way" field in the mutation.
func (m *OrderMutation) PayWay() (r string, exists bool) {
v := m.pay_way
if v == nil {
return
}
return *v, true
}
// OldPayWay returns the old "pay_way" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldPayWay(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPayWay is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPayWay requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPayWay: %w", err)
}
return oldValue.PayWay, nil
}
// ResetPayWay resets all changes to the "pay_way" field.
func (m *OrderMutation) ResetPayWay() {
m.pay_way = nil
}
// SetOutOrderNo sets the "out_order_no" field.
func (m *OrderMutation) SetOutOrderNo(s string) {
m.out_order_no = &s
}
// OutOrderNo returns the value of the "out_order_no" field in the mutation.
func (m *OrderMutation) OutOrderNo() (r string, exists bool) {
v := m.out_order_no
if v == nil {
return
}
return *v, true
}
// OldOutOrderNo returns the old "out_order_no" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldOutOrderNo(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOutOrderNo is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOutOrderNo requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOutOrderNo: %w", err)
}
return oldValue.OutOrderNo, nil
}
// ResetOutOrderNo resets all changes to the "out_order_no" field.
func (m *OrderMutation) ResetOutOrderNo() {
m.out_order_no = nil
}
// SetTotalAmount sets the "total_amount" field.
func (m *OrderMutation) SetTotalAmount(u uint64) {
m.total_amount = &u
m.addtotal_amount = nil
}
// TotalAmount returns the value of the "total_amount" field in the mutation.
func (m *OrderMutation) TotalAmount() (r uint64, exists bool) {
v := m.total_amount
if v == nil {
return
}
return *v, true
}
// OldTotalAmount returns the old "total_amount" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldTotalAmount(ctx context.Context) (v uint64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTotalAmount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTotalAmount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTotalAmount: %w", err)
}
return oldValue.TotalAmount, nil
}
// AddTotalAmount adds u to the "total_amount" field.
func (m *OrderMutation) AddTotalAmount(u int64) {
if m.addtotal_amount != nil {
*m.addtotal_amount += u
} else {
m.addtotal_amount = &u
}
}
// AddedTotalAmount returns the value that was added to the "total_amount" field in this mutation.
func (m *OrderMutation) AddedTotalAmount() (r int64, exists bool) {
v := m.addtotal_amount
if v == nil {
return
}
return *v, true
}
// ResetTotalAmount resets all changes to the "total_amount" field.
func (m *OrderMutation) ResetTotalAmount() {
m.total_amount = nil
m.addtotal_amount = nil
}
// SetBody sets the "body" field.
func (m *OrderMutation) SetBody(s string) {
m.body = &s
}
// Body returns the value of the "body" field in the mutation.
func (m *OrderMutation) Body() (r string, exists bool) {
v := m.body
if v == nil {
return
}
return *v, true
}
// OldBody returns the old "body" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldBody(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBody is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBody requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBody: %w", err)
}
return oldValue.Body, nil
}
// ResetBody resets all changes to the "body" field.
func (m *OrderMutation) ResetBody() {
m.body = nil
}
// SetOrderStatus sets the "order_status" field.
func (m *OrderMutation) SetOrderStatus(i int8) {
m.order_status = &i
m.addorder_status = nil
}
// OrderStatus returns the value of the "order_status" field in the mutation.
func (m *OrderMutation) OrderStatus() (r int8, exists bool) {
v := m.order_status
if v == nil {
return
}
return *v, true
}
// OldOrderStatus returns the old "order_status" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldOrderStatus(ctx context.Context) (v int8, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOrderStatus is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOrderStatus requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOrderStatus: %w", err)
}
return oldValue.OrderStatus, nil
}
// AddOrderStatus adds i to the "order_status" field.
func (m *OrderMutation) AddOrderStatus(i int8) {
if m.addorder_status != nil {
*m.addorder_status += i
} else {
m.addorder_status = &i
}
}
// AddedOrderStatus returns the value that was added to the "order_status" field in this mutation.
func (m *OrderMutation) AddedOrderStatus() (r int8, exists bool) {
v := m.addorder_status
if v == nil {
return
}
return *v, true
}
// ResetOrderStatus resets all changes to the "order_status" field.
func (m *OrderMutation) ResetOrderStatus() {
m.order_status = nil
m.addorder_status = nil
}
// SetAuthCode sets the "auth_code" field.
func (m *OrderMutation) SetAuthCode(s string) {
m.auth_code = &s
}
// AuthCode returns the value of the "auth_code" field in the mutation.
func (m *OrderMutation) AuthCode() (r string, exists bool) {
v := m.auth_code
if v == nil {
return
}
return *v, true
}
// OldAuthCode returns the old "auth_code" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldAuthCode(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAuthCode is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAuthCode requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAuthCode: %w", err)
}
return oldValue.AuthCode, nil
}
// ResetAuthCode resets all changes to the "auth_code" field.
func (m *OrderMutation) ResetAuthCode() {
m.auth_code = nil
}
// SetWxAppid sets the "wx_appid" field.
func (m *OrderMutation) SetWxAppid(s string) {
m.wx_appid = &s
}
// WxAppid returns the value of the "wx_appid" field in the mutation.
func (m *OrderMutation) WxAppid() (r string, exists bool) {
v := m.wx_appid
if v == nil {
return
}
return *v, true
}
// OldWxAppid returns the old "wx_appid" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldWxAppid(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldWxAppid is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldWxAppid requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldWxAppid: %w", err)
}
return oldValue.WxAppid, nil
}
// ResetWxAppid resets all changes to the "wx_appid" field.
func (m *OrderMutation) ResetWxAppid() {
m.wx_appid = nil
}
// SetSubOpenid sets the "sub_openid" field.
func (m *OrderMutation) SetSubOpenid(s string) {
m.sub_openid = &s
}
// SubOpenid returns the value of the "sub_openid" field in the mutation.
func (m *OrderMutation) SubOpenid() (r string, exists bool) {
v := m.sub_openid
if v == nil {
return
}
return *v, true
}
// OldSubOpenid returns the old "sub_openid" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldSubOpenid(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSubOpenid is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSubOpenid requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSubOpenid: %w", err)
}
return oldValue.SubOpenid, nil
}
// ResetSubOpenid resets all changes to the "sub_openid" field.
func (m *OrderMutation) ResetSubOpenid() {
m.sub_openid = nil
}
// SetJumpURL sets the "jump_url" field.
func (m *OrderMutation) SetJumpURL(s string) {
m.jump_url = &s
}
// JumpURL returns the value of the "jump_url" field in the mutation.
func (m *OrderMutation) JumpURL() (r string, exists bool) {
v := m.jump_url
if v == nil {
return
}
return *v, true
}
// OldJumpURL returns the old "jump_url" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldJumpURL(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldJumpURL is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldJumpURL requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldJumpURL: %w", err)
}
return oldValue.JumpURL, nil
}
// ResetJumpURL resets all changes to the "jump_url" field.
func (m *OrderMutation) ResetJumpURL() {
m.jump_url = nil
}
// SetNotifyURL sets the "notify_url" field.
func (m *OrderMutation) SetNotifyURL(s string) {
m.notify_url = &s
}
// NotifyURL returns the value of the "notify_url" field in the mutation.
func (m *OrderMutation) NotifyURL() (r string, exists bool) {
v := m.notify_url
if v == nil {
return
}
return *v, true
}
// OldNotifyURL returns the old "notify_url" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldNotifyURL(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNotifyURL is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNotifyURL requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNotifyURL: %w", err)
}
return oldValue.NotifyURL, nil
}
// ResetNotifyURL resets all changes to the "notify_url" field.
func (m *OrderMutation) ResetNotifyURL() {
m.notify_url = nil
}
// SetClientIP sets the "client_ip" field.
func (m *OrderMutation) SetClientIP(s string) {
m.client_ip = &s
}
// ClientIP returns the value of the "client_ip" field in the mutation.
func (m *OrderMutation) ClientIP() (r string, exists bool) {
v := m.client_ip
if v == nil {
return
}
return *v, true
}
// OldClientIP returns the old "client_ip" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldClientIP(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldClientIP is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldClientIP requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldClientIP: %w", err)
}
return oldValue.ClientIP, nil
}
// ResetClientIP resets all changes to the "client_ip" field.
func (m *OrderMutation) ResetClientIP() {
m.client_ip = nil
}
// SetAttach sets the "attach" field.
func (m *OrderMutation) SetAttach(s string) {
m.attach = &s
}
// Attach returns the value of the "attach" field in the mutation.
func (m *OrderMutation) Attach() (r string, exists bool) {
v := m.attach
if v == nil {
return
}
return *v, true
}
// OldAttach returns the old "attach" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldAttach(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAttach is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAttach requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAttach: %w", err)
}
return oldValue.Attach, nil
}
// ResetAttach resets all changes to the "attach" field.
func (m *OrderMutation) ResetAttach() {
m.attach = nil
}
// SetOrderExpiration sets the "order_expiration" field.
func (m *OrderMutation) SetOrderExpiration(s string) {
m.order_expiration = &s
}
// OrderExpiration returns the value of the "order_expiration" field in the mutation.
func (m *OrderMutation) OrderExpiration() (r string, exists bool) {
v := m.order_expiration
if v == nil {
return
}
return *v, true
}
// OldOrderExpiration returns the old "order_expiration" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldOrderExpiration(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOrderExpiration is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOrderExpiration requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOrderExpiration: %w", err)
}
return oldValue.OrderExpiration, nil
}
// ResetOrderExpiration resets all changes to the "order_expiration" field.
func (m *OrderMutation) ResetOrderExpiration() {
m.order_expiration = nil
}
// SetExtendParams sets the "extend_params" field.
func (m *OrderMutation) SetExtendParams(s string) {
m.extend_params = &s
}
// ExtendParams returns the value of the "extend_params" field in the mutation.
func (m *OrderMutation) ExtendParams() (r string, exists bool) {
v := m.extend_params
if v == nil {
return
}
return *v, true
}
// OldExtendParams returns the old "extend_params" field's value of the Order entity.
// If the Order object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *OrderMutation) OldExtendParams(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldExtendParams is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldExtendParams requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldExtendParams: %w", err)
}
return oldValue.ExtendParams, nil
}
// ResetExtendParams resets all changes to the "extend_params" field.
func (m *OrderMutation) ResetExtendParams() {
m.extend_params = nil
}
// Where appends a list predicates to the OrderMutation builder.
func (m *OrderMutation) Where(ps ...predicate.Order) {
m.predicates = append(m.predicates, ps...)
}
// Op returns the operation name.
func (m *OrderMutation) Op() Op {
return m.op
}
// Type returns the node type of this mutation (Order).
func (m *OrderMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *OrderMutation) Fields() []string {
fields := make([]string, 0, 16)
if m.merchant_id != nil {
fields = append(fields, order.FieldMerchantID)
}
if m.channel != nil {
fields = append(fields, order.FieldChannel)
}
if m.pay_way != nil {
fields = append(fields, order.FieldPayWay)
}
if m.out_order_no != nil {
fields = append(fields, order.FieldOutOrderNo)
}
if m.total_amount != nil {
fields = append(fields, order.FieldTotalAmount)
}
if m.body != nil {
fields = append(fields, order.FieldBody)
}
if m.order_status != nil {
fields = append(fields, order.FieldOrderStatus)
}
if m.auth_code != nil {
fields = append(fields, order.FieldAuthCode)
}
if m.wx_appid != nil {
fields = append(fields, order.FieldWxAppid)
}
if m.sub_openid != nil {
fields = append(fields, order.FieldSubOpenid)
}
if m.jump_url != nil {
fields = append(fields, order.FieldJumpURL)
}
if m.notify_url != nil {
fields = append(fields, order.FieldNotifyURL)
}
if m.client_ip != nil {
fields = append(fields, order.FieldClientIP)
}
if m.attach != nil {
fields = append(fields, order.FieldAttach)
}
if m.order_expiration != nil {
fields = append(fields, order.FieldOrderExpiration)
}
if m.extend_params != nil {
fields = append(fields, order.FieldExtendParams)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *OrderMutation) Field(name string) (ent.Value, bool) {
switch name {
case order.FieldMerchantID:
return m.MerchantID()
case order.FieldChannel:
return m.Channel()
case order.FieldPayWay:
return m.PayWay()
case order.FieldOutOrderNo:
return m.OutOrderNo()
case order.FieldTotalAmount:
return m.TotalAmount()
case order.FieldBody:
return m.Body()
case order.FieldOrderStatus:
return m.OrderStatus()
case order.FieldAuthCode:
return m.AuthCode()
case order.FieldWxAppid:
return m.WxAppid()
case order.FieldSubOpenid:
return m.SubOpenid()
case order.FieldJumpURL:
return m.JumpURL()
case order.FieldNotifyURL:
return m.NotifyURL()
case order.FieldClientIP:
return m.ClientIP()
case order.FieldAttach:
return m.Attach()
case order.FieldOrderExpiration:
return m.OrderExpiration()
case order.FieldExtendParams:
return m.ExtendParams()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *OrderMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case order.FieldMerchantID:
return m.OldMerchantID(ctx)
case order.FieldChannel:
return m.OldChannel(ctx)
case order.FieldPayWay:
return m.OldPayWay(ctx)
case order.FieldOutOrderNo:
return m.OldOutOrderNo(ctx)
case order.FieldTotalAmount:
return m.OldTotalAmount(ctx)
case order.FieldBody:
return m.OldBody(ctx)
case order.FieldOrderStatus:
return m.OldOrderStatus(ctx)
case order.FieldAuthCode:
return m.OldAuthCode(ctx)
case order.FieldWxAppid:
return m.OldWxAppid(ctx)
case order.FieldSubOpenid:
return m.OldSubOpenid(ctx)
case order.FieldJumpURL:
return m.OldJumpURL(ctx)
case order.FieldNotifyURL:
return m.OldNotifyURL(ctx)
case order.FieldClientIP:
return m.OldClientIP(ctx)
case order.FieldAttach:
return m.OldAttach(ctx)
case order.FieldOrderExpiration:
return m.OldOrderExpiration(ctx)
case order.FieldExtendParams:
return m.OldExtendParams(ctx)
}
return nil, fmt.Errorf("unknown Order field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *OrderMutation) SetField(name string, value ent.Value) error {
switch name {
case order.FieldMerchantID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMerchantID(v)
return nil
case order.FieldChannel:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetChannel(v)
return nil
case order.FieldPayWay:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPayWay(v)
return nil
case order.FieldOutOrderNo:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetOutOrderNo(v)
return nil
case order.FieldTotalAmount:
v, ok := value.(uint64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTotalAmount(v)
return nil
case order.FieldBody:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBody(v)
return nil
case order.FieldOrderStatus:
v, ok := value.(int8)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetOrderStatus(v)
return nil
case order.FieldAuthCode:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAuthCode(v)
return nil
case order.FieldWxAppid:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetWxAppid(v)
return nil
case order.FieldSubOpenid:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSubOpenid(v)
return nil