-
Notifications
You must be signed in to change notification settings - Fork 13
/
env_update.go
899 lines (821 loc) · 25.8 KB
/
env_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
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
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/e2b-dev/infra/packages/shared/pkg/models/env"
"github.com/e2b-dev/infra/packages/shared/pkg/models/envalias"
"github.com/e2b-dev/infra/packages/shared/pkg/models/envbuild"
"github.com/e2b-dev/infra/packages/shared/pkg/models/internal"
"github.com/e2b-dev/infra/packages/shared/pkg/models/predicate"
"github.com/e2b-dev/infra/packages/shared/pkg/models/team"
"github.com/google/uuid"
)
// EnvUpdate is the builder for updating Env entities.
type EnvUpdate struct {
config
hooks []Hook
mutation *EnvMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the EnvUpdate builder.
func (eu *EnvUpdate) Where(ps ...predicate.Env) *EnvUpdate {
eu.mutation.Where(ps...)
return eu
}
// SetUpdatedAt sets the "updated_at" field.
func (eu *EnvUpdate) SetUpdatedAt(t time.Time) *EnvUpdate {
eu.mutation.SetUpdatedAt(t)
return eu
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (eu *EnvUpdate) SetNillableUpdatedAt(t *time.Time) *EnvUpdate {
if t != nil {
eu.SetUpdatedAt(*t)
}
return eu
}
// SetTeamID sets the "team_id" field.
func (eu *EnvUpdate) SetTeamID(u uuid.UUID) *EnvUpdate {
eu.mutation.SetTeamID(u)
return eu
}
// SetNillableTeamID sets the "team_id" field if the given value is not nil.
func (eu *EnvUpdate) SetNillableTeamID(u *uuid.UUID) *EnvUpdate {
if u != nil {
eu.SetTeamID(*u)
}
return eu
}
// SetPublic sets the "public" field.
func (eu *EnvUpdate) SetPublic(b bool) *EnvUpdate {
eu.mutation.SetPublic(b)
return eu
}
// SetNillablePublic sets the "public" field if the given value is not nil.
func (eu *EnvUpdate) SetNillablePublic(b *bool) *EnvUpdate {
if b != nil {
eu.SetPublic(*b)
}
return eu
}
// SetBuildCount sets the "build_count" field.
func (eu *EnvUpdate) SetBuildCount(i int32) *EnvUpdate {
eu.mutation.ResetBuildCount()
eu.mutation.SetBuildCount(i)
return eu
}
// SetNillableBuildCount sets the "build_count" field if the given value is not nil.
func (eu *EnvUpdate) SetNillableBuildCount(i *int32) *EnvUpdate {
if i != nil {
eu.SetBuildCount(*i)
}
return eu
}
// AddBuildCount adds i to the "build_count" field.
func (eu *EnvUpdate) AddBuildCount(i int32) *EnvUpdate {
eu.mutation.AddBuildCount(i)
return eu
}
// SetSpawnCount sets the "spawn_count" field.
func (eu *EnvUpdate) SetSpawnCount(i int64) *EnvUpdate {
eu.mutation.ResetSpawnCount()
eu.mutation.SetSpawnCount(i)
return eu
}
// SetNillableSpawnCount sets the "spawn_count" field if the given value is not nil.
func (eu *EnvUpdate) SetNillableSpawnCount(i *int64) *EnvUpdate {
if i != nil {
eu.SetSpawnCount(*i)
}
return eu
}
// AddSpawnCount adds i to the "spawn_count" field.
func (eu *EnvUpdate) AddSpawnCount(i int64) *EnvUpdate {
eu.mutation.AddSpawnCount(i)
return eu
}
// SetLastSpawnedAt sets the "last_spawned_at" field.
func (eu *EnvUpdate) SetLastSpawnedAt(t time.Time) *EnvUpdate {
eu.mutation.SetLastSpawnedAt(t)
return eu
}
// SetNillableLastSpawnedAt sets the "last_spawned_at" field if the given value is not nil.
func (eu *EnvUpdate) SetNillableLastSpawnedAt(t *time.Time) *EnvUpdate {
if t != nil {
eu.SetLastSpawnedAt(*t)
}
return eu
}
// ClearLastSpawnedAt clears the value of the "last_spawned_at" field.
func (eu *EnvUpdate) ClearLastSpawnedAt() *EnvUpdate {
eu.mutation.ClearLastSpawnedAt()
return eu
}
// SetTeam sets the "team" edge to the Team entity.
func (eu *EnvUpdate) SetTeam(t *Team) *EnvUpdate {
return eu.SetTeamID(t.ID)
}
// AddEnvAliasIDs adds the "env_aliases" edge to the EnvAlias entity by IDs.
func (eu *EnvUpdate) AddEnvAliasIDs(ids ...string) *EnvUpdate {
eu.mutation.AddEnvAliasIDs(ids...)
return eu
}
// AddEnvAliases adds the "env_aliases" edges to the EnvAlias entity.
func (eu *EnvUpdate) AddEnvAliases(e ...*EnvAlias) *EnvUpdate {
ids := make([]string, len(e))
for i := range e {
ids[i] = e[i].ID
}
return eu.AddEnvAliasIDs(ids...)
}
// AddBuildIDs adds the "builds" edge to the EnvBuild entity by IDs.
func (eu *EnvUpdate) AddBuildIDs(ids ...uuid.UUID) *EnvUpdate {
eu.mutation.AddBuildIDs(ids...)
return eu
}
// AddBuilds adds the "builds" edges to the EnvBuild entity.
func (eu *EnvUpdate) AddBuilds(e ...*EnvBuild) *EnvUpdate {
ids := make([]uuid.UUID, len(e))
for i := range e {
ids[i] = e[i].ID
}
return eu.AddBuildIDs(ids...)
}
// Mutation returns the EnvMutation object of the builder.
func (eu *EnvUpdate) Mutation() *EnvMutation {
return eu.mutation
}
// ClearTeam clears the "team" edge to the Team entity.
func (eu *EnvUpdate) ClearTeam() *EnvUpdate {
eu.mutation.ClearTeam()
return eu
}
// ClearEnvAliases clears all "env_aliases" edges to the EnvAlias entity.
func (eu *EnvUpdate) ClearEnvAliases() *EnvUpdate {
eu.mutation.ClearEnvAliases()
return eu
}
// RemoveEnvAliasIDs removes the "env_aliases" edge to EnvAlias entities by IDs.
func (eu *EnvUpdate) RemoveEnvAliasIDs(ids ...string) *EnvUpdate {
eu.mutation.RemoveEnvAliasIDs(ids...)
return eu
}
// RemoveEnvAliases removes "env_aliases" edges to EnvAlias entities.
func (eu *EnvUpdate) RemoveEnvAliases(e ...*EnvAlias) *EnvUpdate {
ids := make([]string, len(e))
for i := range e {
ids[i] = e[i].ID
}
return eu.RemoveEnvAliasIDs(ids...)
}
// ClearBuilds clears all "builds" edges to the EnvBuild entity.
func (eu *EnvUpdate) ClearBuilds() *EnvUpdate {
eu.mutation.ClearBuilds()
return eu
}
// RemoveBuildIDs removes the "builds" edge to EnvBuild entities by IDs.
func (eu *EnvUpdate) RemoveBuildIDs(ids ...uuid.UUID) *EnvUpdate {
eu.mutation.RemoveBuildIDs(ids...)
return eu
}
// RemoveBuilds removes "builds" edges to EnvBuild entities.
func (eu *EnvUpdate) RemoveBuilds(e ...*EnvBuild) *EnvUpdate {
ids := make([]uuid.UUID, len(e))
for i := range e {
ids[i] = e[i].ID
}
return eu.RemoveBuildIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (eu *EnvUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (eu *EnvUpdate) SaveX(ctx context.Context) int {
affected, err := eu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (eu *EnvUpdate) Exec(ctx context.Context) error {
_, err := eu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (eu *EnvUpdate) ExecX(ctx context.Context) {
if err := eu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (eu *EnvUpdate) check() error {
if _, ok := eu.mutation.TeamID(); eu.mutation.TeamCleared() && !ok {
return errors.New(`models: clearing a required unique edge "Env.team"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (eu *EnvUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *EnvUpdate {
eu.modifiers = append(eu.modifiers, modifiers...)
return eu
}
func (eu *EnvUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := eu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(env.Table, env.Columns, sqlgraph.NewFieldSpec(env.FieldID, field.TypeString))
if ps := eu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := eu.mutation.UpdatedAt(); ok {
_spec.SetField(env.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := eu.mutation.Public(); ok {
_spec.SetField(env.FieldPublic, field.TypeBool, value)
}
if value, ok := eu.mutation.BuildCount(); ok {
_spec.SetField(env.FieldBuildCount, field.TypeInt32, value)
}
if value, ok := eu.mutation.AddedBuildCount(); ok {
_spec.AddField(env.FieldBuildCount, field.TypeInt32, value)
}
if value, ok := eu.mutation.SpawnCount(); ok {
_spec.SetField(env.FieldSpawnCount, field.TypeInt64, value)
}
if value, ok := eu.mutation.AddedSpawnCount(); ok {
_spec.AddField(env.FieldSpawnCount, field.TypeInt64, value)
}
if value, ok := eu.mutation.LastSpawnedAt(); ok {
_spec.SetField(env.FieldLastSpawnedAt, field.TypeTime, value)
}
if eu.mutation.LastSpawnedAtCleared() {
_spec.ClearField(env.FieldLastSpawnedAt, field.TypeTime)
}
if eu.mutation.TeamCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: env.TeamTable,
Columns: []string{env.TeamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
},
}
edge.Schema = eu.schemaConfig.Env
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := eu.mutation.TeamIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: env.TeamTable,
Columns: []string{env.TeamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
},
}
edge.Schema = eu.schemaConfig.Env
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if eu.mutation.EnvAliasesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.EnvAliasesTable,
Columns: []string{env.EnvAliasesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envalias.FieldID, field.TypeString),
},
}
edge.Schema = eu.schemaConfig.EnvAlias
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := eu.mutation.RemovedEnvAliasesIDs(); len(nodes) > 0 && !eu.mutation.EnvAliasesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.EnvAliasesTable,
Columns: []string{env.EnvAliasesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envalias.FieldID, field.TypeString),
},
}
edge.Schema = eu.schemaConfig.EnvAlias
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := eu.mutation.EnvAliasesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.EnvAliasesTable,
Columns: []string{env.EnvAliasesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envalias.FieldID, field.TypeString),
},
}
edge.Schema = eu.schemaConfig.EnvAlias
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if eu.mutation.BuildsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.BuildsTable,
Columns: []string{env.BuildsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envbuild.FieldID, field.TypeUUID),
},
}
edge.Schema = eu.schemaConfig.EnvBuild
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := eu.mutation.RemovedBuildsIDs(); len(nodes) > 0 && !eu.mutation.BuildsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.BuildsTable,
Columns: []string{env.BuildsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envbuild.FieldID, field.TypeUUID),
},
}
edge.Schema = eu.schemaConfig.EnvBuild
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := eu.mutation.BuildsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.BuildsTable,
Columns: []string{env.BuildsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envbuild.FieldID, field.TypeUUID),
},
}
edge.Schema = eu.schemaConfig.EnvBuild
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.Node.Schema = eu.schemaConfig.Env
ctx = internal.NewSchemaConfigContext(ctx, eu.schemaConfig)
_spec.AddModifiers(eu.modifiers...)
if n, err = sqlgraph.UpdateNodes(ctx, eu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{env.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
eu.mutation.done = true
return n, nil
}
// EnvUpdateOne is the builder for updating a single Env entity.
type EnvUpdateOne struct {
config
fields []string
hooks []Hook
mutation *EnvMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUpdatedAt sets the "updated_at" field.
func (euo *EnvUpdateOne) SetUpdatedAt(t time.Time) *EnvUpdateOne {
euo.mutation.SetUpdatedAt(t)
return euo
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (euo *EnvUpdateOne) SetNillableUpdatedAt(t *time.Time) *EnvUpdateOne {
if t != nil {
euo.SetUpdatedAt(*t)
}
return euo
}
// SetTeamID sets the "team_id" field.
func (euo *EnvUpdateOne) SetTeamID(u uuid.UUID) *EnvUpdateOne {
euo.mutation.SetTeamID(u)
return euo
}
// SetNillableTeamID sets the "team_id" field if the given value is not nil.
func (euo *EnvUpdateOne) SetNillableTeamID(u *uuid.UUID) *EnvUpdateOne {
if u != nil {
euo.SetTeamID(*u)
}
return euo
}
// SetPublic sets the "public" field.
func (euo *EnvUpdateOne) SetPublic(b bool) *EnvUpdateOne {
euo.mutation.SetPublic(b)
return euo
}
// SetNillablePublic sets the "public" field if the given value is not nil.
func (euo *EnvUpdateOne) SetNillablePublic(b *bool) *EnvUpdateOne {
if b != nil {
euo.SetPublic(*b)
}
return euo
}
// SetBuildCount sets the "build_count" field.
func (euo *EnvUpdateOne) SetBuildCount(i int32) *EnvUpdateOne {
euo.mutation.ResetBuildCount()
euo.mutation.SetBuildCount(i)
return euo
}
// SetNillableBuildCount sets the "build_count" field if the given value is not nil.
func (euo *EnvUpdateOne) SetNillableBuildCount(i *int32) *EnvUpdateOne {
if i != nil {
euo.SetBuildCount(*i)
}
return euo
}
// AddBuildCount adds i to the "build_count" field.
func (euo *EnvUpdateOne) AddBuildCount(i int32) *EnvUpdateOne {
euo.mutation.AddBuildCount(i)
return euo
}
// SetSpawnCount sets the "spawn_count" field.
func (euo *EnvUpdateOne) SetSpawnCount(i int64) *EnvUpdateOne {
euo.mutation.ResetSpawnCount()
euo.mutation.SetSpawnCount(i)
return euo
}
// SetNillableSpawnCount sets the "spawn_count" field if the given value is not nil.
func (euo *EnvUpdateOne) SetNillableSpawnCount(i *int64) *EnvUpdateOne {
if i != nil {
euo.SetSpawnCount(*i)
}
return euo
}
// AddSpawnCount adds i to the "spawn_count" field.
func (euo *EnvUpdateOne) AddSpawnCount(i int64) *EnvUpdateOne {
euo.mutation.AddSpawnCount(i)
return euo
}
// SetLastSpawnedAt sets the "last_spawned_at" field.
func (euo *EnvUpdateOne) SetLastSpawnedAt(t time.Time) *EnvUpdateOne {
euo.mutation.SetLastSpawnedAt(t)
return euo
}
// SetNillableLastSpawnedAt sets the "last_spawned_at" field if the given value is not nil.
func (euo *EnvUpdateOne) SetNillableLastSpawnedAt(t *time.Time) *EnvUpdateOne {
if t != nil {
euo.SetLastSpawnedAt(*t)
}
return euo
}
// ClearLastSpawnedAt clears the value of the "last_spawned_at" field.
func (euo *EnvUpdateOne) ClearLastSpawnedAt() *EnvUpdateOne {
euo.mutation.ClearLastSpawnedAt()
return euo
}
// SetTeam sets the "team" edge to the Team entity.
func (euo *EnvUpdateOne) SetTeam(t *Team) *EnvUpdateOne {
return euo.SetTeamID(t.ID)
}
// AddEnvAliasIDs adds the "env_aliases" edge to the EnvAlias entity by IDs.
func (euo *EnvUpdateOne) AddEnvAliasIDs(ids ...string) *EnvUpdateOne {
euo.mutation.AddEnvAliasIDs(ids...)
return euo
}
// AddEnvAliases adds the "env_aliases" edges to the EnvAlias entity.
func (euo *EnvUpdateOne) AddEnvAliases(e ...*EnvAlias) *EnvUpdateOne {
ids := make([]string, len(e))
for i := range e {
ids[i] = e[i].ID
}
return euo.AddEnvAliasIDs(ids...)
}
// AddBuildIDs adds the "builds" edge to the EnvBuild entity by IDs.
func (euo *EnvUpdateOne) AddBuildIDs(ids ...uuid.UUID) *EnvUpdateOne {
euo.mutation.AddBuildIDs(ids...)
return euo
}
// AddBuilds adds the "builds" edges to the EnvBuild entity.
func (euo *EnvUpdateOne) AddBuilds(e ...*EnvBuild) *EnvUpdateOne {
ids := make([]uuid.UUID, len(e))
for i := range e {
ids[i] = e[i].ID
}
return euo.AddBuildIDs(ids...)
}
// Mutation returns the EnvMutation object of the builder.
func (euo *EnvUpdateOne) Mutation() *EnvMutation {
return euo.mutation
}
// ClearTeam clears the "team" edge to the Team entity.
func (euo *EnvUpdateOne) ClearTeam() *EnvUpdateOne {
euo.mutation.ClearTeam()
return euo
}
// ClearEnvAliases clears all "env_aliases" edges to the EnvAlias entity.
func (euo *EnvUpdateOne) ClearEnvAliases() *EnvUpdateOne {
euo.mutation.ClearEnvAliases()
return euo
}
// RemoveEnvAliasIDs removes the "env_aliases" edge to EnvAlias entities by IDs.
func (euo *EnvUpdateOne) RemoveEnvAliasIDs(ids ...string) *EnvUpdateOne {
euo.mutation.RemoveEnvAliasIDs(ids...)
return euo
}
// RemoveEnvAliases removes "env_aliases" edges to EnvAlias entities.
func (euo *EnvUpdateOne) RemoveEnvAliases(e ...*EnvAlias) *EnvUpdateOne {
ids := make([]string, len(e))
for i := range e {
ids[i] = e[i].ID
}
return euo.RemoveEnvAliasIDs(ids...)
}
// ClearBuilds clears all "builds" edges to the EnvBuild entity.
func (euo *EnvUpdateOne) ClearBuilds() *EnvUpdateOne {
euo.mutation.ClearBuilds()
return euo
}
// RemoveBuildIDs removes the "builds" edge to EnvBuild entities by IDs.
func (euo *EnvUpdateOne) RemoveBuildIDs(ids ...uuid.UUID) *EnvUpdateOne {
euo.mutation.RemoveBuildIDs(ids...)
return euo
}
// RemoveBuilds removes "builds" edges to EnvBuild entities.
func (euo *EnvUpdateOne) RemoveBuilds(e ...*EnvBuild) *EnvUpdateOne {
ids := make([]uuid.UUID, len(e))
for i := range e {
ids[i] = e[i].ID
}
return euo.RemoveBuildIDs(ids...)
}
// Where appends a list predicates to the EnvUpdate builder.
func (euo *EnvUpdateOne) Where(ps ...predicate.Env) *EnvUpdateOne {
euo.mutation.Where(ps...)
return euo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (euo *EnvUpdateOne) Select(field string, fields ...string) *EnvUpdateOne {
euo.fields = append([]string{field}, fields...)
return euo
}
// Save executes the query and returns the updated Env entity.
func (euo *EnvUpdateOne) Save(ctx context.Context) (*Env, error) {
return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (euo *EnvUpdateOne) SaveX(ctx context.Context) *Env {
node, err := euo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (euo *EnvUpdateOne) Exec(ctx context.Context) error {
_, err := euo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (euo *EnvUpdateOne) ExecX(ctx context.Context) {
if err := euo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (euo *EnvUpdateOne) check() error {
if _, ok := euo.mutation.TeamID(); euo.mutation.TeamCleared() && !ok {
return errors.New(`models: clearing a required unique edge "Env.team"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (euo *EnvUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *EnvUpdateOne {
euo.modifiers = append(euo.modifiers, modifiers...)
return euo
}
func (euo *EnvUpdateOne) sqlSave(ctx context.Context) (_node *Env, err error) {
if err := euo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(env.Table, env.Columns, sqlgraph.NewFieldSpec(env.FieldID, field.TypeString))
id, ok := euo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Env.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := euo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, env.FieldID)
for _, f := range fields {
if !env.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
}
if f != env.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := euo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := euo.mutation.UpdatedAt(); ok {
_spec.SetField(env.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := euo.mutation.Public(); ok {
_spec.SetField(env.FieldPublic, field.TypeBool, value)
}
if value, ok := euo.mutation.BuildCount(); ok {
_spec.SetField(env.FieldBuildCount, field.TypeInt32, value)
}
if value, ok := euo.mutation.AddedBuildCount(); ok {
_spec.AddField(env.FieldBuildCount, field.TypeInt32, value)
}
if value, ok := euo.mutation.SpawnCount(); ok {
_spec.SetField(env.FieldSpawnCount, field.TypeInt64, value)
}
if value, ok := euo.mutation.AddedSpawnCount(); ok {
_spec.AddField(env.FieldSpawnCount, field.TypeInt64, value)
}
if value, ok := euo.mutation.LastSpawnedAt(); ok {
_spec.SetField(env.FieldLastSpawnedAt, field.TypeTime, value)
}
if euo.mutation.LastSpawnedAtCleared() {
_spec.ClearField(env.FieldLastSpawnedAt, field.TypeTime)
}
if euo.mutation.TeamCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: env.TeamTable,
Columns: []string{env.TeamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
},
}
edge.Schema = euo.schemaConfig.Env
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := euo.mutation.TeamIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: env.TeamTable,
Columns: []string{env.TeamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
},
}
edge.Schema = euo.schemaConfig.Env
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if euo.mutation.EnvAliasesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.EnvAliasesTable,
Columns: []string{env.EnvAliasesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envalias.FieldID, field.TypeString),
},
}
edge.Schema = euo.schemaConfig.EnvAlias
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := euo.mutation.RemovedEnvAliasesIDs(); len(nodes) > 0 && !euo.mutation.EnvAliasesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.EnvAliasesTable,
Columns: []string{env.EnvAliasesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envalias.FieldID, field.TypeString),
},
}
edge.Schema = euo.schemaConfig.EnvAlias
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := euo.mutation.EnvAliasesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.EnvAliasesTable,
Columns: []string{env.EnvAliasesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envalias.FieldID, field.TypeString),
},
}
edge.Schema = euo.schemaConfig.EnvAlias
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if euo.mutation.BuildsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.BuildsTable,
Columns: []string{env.BuildsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envbuild.FieldID, field.TypeUUID),
},
}
edge.Schema = euo.schemaConfig.EnvBuild
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := euo.mutation.RemovedBuildsIDs(); len(nodes) > 0 && !euo.mutation.BuildsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.BuildsTable,
Columns: []string{env.BuildsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envbuild.FieldID, field.TypeUUID),
},
}
edge.Schema = euo.schemaConfig.EnvBuild
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := euo.mutation.BuildsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: env.BuildsTable,
Columns: []string{env.BuildsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(envbuild.FieldID, field.TypeUUID),
},
}
edge.Schema = euo.schemaConfig.EnvBuild
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.Node.Schema = euo.schemaConfig.Env
ctx = internal.NewSchemaConfigContext(ctx, euo.schemaConfig)
_spec.AddModifiers(euo.modifiers...)
_node = &Env{config: euo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{env.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
euo.mutation.done = true
return _node, nil
}