func (bpq *BlogPostQuery) Clone() *BlogPostQuery {
	if bpq == nil {
		return nil
	}
	return &BlogPostQuery{
		config:         bpq.config,
		limit:          bpq.limit,
		offset:         bpq.offset,
		order:          append([]OrderFunc{}, bpq.order...),
		predicates:     append([]predicate.BlogPost{}, bpq.predicates...),
		withAuthor:     bpq.withAuthor.Clone(),
		withCategories: bpq.withCategories.Clone(),
		sql:  bpq.sql.Clone(),
		path: bpq.path,
	}
}
Clone returns a duplicate of the BlogPostQuery builder, including all associated steps. It can be
used to prepare common query builders and use them differently after the clone is made.
package ent
import (
	"context"
	"database/sql/driver"
	"errors"
	"fmt"
	"math"
	"entgo.io/contrib/entproto/internal/entprototest/ent/blogpost"
	"entgo.io/contrib/entproto/internal/entprototest/ent/category"
	"entgo.io/contrib/entproto/internal/entprototest/ent/predicate"
	"entgo.io/contrib/entproto/internal/entprototest/ent/user"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)
type BlogPostQuery struct {
	config
	limit      *int
	offset     *int
	unique     *bool
	order      []OrderFunc
	fields     []string
	predicates []predicate.BlogPost
	withAuthor     *UserQuery
	withCategories *CategoryQuery
	withFKs        bool
	sql  *sql.Selector
	path func(context.Context) (*sql.Selector, error)
}
func (bpq *BlogPostQuery) Where(ps ...predicate.BlogPost) *BlogPostQuery {
	bpq.predicates = append(bpq.predicates, ps...)
	return bpq
}
func (bpq *BlogPostQuery) Limit(limit int) *BlogPostQuery {
	bpq.limit = &limit
	return bpq
}
func (bpq *BlogPostQuery) Offset(offset int) *BlogPostQuery {
	bpq.offset = &offset
	return bpq
}
func (bpq *BlogPostQuery) Unique(unique bool) *BlogPostQuery {
	bpq.unique = &unique
	return bpq
}
func (bpq *BlogPostQuery) Order(o ...OrderFunc) *BlogPostQuery {
	bpq.order = append(bpq.order, o...)
	return bpq
}
func (bpq *BlogPostQuery) QueryAuthor() *UserQuery {
	query := &UserQuery{config: bpq.config}
	query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
		if err := bpq.prepareQuery(ctx); err != nil {
			return nil, err
		}
		selector := bpq.sqlQuery(ctx)
		if err := selector.Err(); err != nil {
			return nil, err
		}
		step := sqlgraph.NewStep(
			sqlgraph.From(blogpost.Table, blogpost.FieldID, selector),
			sqlgraph.To(user.Table, user.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, false, blogpost.AuthorTable, blogpost.AuthorColumn),
		)
		fromU = sqlgraph.SetNeighbors(bpq.driver.Dialect(), step)
		return fromU, nil
	}
	return query
}
func (bpq *BlogPostQuery) QueryCategories() *CategoryQuery {
	query := &CategoryQuery{config: bpq.config}
	query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
		if err := bpq.prepareQuery(ctx); err != nil {
			return nil, err
		}
		selector := bpq.sqlQuery(ctx)
		if err := selector.Err(); err != nil {
			return nil, err
		}
		step := sqlgraph.NewStep(
			sqlgraph.From(blogpost.Table, blogpost.FieldID, selector),
			sqlgraph.To(category.Table, category.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, true, blogpost.CategoriesTable, blogpost.CategoriesPrimaryKey...),
		)
		fromU = sqlgraph.SetNeighbors(bpq.driver.Dialect(), step)
		return fromU, nil
	}
	return query
}
func (bpq *BlogPostQuery) First(ctx context.Context) (*BlogPost, error) {
	nodes, err := bpq.Limit(1).All(ctx)
	if err != nil {
		return nil, err
	}
	if len(nodes) == 0 {
		return nil, &NotFoundError{blogpost.Label}
	}
	return nodes[0], nil
}
func (bpq *BlogPostQuery) FirstX(ctx context.Context) *BlogPost {
	node, err := bpq.First(ctx)
	if err != nil && !IsNotFound(err) {
		panic(err)
	}
	return node
}
func (bpq *BlogPostQuery) FirstID(ctx context.Context) (id int, err error) {
	var ids []int
	if ids, err = bpq.Limit(1).IDs(ctx); err != nil {
		return
	}
	if len(ids) == 0 {
		err = &NotFoundError{blogpost.Label}
		return
	}
	return ids[0], nil
}
func (bpq *BlogPostQuery) FirstIDX(ctx context.Context) int {
	id, err := bpq.FirstID(ctx)
	if err != nil && !IsNotFound(err) {
		panic(err)
	}
	return id
}
func (bpq *BlogPostQuery) Only(ctx context.Context) (*BlogPost, error) {
	nodes, err := bpq.Limit(2).All(ctx)
	if err != nil {
		return nil, err
	}
	switch len(nodes) {
	case 1:
		return nodes[0], nil
	case 0:
		return nil, &NotFoundError{blogpost.Label}
	default:
		return nil, &NotSingularError{blogpost.Label}
	}
}
func (bpq *BlogPostQuery) OnlyX(ctx context.Context) *BlogPost {
	node, err := bpq.Only(ctx)
	if err != nil {
		panic(err)
	}
	return node
}
func (bpq *BlogPostQuery) OnlyID(ctx context.Context) (id int, err error) {
	var ids []int
	if ids, err = bpq.Limit(2).IDs(ctx); err != nil {
		return
	}
	switch len(ids) {
	case 1:
		id = ids[0]
	case 0:
		err = &NotFoundError{blogpost.Label}
	default:
		err = &NotSingularError{blogpost.Label}
	}
	return
}
func (bpq *BlogPostQuery) OnlyIDX(ctx context.Context) int {
	id, err := bpq.OnlyID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}
func (bpq *BlogPostQuery) All(ctx context.Context) ([]*BlogPost, error) {
	if err := bpq.prepareQuery(ctx); err != nil {
		return nil, err
	}
	return bpq.sqlAll(ctx)
}
func (bpq *BlogPostQuery) AllX(ctx context.Context) []*BlogPost {
	nodes, err := bpq.All(ctx)
	if err != nil {
		panic(err)
	}
	return nodes
}
func (bpq *BlogPostQuery) IDs(ctx context.Context) ([]int, error) {
	var ids []int
	if err := bpq.Select(blogpost.FieldID).Scan(ctx, &ids); err != nil {
		return nil, err
	}
	return ids, nil
}
func (bpq *BlogPostQuery) IDsX(ctx context.Context) []int {
	ids, err := bpq.IDs(ctx)
	if err != nil {
		panic(err)
	}
	return ids
}
func (bpq *BlogPostQuery) Count(ctx context.Context) (int, error) {
	if err := bpq.prepareQuery(ctx); err != nil {
		return 0, err
	}
	return bpq.sqlCount(ctx)
}
func (bpq *BlogPostQuery) CountX(ctx context.Context) int {
	count, err := bpq.Count(ctx)
	if err != nil {
		panic(err)
	}
	return count
}
func (bpq *BlogPostQuery) Exist(ctx context.Context) (bool, error) {
	if err := bpq.prepareQuery(ctx); err != nil {
		return false, err
	}
	return bpq.sqlExist(ctx)
}
func (bpq *BlogPostQuery) ExistX(ctx context.Context) bool {
	exist, err := bpq.Exist(ctx)
	if err != nil {
		panic(err)
	}
	return exist
}