func (vmgb *ValidMessageGroupBy) Int(ctx context.Context) (_ int, err error) {
	var v []int
	if v, err = vmgb.Ints(ctx); err != nil {
		return
	}
	switch len(v) {
	case 1:
		return v[0], nil
	case 0:
		err = &NotFoundError{validmessage.Label}
	default:
		err = fmt.Errorf("ent: ValidMessageGroupBy.Ints returned %d results when one was expected", len(v))
	}
	return
}
Int returns a single int from a group-by query.
It is only allowed when executing a group-by query with one field.
package ent
import (
	"context"
	"errors"
	"fmt"
	"math"
	"entgo.io/contrib/entproto/internal/entprototest/ent/predicate"
	"entgo.io/contrib/entproto/internal/entprototest/ent/validmessage"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)
type ValidMessageQuery struct {
	config
	limit      *int
	offset     *int
	unique     *bool
	order      []OrderFunc
	fields     []string
	predicates []predicate.ValidMessage
	sql  *sql.Selector
	path func(context.Context) (*sql.Selector, error)
}
func (vmq *ValidMessageQuery) Where(ps ...predicate.ValidMessage) *ValidMessageQuery {
	vmq.predicates = append(vmq.predicates, ps...)
	return vmq
}
func (vmq *ValidMessageQuery) Limit(limit int) *ValidMessageQuery {
	vmq.limit = &limit
	return vmq
}
func (vmq *ValidMessageQuery) Offset(offset int) *ValidMessageQuery {
	vmq.offset = &offset
	return vmq
}
func (vmq *ValidMessageQuery) Unique(unique bool) *ValidMessageQuery {
	vmq.unique = &unique
	return vmq
}
func (vmq *ValidMessageQuery) Order(o ...OrderFunc) *ValidMessageQuery {
	vmq.order = append(vmq.order, o...)
	return vmq
}
func (vmq *ValidMessageQuery) First(ctx context.Context) (*ValidMessage, error) {
	nodes, err := vmq.Limit(1).All(ctx)
	if err != nil {
		return nil, err
	}
	if len(nodes) == 0 {
		return nil, &NotFoundError{validmessage.Label}
	}
	return nodes[0], nil
}
func (vmq *ValidMessageQuery) FirstX(ctx context.Context) *ValidMessage {
	node, err := vmq.First(ctx)
	if err != nil && !IsNotFound(err) {
		panic(err)
	}
	return node
}
func (vmq *ValidMessageQuery) FirstID(ctx context.Context) (id int, err error) {
	var ids []int
	if ids, err = vmq.Limit(1).IDs(ctx); err != nil {
		return
	}
	if len(ids) == 0 {
		err = &NotFoundError{validmessage.Label}
		return
	}
	return ids[0], nil
}
func (vmq *ValidMessageQuery) FirstIDX(ctx context.Context) int {
	id, err := vmq.FirstID(ctx)
	if err != nil && !IsNotFound(err) {
		panic(err)
	}
	return id
}
func (vmq *ValidMessageQuery) Only(ctx context.Context) (*ValidMessage, error) {
	nodes, err := vmq.Limit(2).All(ctx)
	if err != nil {
		return nil, err
	}
	switch len(nodes) {
	case 1:
		return nodes[0], nil
	case 0:
		return nil, &NotFoundError{validmessage.Label}
	default:
		return nil, &NotSingularError{validmessage.Label}
	}
}
func (vmq *ValidMessageQuery) OnlyX(ctx context.Context) *ValidMessage {
	node, err := vmq.Only(ctx)
	if err != nil {
		panic(err)
	}
	return node
}
func (vmq *ValidMessageQuery) OnlyID(ctx context.Context) (id int, err error) {
	var ids []int
	if ids, err = vmq.Limit(2).IDs(ctx); err != nil {
		return
	}
	switch len(ids) {
	case 1:
		id = ids[0]
	case 0:
		err = &NotFoundError{validmessage.Label}
	default:
		err = &NotSingularError{validmessage.Label}
	}
	return
}
func (vmq *ValidMessageQuery) OnlyIDX(ctx context.Context) int {
	id, err := vmq.OnlyID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}
func (vmq *ValidMessageQuery) All(ctx context.Context) ([]*ValidMessage, error) {
	if err := vmq.prepareQuery(ctx); err != nil {
		return nil, err
	}
	return vmq.sqlAll(ctx)
}
func (vmq *ValidMessageQuery) AllX(ctx context.Context) []*ValidMessage {
	nodes, err := vmq.All(ctx)
	if err != nil {
		panic(err)
	}
	return nodes
}
func (vmq *ValidMessageQuery) IDs(ctx context.Context) ([]int, error) {
	var ids []int
	if err := vmq.Select(validmessage.FieldID).Scan(ctx, &ids); err != nil {
		return nil, err
	}
	return ids, nil
}
func (vmq *ValidMessageQuery) IDsX(ctx context.Context) []int {
	ids, err := vmq.IDs(ctx)
	if err != nil {
		panic(err)
	}
	return ids
}
func (vmq *ValidMessageQuery) Count(ctx context.Context) (int, error) {
	if err := vmq.prepareQuery(ctx); err != nil {
		return 0, err
	}
	return vmq.sqlCount(ctx)
}
func (vmq *ValidMessageQuery) CountX(ctx context.Context) int {
	count, err := vmq.Count(ctx)
	if err != nil {
		panic(err)
	}
	return count
}
func (vmq *ValidMessageQuery) Exist(ctx context.Context) (bool, error) {
	if err := vmq.prepareQuery(ctx); err != nil {
		return false, err
	}
	return vmq.sqlExist(ctx)
}
func (vmq *ValidMessageQuery) ExistX(ctx context.Context) bool {
	exist, err := vmq.Exist(ctx)
	if err != nil {
		panic(err)
	}
	return exist
}
func (vmq *ValidMessageQuery) Clone() *ValidMessageQuery {
	if vmq == nil {
		return nil
	}
	return &ValidMessageQuery{
		config:     vmq.config,
		limit:      vmq.limit,
		offset:     vmq.offset,
		order:      append([]OrderFunc{}, vmq.order...),
		predicates: append([]predicate.ValidMessage{}, vmq.predicates...),
		sql:  vmq.sql.Clone(),
		path: vmq.path,
	}
}
func (vmq *ValidMessageQuery) GroupBy(field string, fields ...string) *ValidMessageGroupBy {
	group := &ValidMessageGroupBy{config: vmq.config}
	group.fields = append([]string{field}, fields...)
	group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
		if err := vmq.prepareQuery(ctx); err != nil {
			return nil, err
		}
		return vmq.sqlQuery(ctx), nil
	}
	return group
}
func (vmq *ValidMessageQuery) Select(fields ...string) *ValidMessageSelect {
	vmq.fields = append(vmq.fields, fields...)
	return &ValidMessageSelect{ValidMessageQuery: vmq}
}
func (vmq *ValidMessageQuery) prepareQuery(ctx context.Context) error {
	for _, f := range vmq.fields {
		if !validmessage.ValidColumn(f) {
			return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
		}
	}
	if vmq.path != nil {
		prev, err := vmq.path(ctx)
		if err != nil {
			return err
		}
		vmq.sql = prev
	}
	return nil
}
func (vmq *ValidMessageQuery) sqlAll(ctx context.Context) ([]*ValidMessage, error) {
	var (
		nodes = []*ValidMessage{}
		_spec = vmq.querySpec()
	)
	_spec.ScanValues = func(columns []string) ([]interface{}, error) {
		node := &ValidMessage{config: vmq.config}
		nodes = append(nodes, node)
		return node.scanValues(columns)
	}
	_spec.Assign = func(columns []string, values []interface{}) error {
		if len(nodes) == 0 {
			return fmt.Errorf("ent: Assign called without calling ScanValues")
		}
		node := nodes[len(nodes)-1]
		return node.assignValues(columns, values)
	}
	if err := sqlgraph.QueryNodes(ctx, vmq.driver, _spec); err != nil {
		return nil, err
	}
	if len(nodes) == 0 {
		return nodes, nil
	}
	return nodes, nil
}
func (vmq *ValidMessageQuery) sqlCount(ctx context.Context) (int, error) {
	_spec := vmq.querySpec()
	return sqlgraph.CountNodes(ctx, vmq.driver, _spec)
}
func (vmq *ValidMessageQuery) sqlExist(ctx context.Context) (bool, error) {
	n, err := vmq.sqlCount(ctx)
	if err != nil {
		return false, fmt.Errorf("ent: check existence: %w", err)
	}
	return n > 0, nil
}
func (vmq *ValidMessageQuery) querySpec() *sqlgraph.QuerySpec {
	_spec := &sqlgraph.QuerySpec{
		Node: &sqlgraph.NodeSpec{
			Table:   validmessage.Table,
			Columns: validmessage.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: validmessage.FieldID,
			},
		},
		From:   vmq.sql,
		Unique: true,
	}
	if unique := vmq.unique; unique != nil {
		_spec.Unique = *unique
	}
	if fields := vmq.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, validmessage.FieldID)
		for i := range fields {
			if fields[i] != validmessage.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
			}
		}
	}
	if ps := vmq.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if limit := vmq.limit; limit != nil {
		_spec.Limit = *limit
	}
	if offset := vmq.offset; offset != nil {
		_spec.Offset = *offset
	}
	if ps := vmq.order; len(ps) > 0 {
		_spec.Order = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	return _spec
}
func (vmq *ValidMessageQuery) sqlQuery(ctx context.Context) *sql.Selector {
	builder := sql.Dialect(vmq.driver.Dialect())
	t1 := builder.Table(validmessage.Table)
	columns := vmq.fields
	if len(columns) == 0 {
		columns = validmessage.Columns
	}
	selector := builder.Select(t1.Columns(columns...)...).From(t1)
	if vmq.sql != nil {
		selector = vmq.sql
		selector.Select(selector.Columns(columns...)...)
	}
	for _, p := range vmq.predicates {
		p(selector)
	}
	for _, p := range vmq.order {
		p(selector)
	}
	if offset := vmq.offset; offset != nil {
		selector.Offset(*offset).Limit(math.MaxInt32)
	}
	if limit := vmq.limit; limit != nil {
		selector.Limit(*limit)
	}
	return selector
}
type ValidMessageGroupBy struct {
	config
	fields []string
	fns    []AggregateFunc
	sql  *sql.Selector
	path func(context.Context) (*sql.Selector, error)
}
func (vmgb *ValidMessageGroupBy) Aggregate(fns ...AggregateFunc) *ValidMessageGroupBy {
	vmgb.fns = append(vmgb.fns, fns...)
	return vmgb
}
func (vmgb *ValidMessageGroupBy) Scan(ctx context.Context, v interface{}) error {
	query, err := vmgb.path(ctx)
	if err != nil {
		return err
	}
	vmgb.sql = query
	return vmgb.sqlScan(ctx, v)
}
func (vmgb *ValidMessageGroupBy) ScanX(ctx context.Context, v interface{}) {
	if err := vmgb.Scan(ctx, v); err != nil {
		panic(err)
	}
}
func (vmgb *ValidMessageGroupBy) Strings(ctx context.Context) ([]string, error) {
	if len(vmgb.fields) > 1 {
		return nil, errors.New("ent: ValidMessageGroupBy.Strings is not achievable when grouping more than 1 field")
	}
	var v []string
	if err := vmgb.Scan(ctx, &v); err != nil {
		return nil, err
	}
	return v, nil
}
func (vmgb *ValidMessageGroupBy) StringsX(ctx context.Context) []string {
	v, err := vmgb.Strings(ctx)
	if err != nil {
		panic(err)
	}
	return v
}
func (vmgb *ValidMessageGroupBy) String(ctx context.Context) (_ string, err error) {
	var v []string
	if v, err = vmgb.Strings(ctx); err != nil {
		return
	}
	switch len(v) {
	case 1:
		return v[0], nil
	case 0:
		err = &NotFoundError{validmessage.Label}
	default:
		err = fmt.Errorf("ent: ValidMessageGroupBy.Strings returned %d results when one was expected", len(v))
	}
	return
}
func (vmgb *ValidMessageGroupBy) StringX(ctx context.Context) string {
	v, err := vmgb.String(ctx)
	if err != nil {
		panic(err)
	}
	return v
}
func (vmgb *ValidMessageGroupBy) Ints(ctx context.Context) ([]int, error) {
	if len(vmgb.fields) > 1 {
		return nil, errors.New("ent: ValidMessageGroupBy.Ints is not achievable when grouping more than 1 field")
	}
	var v []int
	if err := vmgb.Scan(ctx, &v); err != nil {
		return nil, err
	}
	return v, nil
}
func (vmgb *ValidMessageGroupBy) IntsX(ctx context.Context) []int {
	v, err := vmgb.Ints(ctx)
	if err != nil {
		panic(err)
	}
	return v
}