func (bpcb *BlogPostCreateBulk) SaveX(ctx context.Context) []*BlogPost {
	v, err := bpcb.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}
SaveX is like Save, but panics if an error occurs.
package ent
import (
	"context"
	"errors"
	"fmt"
	"entgo.io/contrib/entproto/internal/entprototest/ent/blogpost"
	"entgo.io/contrib/entproto/internal/entprototest/ent/category"
	"entgo.io/contrib/entproto/internal/entprototest/ent/user"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)
type BlogPostCreate struct {
	config
	mutation *BlogPostMutation
	hooks    []Hook
}
func (bpc *BlogPostCreate) SetTitle(s string) *BlogPostCreate {
	bpc.mutation.SetTitle(s)
	return bpc
}
func (bpc *BlogPostCreate) SetBody(s string) *BlogPostCreate {
	bpc.mutation.SetBody(s)
	return bpc
}
func (bpc *BlogPostCreate) SetExternalID(i int) *BlogPostCreate {
	bpc.mutation.SetExternalID(i)
	return bpc
}
func (bpc *BlogPostCreate) SetAuthorID(id int) *BlogPostCreate {
	bpc.mutation.SetAuthorID(id)
	return bpc
}
func (bpc *BlogPostCreate) SetNillableAuthorID(id *int) *BlogPostCreate {
	if id != nil {
		bpc = bpc.SetAuthorID(*id)
	}
	return bpc
}
func (bpc *BlogPostCreate) SetAuthor(u *User) *BlogPostCreate {
	return bpc.SetAuthorID(u.ID)
}
func (bpc *BlogPostCreate) AddCategoryIDs(ids ...int) *BlogPostCreate {
	bpc.mutation.AddCategoryIDs(ids...)
	return bpc
}
func (bpc *BlogPostCreate) AddCategories(c ...*Category) *BlogPostCreate {
	ids := make([]int, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return bpc.AddCategoryIDs(ids...)
}
func (bpc *BlogPostCreate) Mutation() *BlogPostMutation {
	return bpc.mutation
}
func (bpc *BlogPostCreate) Save(ctx context.Context) (*BlogPost, error) {
	var (
		err  error
		node *BlogPost
	)
	if len(bpc.hooks) == 0 {
		if err = bpc.check(); err != nil {
			return nil, err
		}
		node, err = bpc.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*BlogPostMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			if err = bpc.check(); err != nil {
				return nil, err
			}
			bpc.mutation = mutation
			if node, err = bpc.sqlSave(ctx); err != nil {
				return nil, err
			}
			mutation.id = &node.ID
			mutation.done = true
			return node, err
		})
		for i := len(bpc.hooks) - 1; i >= 0; i-- {
			if bpc.hooks[i] == nil {
				return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
			}
			mut = bpc.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, bpc.mutation); err != nil {
			return nil, err
		}
	}
	return node, err
}
func (bpc *BlogPostCreate) SaveX(ctx context.Context) *BlogPost {
	v, err := bpc.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}
func (bpc *BlogPostCreate) Exec(ctx context.Context) error {
	_, err := bpc.Save(ctx)
	return err
}
func (bpc *BlogPostCreate) ExecX(ctx context.Context) {
	if err := bpc.Exec(ctx); err != nil {
		panic(err)
	}
}
func (bpc *BlogPostCreate) check() error {
	if _, ok := bpc.mutation.Title(); !ok {
		return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "title"`)}
	}
	if _, ok := bpc.mutation.Body(); !ok {
		return &ValidationError{Name: "body", err: errors.New(`ent: missing required field "body"`)}
	}
	if _, ok := bpc.mutation.ExternalID(); !ok {
		return &ValidationError{Name: "external_id", err: errors.New(`ent: missing required field "external_id"`)}
	}
	return nil
}
func (bpc *BlogPostCreate) sqlSave(ctx context.Context) (*BlogPost, error) {
	_node, _spec := bpc.createSpec()
	if err := sqlgraph.CreateNode(ctx, bpc.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 (bpc *BlogPostCreate) createSpec() (*BlogPost, *sqlgraph.CreateSpec) {
	var (
		_node = &BlogPost{config: bpc.config}
		_spec = &sqlgraph.CreateSpec{
			Table: blogpost.Table,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: blogpost.FieldID,
			},
		}
	)
	if value, ok := bpc.mutation.Title(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: blogpost.FieldTitle,
		})
		_node.Title = value
	}
	if value, ok := bpc.mutation.Body(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: blogpost.FieldBody,
		})
		_node.Body = value
	}
	if value, ok := bpc.mutation.ExternalID(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: blogpost.FieldExternalID,
		})
		_node.ExternalID = value
	}
	if nodes := bpc.mutation.AuthorIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   blogpost.AuthorTable,
			Columns: []string{blogpost.AuthorColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: user.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.blog_post_author = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := bpc.mutation.CategoriesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   blogpost.CategoriesTable,
			Columns: blogpost.CategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: category.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}
type BlogPostCreateBulk struct {
	config
	builders []*BlogPostCreate
}
func (bpcb *BlogPostCreateBulk) Save(ctx context.Context) ([]*BlogPost, error) {
	specs := make([]*sqlgraph.CreateSpec, len(bpcb.builders))
	nodes := make([]*BlogPost, len(bpcb.builders))
	mutators := make([]Mutator, len(bpcb.builders))
	for i := range bpcb.builders {
		func(i int, root context.Context) {
			builder := bpcb.builders[i]
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*BlogPostMutation)
				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, bpcb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					if err = sqlgraph.BatchCreate(ctx, bpcb.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, bpcb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}