// Save creates the Fact entities in the database.
Save creates the Fact entities in the database.
// Save creates the Fact entities in the database .
func (fcb *FactCreateBulk) Save(ctx context.Context) ([]*Fact, error) {
	specs := make([]*sqlgraph.CreateSpec, len(fcb.builders))
	nodes := make([]*Fact, len(fcb.builders))
	mutators := make([]Mutator, len(fcb.builders))
	for i := range fcb.builders {
		func(i int, root context.Context) {
			builder := fcb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*FactMutation)
				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, fcb.builders[i+1].mutation)
				} else {
					if err = sqlgraph.BatchCreate(ctx, fcb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
						if cerr, ok := isSQLConstraintError(err); ok {
							err = cerr
						}
					}
				}
				mutation.done = true
				if err != nil {
					return nil, err
				}
				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, fcb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}
func ( fcb * FactCreateBulk ) Save ( ctx context . Context ) ( [ ] * Fact , error ) { specs := make ( [ ] * sqlgraph . CreateSpec , len ( fcb . builders ) ) nodes := make ( [ ] * Fact , len ( fcb . builders ) ) mutators := make ( [ ] Mutator , len ( fcb . builders ) ) for i := range fcb . builders { func ( i int , root context . Context ) { builder := fcb . builders [ i ] builder . defaults ( ) var mut Mutator = MutateFunc ( func ( ctx context . Context , m Mutation ) ( Value , error ) { mutation , ok := m . ( * FactMutation ) if ! ok { return nil , fmt . Errorf ( " " , 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 , fcb . builders [ i + 1 ] . mutation ) } else { if err = sqlgraph . BatchCreate ( ctx , fcb . driver , & sqlgraph . BatchCreateSpec { Nodes : specs } ) ; err != nil { if cerr , ok := isSQLConstraintError ( err ) ; ok { err = cerr } } } mutation . done = true if err != nil { return nil , err } 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 , fcb . builders [ 0 ] . mutation ) ; err != nil { return nil , err } } return nodes , nil }
Save creates the Fact entities in the database.
Save creates the Fact entities in the database .
// Invoke the actual operation on the latest mutation in the chain.