This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdeployment_create.go
722 lines (669 loc) · 20.3 KB
/
deployment_create.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
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/gitploy-io/gitploy/model/ent/deployment"
"github.com/gitploy-io/gitploy/model/ent/deploymentstatus"
"github.com/gitploy-io/gitploy/model/ent/repo"
"github.com/gitploy-io/gitploy/model/ent/review"
"github.com/gitploy-io/gitploy/model/ent/user"
)
// DeploymentCreate is the builder for creating a Deployment entity.
type DeploymentCreate struct {
config
mutation *DeploymentMutation
hooks []Hook
}
// SetNumber sets the "number" field.
func (dc *DeploymentCreate) SetNumber(i int) *DeploymentCreate {
dc.mutation.SetNumber(i)
return dc
}
// SetType sets the "type" field.
func (dc *DeploymentCreate) SetType(d deployment.Type) *DeploymentCreate {
dc.mutation.SetType(d)
return dc
}
// SetNillableType sets the "type" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableType(d *deployment.Type) *DeploymentCreate {
if d != nil {
dc.SetType(*d)
}
return dc
}
// SetEnv sets the "env" field.
func (dc *DeploymentCreate) SetEnv(s string) *DeploymentCreate {
dc.mutation.SetEnv(s)
return dc
}
// SetRef sets the "ref" field.
func (dc *DeploymentCreate) SetRef(s string) *DeploymentCreate {
dc.mutation.SetRef(s)
return dc
}
// SetDynamicPayload sets the "dynamic_payload" field.
func (dc *DeploymentCreate) SetDynamicPayload(m map[string]interface{}) *DeploymentCreate {
dc.mutation.SetDynamicPayload(m)
return dc
}
// SetStatus sets the "status" field.
func (dc *DeploymentCreate) SetStatus(d deployment.Status) *DeploymentCreate {
dc.mutation.SetStatus(d)
return dc
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableStatus(d *deployment.Status) *DeploymentCreate {
if d != nil {
dc.SetStatus(*d)
}
return dc
}
// SetUID sets the "uid" field.
func (dc *DeploymentCreate) SetUID(i int64) *DeploymentCreate {
dc.mutation.SetUID(i)
return dc
}
// SetNillableUID sets the "uid" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableUID(i *int64) *DeploymentCreate {
if i != nil {
dc.SetUID(*i)
}
return dc
}
// SetSha sets the "sha" field.
func (dc *DeploymentCreate) SetSha(s string) *DeploymentCreate {
dc.mutation.SetSha(s)
return dc
}
// SetNillableSha sets the "sha" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableSha(s *string) *DeploymentCreate {
if s != nil {
dc.SetSha(*s)
}
return dc
}
// SetHTMLURL sets the "html_url" field.
func (dc *DeploymentCreate) SetHTMLURL(s string) *DeploymentCreate {
dc.mutation.SetHTMLURL(s)
return dc
}
// SetNillableHTMLURL sets the "html_url" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableHTMLURL(s *string) *DeploymentCreate {
if s != nil {
dc.SetHTMLURL(*s)
}
return dc
}
// SetProductionEnvironment sets the "production_environment" field.
func (dc *DeploymentCreate) SetProductionEnvironment(b bool) *DeploymentCreate {
dc.mutation.SetProductionEnvironment(b)
return dc
}
// SetNillableProductionEnvironment sets the "production_environment" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableProductionEnvironment(b *bool) *DeploymentCreate {
if b != nil {
dc.SetProductionEnvironment(*b)
}
return dc
}
// SetIsRollback sets the "is_rollback" field.
func (dc *DeploymentCreate) SetIsRollback(b bool) *DeploymentCreate {
dc.mutation.SetIsRollback(b)
return dc
}
// SetNillableIsRollback sets the "is_rollback" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableIsRollback(b *bool) *DeploymentCreate {
if b != nil {
dc.SetIsRollback(*b)
}
return dc
}
// SetCreatedAt sets the "created_at" field.
func (dc *DeploymentCreate) SetCreatedAt(t time.Time) *DeploymentCreate {
dc.mutation.SetCreatedAt(t)
return dc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableCreatedAt(t *time.Time) *DeploymentCreate {
if t != nil {
dc.SetCreatedAt(*t)
}
return dc
}
// SetUpdatedAt sets the "updated_at" field.
func (dc *DeploymentCreate) SetUpdatedAt(t time.Time) *DeploymentCreate {
dc.mutation.SetUpdatedAt(t)
return dc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableUpdatedAt(t *time.Time) *DeploymentCreate {
if t != nil {
dc.SetUpdatedAt(*t)
}
return dc
}
// SetUserID sets the "user_id" field.
func (dc *DeploymentCreate) SetUserID(i int64) *DeploymentCreate {
dc.mutation.SetUserID(i)
return dc
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableUserID(i *int64) *DeploymentCreate {
if i != nil {
dc.SetUserID(*i)
}
return dc
}
// SetRepoID sets the "repo_id" field.
func (dc *DeploymentCreate) SetRepoID(i int64) *DeploymentCreate {
dc.mutation.SetRepoID(i)
return dc
}
// SetIsApprovalEnabled sets the "is_approval_enabled" field.
func (dc *DeploymentCreate) SetIsApprovalEnabled(b bool) *DeploymentCreate {
dc.mutation.SetIsApprovalEnabled(b)
return dc
}
// SetNillableIsApprovalEnabled sets the "is_approval_enabled" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableIsApprovalEnabled(b *bool) *DeploymentCreate {
if b != nil {
dc.SetIsApprovalEnabled(*b)
}
return dc
}
// SetRequiredApprovalCount sets the "required_approval_count" field.
func (dc *DeploymentCreate) SetRequiredApprovalCount(i int) *DeploymentCreate {
dc.mutation.SetRequiredApprovalCount(i)
return dc
}
// SetNillableRequiredApprovalCount sets the "required_approval_count" field if the given value is not nil.
func (dc *DeploymentCreate) SetNillableRequiredApprovalCount(i *int) *DeploymentCreate {
if i != nil {
dc.SetRequiredApprovalCount(*i)
}
return dc
}
// SetUser sets the "user" edge to the User entity.
func (dc *DeploymentCreate) SetUser(u *User) *DeploymentCreate {
return dc.SetUserID(u.ID)
}
// SetRepo sets the "repo" edge to the Repo entity.
func (dc *DeploymentCreate) SetRepo(r *Repo) *DeploymentCreate {
return dc.SetRepoID(r.ID)
}
// AddReviewIDs adds the "reviews" edge to the Review entity by IDs.
func (dc *DeploymentCreate) AddReviewIDs(ids ...int) *DeploymentCreate {
dc.mutation.AddReviewIDs(ids...)
return dc
}
// AddReviews adds the "reviews" edges to the Review entity.
func (dc *DeploymentCreate) AddReviews(r ...*Review) *DeploymentCreate {
ids := make([]int, len(r))
for i := range r {
ids[i] = r[i].ID
}
return dc.AddReviewIDs(ids...)
}
// AddDeploymentStatusIDs adds the "deployment_statuses" edge to the DeploymentStatus entity by IDs.
func (dc *DeploymentCreate) AddDeploymentStatusIDs(ids ...int) *DeploymentCreate {
dc.mutation.AddDeploymentStatusIDs(ids...)
return dc
}
// AddDeploymentStatuses adds the "deployment_statuses" edges to the DeploymentStatus entity.
func (dc *DeploymentCreate) AddDeploymentStatuses(d ...*DeploymentStatus) *DeploymentCreate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dc.AddDeploymentStatusIDs(ids...)
}
// Mutation returns the DeploymentMutation object of the builder.
func (dc *DeploymentCreate) Mutation() *DeploymentMutation {
return dc.mutation
}
// Save creates the Deployment in the database.
func (dc *DeploymentCreate) Save(ctx context.Context) (*Deployment, error) {
var (
err error
node *Deployment
)
dc.defaults()
if len(dc.hooks) == 0 {
if err = dc.check(); err != nil {
return nil, err
}
node, err = dc.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DeploymentMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = dc.check(); err != nil {
return nil, err
}
dc.mutation = mutation
if node, err = dc.sqlSave(ctx); err != nil {
return nil, err
}
mutation.id = &node.ID
mutation.done = true
return node, err
})
for i := len(dc.hooks) - 1; i >= 0; i-- {
if dc.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = dc.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, dc.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX calls Save and panics if Save returns an error.
func (dc *DeploymentCreate) SaveX(ctx context.Context) *Deployment {
v, err := dc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dc *DeploymentCreate) Exec(ctx context.Context) error {
_, err := dc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dc *DeploymentCreate) ExecX(ctx context.Context) {
if err := dc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (dc *DeploymentCreate) defaults() {
if _, ok := dc.mutation.GetType(); !ok {
v := deployment.DefaultType
dc.mutation.SetType(v)
}
if _, ok := dc.mutation.Status(); !ok {
v := deployment.DefaultStatus
dc.mutation.SetStatus(v)
}
if _, ok := dc.mutation.ProductionEnvironment(); !ok {
v := deployment.DefaultProductionEnvironment
dc.mutation.SetProductionEnvironment(v)
}
if _, ok := dc.mutation.IsRollback(); !ok {
v := deployment.DefaultIsRollback
dc.mutation.SetIsRollback(v)
}
if _, ok := dc.mutation.CreatedAt(); !ok {
v := deployment.DefaultCreatedAt()
dc.mutation.SetCreatedAt(v)
}
if _, ok := dc.mutation.UpdatedAt(); !ok {
v := deployment.DefaultUpdatedAt()
dc.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (dc *DeploymentCreate) check() error {
if _, ok := dc.mutation.Number(); !ok {
return &ValidationError{Name: "number", err: errors.New(`ent: missing required field "Deployment.number"`)}
}
if _, ok := dc.mutation.GetType(); !ok {
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Deployment.type"`)}
}
if v, ok := dc.mutation.GetType(); ok {
if err := deployment.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Deployment.type": %w`, err)}
}
}
if _, ok := dc.mutation.Env(); !ok {
return &ValidationError{Name: "env", err: errors.New(`ent: missing required field "Deployment.env"`)}
}
if _, ok := dc.mutation.Ref(); !ok {
return &ValidationError{Name: "ref", err: errors.New(`ent: missing required field "Deployment.ref"`)}
}
if _, ok := dc.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Deployment.status"`)}
}
if v, ok := dc.mutation.Status(); ok {
if err := deployment.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Deployment.status": %w`, err)}
}
}
if v, ok := dc.mutation.HTMLURL(); ok {
if err := deployment.HTMLURLValidator(v); err != nil {
return &ValidationError{Name: "html_url", err: fmt.Errorf(`ent: validator failed for field "Deployment.html_url": %w`, err)}
}
}
if _, ok := dc.mutation.ProductionEnvironment(); !ok {
return &ValidationError{Name: "production_environment", err: errors.New(`ent: missing required field "Deployment.production_environment"`)}
}
if _, ok := dc.mutation.IsRollback(); !ok {
return &ValidationError{Name: "is_rollback", err: errors.New(`ent: missing required field "Deployment.is_rollback"`)}
}
if _, ok := dc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Deployment.created_at"`)}
}
if _, ok := dc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Deployment.updated_at"`)}
}
if _, ok := dc.mutation.RepoID(); !ok {
return &ValidationError{Name: "repo_id", err: errors.New(`ent: missing required field "Deployment.repo_id"`)}
}
if _, ok := dc.mutation.RepoID(); !ok {
return &ValidationError{Name: "repo", err: errors.New(`ent: missing required edge "Deployment.repo"`)}
}
return nil
}
func (dc *DeploymentCreate) sqlSave(ctx context.Context) (*Deployment, error) {
_node, _spec := dc.createSpec()
if err := sqlgraph.CreateNode(ctx, dc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
return _node, nil
}
func (dc *DeploymentCreate) createSpec() (*Deployment, *sqlgraph.CreateSpec) {
var (
_node = &Deployment{config: dc.config}
_spec = &sqlgraph.CreateSpec{
Table: deployment.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: deployment.FieldID,
},
}
)
if value, ok := dc.mutation.Number(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: deployment.FieldNumber,
})
_node.Number = value
}
if value, ok := dc.mutation.GetType(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeEnum,
Value: value,
Column: deployment.FieldType,
})
_node.Type = value
}
if value, ok := dc.mutation.Env(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: deployment.FieldEnv,
})
_node.Env = value
}
if value, ok := dc.mutation.Ref(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: deployment.FieldRef,
})
_node.Ref = value
}
if value, ok := dc.mutation.DynamicPayload(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Value: value,
Column: deployment.FieldDynamicPayload,
})
_node.DynamicPayload = value
}
if value, ok := dc.mutation.Status(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeEnum,
Value: value,
Column: deployment.FieldStatus,
})
_node.Status = value
}
if value, ok := dc.mutation.UID(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: deployment.FieldUID,
})
_node.UID = value
}
if value, ok := dc.mutation.Sha(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: deployment.FieldSha,
})
_node.Sha = value
}
if value, ok := dc.mutation.HTMLURL(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: deployment.FieldHTMLURL,
})
_node.HTMLURL = value
}
if value, ok := dc.mutation.ProductionEnvironment(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeBool,
Value: value,
Column: deployment.FieldProductionEnvironment,
})
_node.ProductionEnvironment = value
}
if value, ok := dc.mutation.IsRollback(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeBool,
Value: value,
Column: deployment.FieldIsRollback,
})
_node.IsRollback = value
}
if value, ok := dc.mutation.CreatedAt(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: deployment.FieldCreatedAt,
})
_node.CreatedAt = value
}
if value, ok := dc.mutation.UpdatedAt(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: deployment.FieldUpdatedAt,
})
_node.UpdatedAt = value
}
if value, ok := dc.mutation.IsApprovalEnabled(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeBool,
Value: value,
Column: deployment.FieldIsApprovalEnabled,
})
_node.IsApprovalEnabled = &value
}
if value, ok := dc.mutation.RequiredApprovalCount(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: deployment.FieldRequiredApprovalCount,
})
_node.RequiredApprovalCount = &value
}
if nodes := dc.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: deployment.UserTable,
Columns: []string{deployment.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Column: user.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.UserID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := dc.mutation.RepoIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: deployment.RepoTable,
Columns: []string{deployment.RepoColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Column: repo.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.RepoID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := dc.mutation.ReviewsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: deployment.ReviewsTable,
Columns: []string{deployment.ReviewsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: review.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := dc.mutation.DeploymentStatusesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: deployment.DeploymentStatusesTable,
Columns: []string{deployment.DeploymentStatusesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: deploymentstatus.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// DeploymentCreateBulk is the builder for creating many Deployment entities in bulk.
type DeploymentCreateBulk struct {
config
builders []*DeploymentCreate
}
// Save creates the Deployment entities in the database.
func (dcb *DeploymentCreateBulk) Save(ctx context.Context) ([]*Deployment, error) {
specs := make([]*sqlgraph.CreateSpec, len(dcb.builders))
nodes := make([]*Deployment, len(dcb.builders))
mutators := make([]Mutator, len(dcb.builders))
for i := range dcb.builders {
func(i int, root context.Context) {
builder := dcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DeploymentMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
nodes[i], specs[i] = builder.createSpec()
var err error
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, dcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, dcb.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
mutation.done = true
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, dcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dcb *DeploymentCreateBulk) SaveX(ctx context.Context) []*Deployment {
v, err := dcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dcb *DeploymentCreateBulk) Exec(ctx context.Context) error {
_, err := dcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dcb *DeploymentCreateBulk) ExecX(ctx context.Context) {
if err := dcb.Exec(ctx); err != nil {
panic(err)
}
}