Save creates the AllowList entities in the database.
(ctx context.Context)
| 492 | |
| 493 | // Save creates the AllowList entities in the database. |
| 494 | func (_c *AllowListCreateBulk) Save(ctx context.Context) ([]*AllowList, error) { |
| 495 | if _c.err != nil { |
| 496 | return nil, _c.err |
| 497 | } |
| 498 | specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) |
| 499 | nodes := make([]*AllowList, len(_c.builders)) |
| 500 | mutators := make([]Mutator, len(_c.builders)) |
| 501 | for i := range _c.builders { |
| 502 | func(i int, root context.Context) { |
| 503 | builder := _c.builders[i] |
| 504 | builder.defaults() |
| 505 | var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
| 506 | mutation, ok := m.(*AllowListMutation) |
| 507 | if !ok { |
| 508 | return nil, fmt.Errorf("unexpected mutation type %T", m) |
| 509 | } |
| 510 | if err := builder.check(); err != nil { |
| 511 | return nil, err |
| 512 | } |
| 513 | builder.mutation = mutation |
| 514 | var err error |
| 515 | nodes[i], specs[i] = builder.createSpec() |
| 516 | if i < len(mutators)-1 { |
| 517 | _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) |
| 518 | } else { |
| 519 | spec := &sqlgraph.BatchCreateSpec{Nodes: specs} |
| 520 | spec.OnConflict = _c.conflict |
| 521 | // Invoke the actual operation on the latest mutation in the chain. |
| 522 | if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { |
| 523 | if sqlgraph.IsConstraintError(err) { |
| 524 | err = &ConstraintError{msg: err.Error(), wrap: err} |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | if err != nil { |
| 529 | return nil, err |
| 530 | } |
| 531 | mutation.id = &nodes[i].ID |
| 532 | if specs[i].ID.Value != nil { |
| 533 | id := specs[i].ID.Value.(int64) |
| 534 | nodes[i].ID = int(id) |
| 535 | } |
| 536 | mutation.done = true |
| 537 | return nodes[i], nil |
| 538 | }) |
| 539 | for i := len(builder.hooks) - 1; i >= 0; i-- { |
| 540 | mut = builder.hooks[i](mut) |
| 541 | } |
| 542 | mutators[i] = mut |
| 543 | }(i, ctx) |
| 544 | } |
| 545 | if len(mutators) > 0 { |
| 546 | if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { |
| 547 | return nil, err |
| 548 | } |
| 549 | } |
| 550 | return nodes, nil |
| 551 | } |