Save creates the GitCommit entities in the database.
(ctx context.Context)
| 742 | |
| 743 | // Save creates the GitCommit entities in the database. |
| 744 | func (gccb *GitCommitCreateBulk) Save(ctx context.Context) ([]*GitCommit, error) { |
| 745 | if gccb.err != nil { |
| 746 | return nil, gccb.err |
| 747 | } |
| 748 | specs := make([]*sqlgraph.CreateSpec, len(gccb.builders)) |
| 749 | nodes := make([]*GitCommit, len(gccb.builders)) |
| 750 | mutators := make([]Mutator, len(gccb.builders)) |
| 751 | for i := range gccb.builders { |
| 752 | func(i int, root context.Context) { |
| 753 | builder := gccb.builders[i] |
| 754 | builder.defaults() |
| 755 | var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
| 756 | mutation, ok := m.(*GitCommitMutation) |
| 757 | if !ok { |
| 758 | return nil, fmt.Errorf("unexpected mutation type %T", m) |
| 759 | } |
| 760 | if err := builder.check(); err != nil { |
| 761 | return nil, err |
| 762 | } |
| 763 | builder.mutation = mutation |
| 764 | var err error |
| 765 | nodes[i], specs[i] = builder.createSpec() |
| 766 | if i < len(mutators)-1 { |
| 767 | _, err = mutators[i+1].Mutate(root, gccb.builders[i+1].mutation) |
| 768 | } else { |
| 769 | spec := &sqlgraph.BatchCreateSpec{Nodes: specs} |
| 770 | spec.OnConflict = gccb.conflict |
| 771 | // Invoke the actual operation on the latest mutation in the chain. |
| 772 | if err = sqlgraph.BatchCreate(ctx, gccb.driver, spec); err != nil { |
| 773 | if sqlgraph.IsConstraintError(err) { |
| 774 | err = &ConstraintError{msg: err.Error(), wrap: err} |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | if err != nil { |
| 779 | return nil, err |
| 780 | } |
| 781 | mutation.id = &nodes[i].ID |
| 782 | mutation.done = true |
| 783 | return nodes[i], nil |
| 784 | }) |
| 785 | for i := len(builder.hooks) - 1; i >= 0; i-- { |
| 786 | mut = builder.hooks[i](mut) |
| 787 | } |
| 788 | mutators[i] = mut |
| 789 | }(i, ctx) |
| 790 | } |
| 791 | if len(mutators) > 0 { |
| 792 | if _, err := mutators[0].Mutate(ctx, gccb.builders[0].mutation); err != nil { |
| 793 | return nil, err |
| 794 | } |
| 795 | } |
| 796 | return nodes, nil |
| 797 | } |
| 798 | |
| 799 | // SaveX is like Save, but panics if an error occurs. |
| 800 | func (gccb *GitCommitCreateBulk) SaveX(ctx context.Context) []*GitCommit { |