-
Notifications
You must be signed in to change notification settings - Fork 3
/
flownodeinstance_update.go
852 lines (785 loc) · 26.5 KB
/
flownodeinstance_update.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
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/BeanWei/li/li-engine/contrib/liflow/ent/flowinstance"
"github.com/BeanWei/li/li-engine/contrib/liflow/ent/flownodeinstance"
"github.com/BeanWei/li/li-engine/contrib/liflow/ent/predicate"
)
// FlowNodeInstanceUpdate is the builder for updating FlowNodeInstance entities.
type FlowNodeInstanceUpdate struct {
config
hooks []Hook
mutation *FlowNodeInstanceMutation
}
// Where appends a list predicates to the FlowNodeInstanceUpdate builder.
func (fniu *FlowNodeInstanceUpdate) Where(ps ...predicate.FlowNodeInstance) *FlowNodeInstanceUpdate {
fniu.mutation.Where(ps...)
return fniu
}
// SetUpdatedAt sets the "updated_at" field.
func (fniu *FlowNodeInstanceUpdate) SetUpdatedAt(i int64) *FlowNodeInstanceUpdate {
fniu.mutation.ResetUpdatedAt()
fniu.mutation.SetUpdatedAt(i)
return fniu
}
// AddUpdatedAt adds i to the "updated_at" field.
func (fniu *FlowNodeInstanceUpdate) AddUpdatedAt(i int64) *FlowNodeInstanceUpdate {
fniu.mutation.AddUpdatedAt(i)
return fniu
}
// SetDeletedAt sets the "deleted_at" field.
func (fniu *FlowNodeInstanceUpdate) SetDeletedAt(i int64) *FlowNodeInstanceUpdate {
fniu.mutation.ResetDeletedAt()
fniu.mutation.SetDeletedAt(i)
return fniu
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (fniu *FlowNodeInstanceUpdate) SetNillableDeletedAt(i *int64) *FlowNodeInstanceUpdate {
if i != nil {
fniu.SetDeletedAt(*i)
}
return fniu
}
// AddDeletedAt adds i to the "deleted_at" field.
func (fniu *FlowNodeInstanceUpdate) AddDeletedAt(i int64) *FlowNodeInstanceUpdate {
fniu.mutation.AddDeletedAt(i)
return fniu
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (fniu *FlowNodeInstanceUpdate) ClearDeletedAt() *FlowNodeInstanceUpdate {
fniu.mutation.ClearDeletedAt()
return fniu
}
// SetFlowInstanceID sets the "flow_instance_id" field.
func (fniu *FlowNodeInstanceUpdate) SetFlowInstanceID(s string) *FlowNodeInstanceUpdate {
fniu.mutation.SetFlowInstanceID(s)
return fniu
}
// SetSourceFlowNodeInstanceID sets the "source_flow_node_instance_id" field.
func (fniu *FlowNodeInstanceUpdate) SetSourceFlowNodeInstanceID(s string) *FlowNodeInstanceUpdate {
fniu.mutation.SetSourceFlowNodeInstanceID(s)
return fniu
}
// SetNillableSourceFlowNodeInstanceID sets the "source_flow_node_instance_id" field if the given value is not nil.
func (fniu *FlowNodeInstanceUpdate) SetNillableSourceFlowNodeInstanceID(s *string) *FlowNodeInstanceUpdate {
if s != nil {
fniu.SetSourceFlowNodeInstanceID(*s)
}
return fniu
}
// ClearSourceFlowNodeInstanceID clears the value of the "source_flow_node_instance_id" field.
func (fniu *FlowNodeInstanceUpdate) ClearSourceFlowNodeInstanceID() *FlowNodeInstanceUpdate {
fniu.mutation.ClearSourceFlowNodeInstanceID()
return fniu
}
// SetFlowInstanceDataID sets the "flow_instance_data_id" field.
func (fniu *FlowNodeInstanceUpdate) SetFlowInstanceDataID(s string) *FlowNodeInstanceUpdate {
fniu.mutation.SetFlowInstanceDataID(s)
return fniu
}
// SetNillableFlowInstanceDataID sets the "flow_instance_data_id" field if the given value is not nil.
func (fniu *FlowNodeInstanceUpdate) SetNillableFlowInstanceDataID(s *string) *FlowNodeInstanceUpdate {
if s != nil {
fniu.SetFlowInstanceDataID(*s)
}
return fniu
}
// ClearFlowInstanceDataID clears the value of the "flow_instance_data_id" field.
func (fniu *FlowNodeInstanceUpdate) ClearFlowInstanceDataID() *FlowNodeInstanceUpdate {
fniu.mutation.ClearFlowInstanceDataID()
return fniu
}
// SetNodeKey sets the "node_key" field.
func (fniu *FlowNodeInstanceUpdate) SetNodeKey(s string) *FlowNodeInstanceUpdate {
fniu.mutation.SetNodeKey(s)
return fniu
}
// SetSourceNodeKey sets the "source_node_key" field.
func (fniu *FlowNodeInstanceUpdate) SetSourceNodeKey(s string) *FlowNodeInstanceUpdate {
fniu.mutation.SetSourceNodeKey(s)
return fniu
}
// SetNillableSourceNodeKey sets the "source_node_key" field if the given value is not nil.
func (fniu *FlowNodeInstanceUpdate) SetNillableSourceNodeKey(s *string) *FlowNodeInstanceUpdate {
if s != nil {
fniu.SetSourceNodeKey(*s)
}
return fniu
}
// ClearSourceNodeKey clears the value of the "source_node_key" field.
func (fniu *FlowNodeInstanceUpdate) ClearSourceNodeKey() *FlowNodeInstanceUpdate {
fniu.mutation.ClearSourceNodeKey()
return fniu
}
// SetStatus sets the "status" field.
func (fniu *FlowNodeInstanceUpdate) SetStatus(i int8) *FlowNodeInstanceUpdate {
fniu.mutation.ResetStatus()
fniu.mutation.SetStatus(i)
return fniu
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (fniu *FlowNodeInstanceUpdate) SetNillableStatus(i *int8) *FlowNodeInstanceUpdate {
if i != nil {
fniu.SetStatus(*i)
}
return fniu
}
// AddStatus adds i to the "status" field.
func (fniu *FlowNodeInstanceUpdate) AddStatus(i int8) *FlowNodeInstanceUpdate {
fniu.mutation.AddStatus(i)
return fniu
}
// SetFlowInstance sets the "flow_instance" edge to the FlowInstance entity.
func (fniu *FlowNodeInstanceUpdate) SetFlowInstance(f *FlowInstance) *FlowNodeInstanceUpdate {
return fniu.SetFlowInstanceID(f.ID)
}
// Mutation returns the FlowNodeInstanceMutation object of the builder.
func (fniu *FlowNodeInstanceUpdate) Mutation() *FlowNodeInstanceMutation {
return fniu.mutation
}
// ClearFlowInstance clears the "flow_instance" edge to the FlowInstance entity.
func (fniu *FlowNodeInstanceUpdate) ClearFlowInstance() *FlowNodeInstanceUpdate {
fniu.mutation.ClearFlowInstance()
return fniu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (fniu *FlowNodeInstanceUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
fniu.defaults()
if len(fniu.hooks) == 0 {
if err = fniu.check(); err != nil {
return 0, err
}
affected, err = fniu.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*FlowNodeInstanceMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = fniu.check(); err != nil {
return 0, err
}
fniu.mutation = mutation
affected, err = fniu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(fniu.hooks) - 1; i >= 0; i-- {
if fniu.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = fniu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, fniu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (fniu *FlowNodeInstanceUpdate) SaveX(ctx context.Context) int {
affected, err := fniu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (fniu *FlowNodeInstanceUpdate) Exec(ctx context.Context) error {
_, err := fniu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (fniu *FlowNodeInstanceUpdate) ExecX(ctx context.Context) {
if err := fniu.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (fniu *FlowNodeInstanceUpdate) defaults() {
if _, ok := fniu.mutation.UpdatedAt(); !ok {
v := flownodeinstance.UpdateDefaultUpdatedAt()
fniu.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (fniu *FlowNodeInstanceUpdate) check() error {
if v, ok := fniu.mutation.FlowInstanceID(); ok {
if err := flownodeinstance.FlowInstanceIDValidator(v); err != nil {
return &ValidationError{Name: "flow_instance_id", err: fmt.Errorf(`ent: validator failed for field "FlowNodeInstance.flow_instance_id": %w`, err)}
}
}
if v, ok := fniu.mutation.NodeKey(); ok {
if err := flownodeinstance.NodeKeyValidator(v); err != nil {
return &ValidationError{Name: "node_key", err: fmt.Errorf(`ent: validator failed for field "FlowNodeInstance.node_key": %w`, err)}
}
}
if _, ok := fniu.mutation.FlowInstanceID(); fniu.mutation.FlowInstanceCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "FlowNodeInstance.flow_instance"`)
}
return nil
}
func (fniu *FlowNodeInstanceUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: flownodeinstance.Table,
Columns: flownodeinstance.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flownodeinstance.FieldID,
},
},
}
if ps := fniu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := fniu.mutation.UpdatedAt(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: flownodeinstance.FieldUpdatedAt,
})
}
if value, ok := fniu.mutation.AddedUpdatedAt(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: flownodeinstance.FieldUpdatedAt,
})
}
if value, ok := fniu.mutation.DeletedAt(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: flownodeinstance.FieldDeletedAt,
})
}
if value, ok := fniu.mutation.AddedDeletedAt(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: flownodeinstance.FieldDeletedAt,
})
}
if fniu.mutation.DeletedAtCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Column: flownodeinstance.FieldDeletedAt,
})
}
if value, ok := fniu.mutation.SourceFlowNodeInstanceID(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: flownodeinstance.FieldSourceFlowNodeInstanceID,
})
}
if fniu.mutation.SourceFlowNodeInstanceIDCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flownodeinstance.FieldSourceFlowNodeInstanceID,
})
}
if value, ok := fniu.mutation.FlowInstanceDataID(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: flownodeinstance.FieldFlowInstanceDataID,
})
}
if fniu.mutation.FlowInstanceDataIDCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flownodeinstance.FieldFlowInstanceDataID,
})
}
if value, ok := fniu.mutation.NodeKey(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: flownodeinstance.FieldNodeKey,
})
}
if value, ok := fniu.mutation.SourceNodeKey(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: flownodeinstance.FieldSourceNodeKey,
})
}
if fniu.mutation.SourceNodeKeyCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flownodeinstance.FieldSourceNodeKey,
})
}
if value, ok := fniu.mutation.Status(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt8,
Value: value,
Column: flownodeinstance.FieldStatus,
})
}
if value, ok := fniu.mutation.AddedStatus(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt8,
Value: value,
Column: flownodeinstance.FieldStatus,
})
}
if fniu.mutation.FlowInstanceCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: flownodeinstance.FlowInstanceTable,
Columns: []string{flownodeinstance.FlowInstanceColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flowinstance.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fniu.mutation.FlowInstanceIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: flownodeinstance.FlowInstanceTable,
Columns: []string{flownodeinstance.FlowInstanceColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flowinstance.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, fniu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{flownodeinstance.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return 0, err
}
return n, nil
}
// FlowNodeInstanceUpdateOne is the builder for updating a single FlowNodeInstance entity.
type FlowNodeInstanceUpdateOne struct {
config
fields []string
hooks []Hook
mutation *FlowNodeInstanceMutation
}
// SetUpdatedAt sets the "updated_at" field.
func (fniuo *FlowNodeInstanceUpdateOne) SetUpdatedAt(i int64) *FlowNodeInstanceUpdateOne {
fniuo.mutation.ResetUpdatedAt()
fniuo.mutation.SetUpdatedAt(i)
return fniuo
}
// AddUpdatedAt adds i to the "updated_at" field.
func (fniuo *FlowNodeInstanceUpdateOne) AddUpdatedAt(i int64) *FlowNodeInstanceUpdateOne {
fniuo.mutation.AddUpdatedAt(i)
return fniuo
}
// SetDeletedAt sets the "deleted_at" field.
func (fniuo *FlowNodeInstanceUpdateOne) SetDeletedAt(i int64) *FlowNodeInstanceUpdateOne {
fniuo.mutation.ResetDeletedAt()
fniuo.mutation.SetDeletedAt(i)
return fniuo
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (fniuo *FlowNodeInstanceUpdateOne) SetNillableDeletedAt(i *int64) *FlowNodeInstanceUpdateOne {
if i != nil {
fniuo.SetDeletedAt(*i)
}
return fniuo
}
// AddDeletedAt adds i to the "deleted_at" field.
func (fniuo *FlowNodeInstanceUpdateOne) AddDeletedAt(i int64) *FlowNodeInstanceUpdateOne {
fniuo.mutation.AddDeletedAt(i)
return fniuo
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (fniuo *FlowNodeInstanceUpdateOne) ClearDeletedAt() *FlowNodeInstanceUpdateOne {
fniuo.mutation.ClearDeletedAt()
return fniuo
}
// SetFlowInstanceID sets the "flow_instance_id" field.
func (fniuo *FlowNodeInstanceUpdateOne) SetFlowInstanceID(s string) *FlowNodeInstanceUpdateOne {
fniuo.mutation.SetFlowInstanceID(s)
return fniuo
}
// SetSourceFlowNodeInstanceID sets the "source_flow_node_instance_id" field.
func (fniuo *FlowNodeInstanceUpdateOne) SetSourceFlowNodeInstanceID(s string) *FlowNodeInstanceUpdateOne {
fniuo.mutation.SetSourceFlowNodeInstanceID(s)
return fniuo
}
// SetNillableSourceFlowNodeInstanceID sets the "source_flow_node_instance_id" field if the given value is not nil.
func (fniuo *FlowNodeInstanceUpdateOne) SetNillableSourceFlowNodeInstanceID(s *string) *FlowNodeInstanceUpdateOne {
if s != nil {
fniuo.SetSourceFlowNodeInstanceID(*s)
}
return fniuo
}
// ClearSourceFlowNodeInstanceID clears the value of the "source_flow_node_instance_id" field.
func (fniuo *FlowNodeInstanceUpdateOne) ClearSourceFlowNodeInstanceID() *FlowNodeInstanceUpdateOne {
fniuo.mutation.ClearSourceFlowNodeInstanceID()
return fniuo
}
// SetFlowInstanceDataID sets the "flow_instance_data_id" field.
func (fniuo *FlowNodeInstanceUpdateOne) SetFlowInstanceDataID(s string) *FlowNodeInstanceUpdateOne {
fniuo.mutation.SetFlowInstanceDataID(s)
return fniuo
}
// SetNillableFlowInstanceDataID sets the "flow_instance_data_id" field if the given value is not nil.
func (fniuo *FlowNodeInstanceUpdateOne) SetNillableFlowInstanceDataID(s *string) *FlowNodeInstanceUpdateOne {
if s != nil {
fniuo.SetFlowInstanceDataID(*s)
}
return fniuo
}
// ClearFlowInstanceDataID clears the value of the "flow_instance_data_id" field.
func (fniuo *FlowNodeInstanceUpdateOne) ClearFlowInstanceDataID() *FlowNodeInstanceUpdateOne {
fniuo.mutation.ClearFlowInstanceDataID()
return fniuo
}
// SetNodeKey sets the "node_key" field.
func (fniuo *FlowNodeInstanceUpdateOne) SetNodeKey(s string) *FlowNodeInstanceUpdateOne {
fniuo.mutation.SetNodeKey(s)
return fniuo
}
// SetSourceNodeKey sets the "source_node_key" field.
func (fniuo *FlowNodeInstanceUpdateOne) SetSourceNodeKey(s string) *FlowNodeInstanceUpdateOne {
fniuo.mutation.SetSourceNodeKey(s)
return fniuo
}
// SetNillableSourceNodeKey sets the "source_node_key" field if the given value is not nil.
func (fniuo *FlowNodeInstanceUpdateOne) SetNillableSourceNodeKey(s *string) *FlowNodeInstanceUpdateOne {
if s != nil {
fniuo.SetSourceNodeKey(*s)
}
return fniuo
}
// ClearSourceNodeKey clears the value of the "source_node_key" field.
func (fniuo *FlowNodeInstanceUpdateOne) ClearSourceNodeKey() *FlowNodeInstanceUpdateOne {
fniuo.mutation.ClearSourceNodeKey()
return fniuo
}
// SetStatus sets the "status" field.
func (fniuo *FlowNodeInstanceUpdateOne) SetStatus(i int8) *FlowNodeInstanceUpdateOne {
fniuo.mutation.ResetStatus()
fniuo.mutation.SetStatus(i)
return fniuo
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (fniuo *FlowNodeInstanceUpdateOne) SetNillableStatus(i *int8) *FlowNodeInstanceUpdateOne {
if i != nil {
fniuo.SetStatus(*i)
}
return fniuo
}
// AddStatus adds i to the "status" field.
func (fniuo *FlowNodeInstanceUpdateOne) AddStatus(i int8) *FlowNodeInstanceUpdateOne {
fniuo.mutation.AddStatus(i)
return fniuo
}
// SetFlowInstance sets the "flow_instance" edge to the FlowInstance entity.
func (fniuo *FlowNodeInstanceUpdateOne) SetFlowInstance(f *FlowInstance) *FlowNodeInstanceUpdateOne {
return fniuo.SetFlowInstanceID(f.ID)
}
// Mutation returns the FlowNodeInstanceMutation object of the builder.
func (fniuo *FlowNodeInstanceUpdateOne) Mutation() *FlowNodeInstanceMutation {
return fniuo.mutation
}
// ClearFlowInstance clears the "flow_instance" edge to the FlowInstance entity.
func (fniuo *FlowNodeInstanceUpdateOne) ClearFlowInstance() *FlowNodeInstanceUpdateOne {
fniuo.mutation.ClearFlowInstance()
return fniuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (fniuo *FlowNodeInstanceUpdateOne) Select(field string, fields ...string) *FlowNodeInstanceUpdateOne {
fniuo.fields = append([]string{field}, fields...)
return fniuo
}
// Save executes the query and returns the updated FlowNodeInstance entity.
func (fniuo *FlowNodeInstanceUpdateOne) Save(ctx context.Context) (*FlowNodeInstance, error) {
var (
err error
node *FlowNodeInstance
)
fniuo.defaults()
if len(fniuo.hooks) == 0 {
if err = fniuo.check(); err != nil {
return nil, err
}
node, err = fniuo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*FlowNodeInstanceMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = fniuo.check(); err != nil {
return nil, err
}
fniuo.mutation = mutation
node, err = fniuo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(fniuo.hooks) - 1; i >= 0; i-- {
if fniuo.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = fniuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, fniuo.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (fniuo *FlowNodeInstanceUpdateOne) SaveX(ctx context.Context) *FlowNodeInstance {
node, err := fniuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (fniuo *FlowNodeInstanceUpdateOne) Exec(ctx context.Context) error {
_, err := fniuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (fniuo *FlowNodeInstanceUpdateOne) ExecX(ctx context.Context) {
if err := fniuo.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (fniuo *FlowNodeInstanceUpdateOne) defaults() {
if _, ok := fniuo.mutation.UpdatedAt(); !ok {
v := flownodeinstance.UpdateDefaultUpdatedAt()
fniuo.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (fniuo *FlowNodeInstanceUpdateOne) check() error {
if v, ok := fniuo.mutation.FlowInstanceID(); ok {
if err := flownodeinstance.FlowInstanceIDValidator(v); err != nil {
return &ValidationError{Name: "flow_instance_id", err: fmt.Errorf(`ent: validator failed for field "FlowNodeInstance.flow_instance_id": %w`, err)}
}
}
if v, ok := fniuo.mutation.NodeKey(); ok {
if err := flownodeinstance.NodeKeyValidator(v); err != nil {
return &ValidationError{Name: "node_key", err: fmt.Errorf(`ent: validator failed for field "FlowNodeInstance.node_key": %w`, err)}
}
}
if _, ok := fniuo.mutation.FlowInstanceID(); fniuo.mutation.FlowInstanceCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "FlowNodeInstance.flow_instance"`)
}
return nil
}
func (fniuo *FlowNodeInstanceUpdateOne) sqlSave(ctx context.Context) (_node *FlowNodeInstance, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: flownodeinstance.Table,
Columns: flownodeinstance.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flownodeinstance.FieldID,
},
},
}
id, ok := fniuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "FlowNodeInstance.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := fniuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, flownodeinstance.FieldID)
for _, f := range fields {
if !flownodeinstance.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != flownodeinstance.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := fniuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := fniuo.mutation.UpdatedAt(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: flownodeinstance.FieldUpdatedAt,
})
}
if value, ok := fniuo.mutation.AddedUpdatedAt(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: flownodeinstance.FieldUpdatedAt,
})
}
if value, ok := fniuo.mutation.DeletedAt(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: flownodeinstance.FieldDeletedAt,
})
}
if value, ok := fniuo.mutation.AddedDeletedAt(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: flownodeinstance.FieldDeletedAt,
})
}
if fniuo.mutation.DeletedAtCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Column: flownodeinstance.FieldDeletedAt,
})
}
if value, ok := fniuo.mutation.SourceFlowNodeInstanceID(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: flownodeinstance.FieldSourceFlowNodeInstanceID,
})
}
if fniuo.mutation.SourceFlowNodeInstanceIDCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flownodeinstance.FieldSourceFlowNodeInstanceID,
})
}
if value, ok := fniuo.mutation.FlowInstanceDataID(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: flownodeinstance.FieldFlowInstanceDataID,
})
}
if fniuo.mutation.FlowInstanceDataIDCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flownodeinstance.FieldFlowInstanceDataID,
})
}
if value, ok := fniuo.mutation.NodeKey(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: flownodeinstance.FieldNodeKey,
})
}
if value, ok := fniuo.mutation.SourceNodeKey(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: flownodeinstance.FieldSourceNodeKey,
})
}
if fniuo.mutation.SourceNodeKeyCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flownodeinstance.FieldSourceNodeKey,
})
}
if value, ok := fniuo.mutation.Status(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt8,
Value: value,
Column: flownodeinstance.FieldStatus,
})
}
if value, ok := fniuo.mutation.AddedStatus(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt8,
Value: value,
Column: flownodeinstance.FieldStatus,
})
}
if fniuo.mutation.FlowInstanceCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: flownodeinstance.FlowInstanceTable,
Columns: []string{flownodeinstance.FlowInstanceColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flowinstance.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fniuo.mutation.FlowInstanceIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: flownodeinstance.FlowInstanceTable,
Columns: []string{flownodeinstance.FlowInstanceColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: flowinstance.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &FlowNodeInstance{config: fniuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, fniuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{flownodeinstance.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return nil, err
}
return _node, nil
}