Save creates the NodeVersion entities in the database.
(ctx context.Context)
| 876 | |
| 877 | // Save creates the NodeVersion entities in the database. |
| 878 | func (nvcb *NodeVersionCreateBulk) Save(ctx context.Context) ([]*NodeVersion, error) { |
| 879 | if nvcb.err != nil { |
| 880 | return nil, nvcb.err |
| 881 | } |
| 882 | specs := make([]*sqlgraph.CreateSpec, len(nvcb.builders)) |
| 883 | nodes := make([]*NodeVersion, len(nvcb.builders)) |
| 884 | mutators := make([]Mutator, len(nvcb.builders)) |
| 885 | for i := range nvcb.builders { |
| 886 | func(i int, root context.Context) { |
| 887 | builder := nvcb.builders[i] |
| 888 | builder.defaults() |
| 889 | var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
| 890 | mutation, ok := m.(*NodeVersionMutation) |
| 891 | if !ok { |
| 892 | return nil, fmt.Errorf("unexpected mutation type %T", m) |
| 893 | } |
| 894 | if err := builder.check(); err != nil { |
| 895 | return nil, err |
| 896 | } |
| 897 | builder.mutation = mutation |
| 898 | var err error |
| 899 | nodes[i], specs[i] = builder.createSpec() |
| 900 | if i < len(mutators)-1 { |
| 901 | _, err = mutators[i+1].Mutate(root, nvcb.builders[i+1].mutation) |
| 902 | } else { |
| 903 | spec := &sqlgraph.BatchCreateSpec{Nodes: specs} |
| 904 | spec.OnConflict = nvcb.conflict |
| 905 | // Invoke the actual operation on the latest mutation in the chain. |
| 906 | if err = sqlgraph.BatchCreate(ctx, nvcb.driver, spec); err != nil { |
| 907 | if sqlgraph.IsConstraintError(err) { |
| 908 | err = &ConstraintError{msg: err.Error(), wrap: err} |
| 909 | } |
| 910 | } |
| 911 | } |
| 912 | if err != nil { |
| 913 | return nil, err |
| 914 | } |
| 915 | mutation.id = &nodes[i].ID |
| 916 | mutation.done = true |
| 917 | return nodes[i], nil |
| 918 | }) |
| 919 | for i := len(builder.hooks) - 1; i >= 0; i-- { |
| 920 | mut = builder.hooks[i](mut) |
| 921 | } |
| 922 | mutators[i] = mut |
| 923 | }(i, ctx) |
| 924 | } |
| 925 | if len(mutators) > 0 { |
| 926 | if _, err := mutators[0].Mutate(ctx, nvcb.builders[0].mutation); err != nil { |
| 927 | return nil, err |
| 928 | } |
| 929 | } |
| 930 | return nodes, nil |
| 931 | } |
| 932 | |
| 933 | // SaveX is like Save, but panics if an error occurs. |
| 934 | func (nvcb *NodeVersionCreateBulk) SaveX(ctx context.Context) []*NodeVersion { |