612 lines
17 KiB
Go
612 lines
17 KiB
Go
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
||
|
package ent
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql/driver"
|
||
|
"fmt"
|
||
|
"math"
|
||
|
"thesis/ent/key"
|
||
|
"thesis/ent/predicate"
|
||
|
"thesis/ent/validators"
|
||
|
|
||
|
"entgo.io/ent/dialect/sql"
|
||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
"entgo.io/ent/schema/field"
|
||
|
)
|
||
|
|
||
|
// ValidatorsQuery is the builder for querying Validators entities.
|
||
|
type ValidatorsQuery struct {
|
||
|
config
|
||
|
ctx *QueryContext
|
||
|
order []validators.OrderOption
|
||
|
inters []Interceptor
|
||
|
predicates []predicate.Validators
|
||
|
withKey *KeyQuery
|
||
|
withFKs bool
|
||
|
// intermediate query (i.e. traversal path).
|
||
|
sql *sql.Selector
|
||
|
path func(context.Context) (*sql.Selector, error)
|
||
|
}
|
||
|
|
||
|
// Where adds a new predicate for the ValidatorsQuery builder.
|
||
|
func (vq *ValidatorsQuery) Where(ps ...predicate.Validators) *ValidatorsQuery {
|
||
|
vq.predicates = append(vq.predicates, ps...)
|
||
|
return vq
|
||
|
}
|
||
|
|
||
|
// Limit the number of records to be returned by this query.
|
||
|
func (vq *ValidatorsQuery) Limit(limit int) *ValidatorsQuery {
|
||
|
vq.ctx.Limit = &limit
|
||
|
return vq
|
||
|
}
|
||
|
|
||
|
// Offset to start from.
|
||
|
func (vq *ValidatorsQuery) Offset(offset int) *ValidatorsQuery {
|
||
|
vq.ctx.Offset = &offset
|
||
|
return vq
|
||
|
}
|
||
|
|
||
|
// Unique configures the query builder to filter duplicate records on query.
|
||
|
// By default, unique is set to true, and can be disabled using this method.
|
||
|
func (vq *ValidatorsQuery) Unique(unique bool) *ValidatorsQuery {
|
||
|
vq.ctx.Unique = &unique
|
||
|
return vq
|
||
|
}
|
||
|
|
||
|
// Order specifies how the records should be ordered.
|
||
|
func (vq *ValidatorsQuery) Order(o ...validators.OrderOption) *ValidatorsQuery {
|
||
|
vq.order = append(vq.order, o...)
|
||
|
return vq
|
||
|
}
|
||
|
|
||
|
// QueryKey chains the current query on the "key" edge.
|
||
|
func (vq *ValidatorsQuery) QueryKey() *KeyQuery {
|
||
|
query := (&KeyClient{config: vq.config}).Query()
|
||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||
|
if err := vq.prepareQuery(ctx); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
selector := vq.sqlQuery(ctx)
|
||
|
if err := selector.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(validators.Table, validators.FieldID, selector),
|
||
|
sqlgraph.To(key.Table, key.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.O2M, false, validators.KeyTable, validators.KeyColumn),
|
||
|
)
|
||
|
fromU = sqlgraph.SetNeighbors(vq.driver.Dialect(), step)
|
||
|
return fromU, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// First returns the first Validators entity from the query.
|
||
|
// Returns a *NotFoundError when no Validators was found.
|
||
|
func (vq *ValidatorsQuery) First(ctx context.Context) (*Validators, error) {
|
||
|
nodes, err := vq.Limit(1).All(setContextOp(ctx, vq.ctx, "First"))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(nodes) == 0 {
|
||
|
return nil, &NotFoundError{validators.Label}
|
||
|
}
|
||
|
return nodes[0], nil
|
||
|
}
|
||
|
|
||
|
// FirstX is like First, but panics if an error occurs.
|
||
|
func (vq *ValidatorsQuery) FirstX(ctx context.Context) *Validators {
|
||
|
node, err := vq.First(ctx)
|
||
|
if err != nil && !IsNotFound(err) {
|
||
|
panic(err)
|
||
|
}
|
||
|
return node
|
||
|
}
|
||
|
|
||
|
// FirstID returns the first Validators ID from the query.
|
||
|
// Returns a *NotFoundError when no Validators ID was found.
|
||
|
func (vq *ValidatorsQuery) FirstID(ctx context.Context) (id int, err error) {
|
||
|
var ids []int
|
||
|
if ids, err = vq.Limit(1).IDs(setContextOp(ctx, vq.ctx, "FirstID")); err != nil {
|
||
|
return
|
||
|
}
|
||
|
if len(ids) == 0 {
|
||
|
err = &NotFoundError{validators.Label}
|
||
|
return
|
||
|
}
|
||
|
return ids[0], nil
|
||
|
}
|
||
|
|
||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||
|
func (vq *ValidatorsQuery) FirstIDX(ctx context.Context) int {
|
||
|
id, err := vq.FirstID(ctx)
|
||
|
if err != nil && !IsNotFound(err) {
|
||
|
panic(err)
|
||
|
}
|
||
|
return id
|
||
|
}
|
||
|
|
||
|
// Only returns a single Validators entity found by the query, ensuring it only returns one.
|
||
|
// Returns a *NotSingularError when more than one Validators entity is found.
|
||
|
// Returns a *NotFoundError when no Validators entities are found.
|
||
|
func (vq *ValidatorsQuery) Only(ctx context.Context) (*Validators, error) {
|
||
|
nodes, err := vq.Limit(2).All(setContextOp(ctx, vq.ctx, "Only"))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
switch len(nodes) {
|
||
|
case 1:
|
||
|
return nodes[0], nil
|
||
|
case 0:
|
||
|
return nil, &NotFoundError{validators.Label}
|
||
|
default:
|
||
|
return nil, &NotSingularError{validators.Label}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// OnlyX is like Only, but panics if an error occurs.
|
||
|
func (vq *ValidatorsQuery) OnlyX(ctx context.Context) *Validators {
|
||
|
node, err := vq.Only(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return node
|
||
|
}
|
||
|
|
||
|
// OnlyID is like Only, but returns the only Validators ID in the query.
|
||
|
// Returns a *NotSingularError when more than one Validators ID is found.
|
||
|
// Returns a *NotFoundError when no entities are found.
|
||
|
func (vq *ValidatorsQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||
|
var ids []int
|
||
|
if ids, err = vq.Limit(2).IDs(setContextOp(ctx, vq.ctx, "OnlyID")); err != nil {
|
||
|
return
|
||
|
}
|
||
|
switch len(ids) {
|
||
|
case 1:
|
||
|
id = ids[0]
|
||
|
case 0:
|
||
|
err = &NotFoundError{validators.Label}
|
||
|
default:
|
||
|
err = &NotSingularError{validators.Label}
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||
|
func (vq *ValidatorsQuery) OnlyIDX(ctx context.Context) int {
|
||
|
id, err := vq.OnlyID(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return id
|
||
|
}
|
||
|
|
||
|
// All executes the query and returns a list of ValidatorsSlice.
|
||
|
func (vq *ValidatorsQuery) All(ctx context.Context) ([]*Validators, error) {
|
||
|
ctx = setContextOp(ctx, vq.ctx, "All")
|
||
|
if err := vq.prepareQuery(ctx); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
qr := querierAll[[]*Validators, *ValidatorsQuery]()
|
||
|
return withInterceptors[[]*Validators](ctx, vq, qr, vq.inters)
|
||
|
}
|
||
|
|
||
|
// AllX is like All, but panics if an error occurs.
|
||
|
func (vq *ValidatorsQuery) AllX(ctx context.Context) []*Validators {
|
||
|
nodes, err := vq.All(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return nodes
|
||
|
}
|
||
|
|
||
|
// IDs executes the query and returns a list of Validators IDs.
|
||
|
func (vq *ValidatorsQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||
|
if vq.ctx.Unique == nil && vq.path != nil {
|
||
|
vq.Unique(true)
|
||
|
}
|
||
|
ctx = setContextOp(ctx, vq.ctx, "IDs")
|
||
|
if err = vq.Select(validators.FieldID).Scan(ctx, &ids); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return ids, nil
|
||
|
}
|
||
|
|
||
|
// IDsX is like IDs, but panics if an error occurs.
|
||
|
func (vq *ValidatorsQuery) IDsX(ctx context.Context) []int {
|
||
|
ids, err := vq.IDs(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return ids
|
||
|
}
|
||
|
|
||
|
// Count returns the count of the given query.
|
||
|
func (vq *ValidatorsQuery) Count(ctx context.Context) (int, error) {
|
||
|
ctx = setContextOp(ctx, vq.ctx, "Count")
|
||
|
if err := vq.prepareQuery(ctx); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
return withInterceptors[int](ctx, vq, querierCount[*ValidatorsQuery](), vq.inters)
|
||
|
}
|
||
|
|
||
|
// CountX is like Count, but panics if an error occurs.
|
||
|
func (vq *ValidatorsQuery) CountX(ctx context.Context) int {
|
||
|
count, err := vq.Count(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return count
|
||
|
}
|
||
|
|
||
|
// Exist returns true if the query has elements in the graph.
|
||
|
func (vq *ValidatorsQuery) Exist(ctx context.Context) (bool, error) {
|
||
|
ctx = setContextOp(ctx, vq.ctx, "Exist")
|
||
|
switch _, err := vq.FirstID(ctx); {
|
||
|
case IsNotFound(err):
|
||
|
return false, nil
|
||
|
case err != nil:
|
||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||
|
default:
|
||
|
return true, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ExistX is like Exist, but panics if an error occurs.
|
||
|
func (vq *ValidatorsQuery) ExistX(ctx context.Context) bool {
|
||
|
exist, err := vq.Exist(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return exist
|
||
|
}
|
||
|
|
||
|
// Clone returns a duplicate of the ValidatorsQuery builder, including all associated steps. It can be
|
||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||
|
func (vq *ValidatorsQuery) Clone() *ValidatorsQuery {
|
||
|
if vq == nil {
|
||
|
return nil
|
||
|
}
|
||
|
return &ValidatorsQuery{
|
||
|
config: vq.config,
|
||
|
ctx: vq.ctx.Clone(),
|
||
|
order: append([]validators.OrderOption{}, vq.order...),
|
||
|
inters: append([]Interceptor{}, vq.inters...),
|
||
|
predicates: append([]predicate.Validators{}, vq.predicates...),
|
||
|
withKey: vq.withKey.Clone(),
|
||
|
// clone intermediate query.
|
||
|
sql: vq.sql.Clone(),
|
||
|
path: vq.path,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithKey tells the query-builder to eager-load the nodes that are connected to
|
||
|
// the "key" edge. The optional arguments are used to configure the query builder of the edge.
|
||
|
func (vq *ValidatorsQuery) WithKey(opts ...func(*KeyQuery)) *ValidatorsQuery {
|
||
|
query := (&KeyClient{config: vq.config}).Query()
|
||
|
for _, opt := range opts {
|
||
|
opt(query)
|
||
|
}
|
||
|
vq.withKey = query
|
||
|
return vq
|
||
|
}
|
||
|
|
||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||
|
//
|
||
|
// Example:
|
||
|
//
|
||
|
// var v []struct {
|
||
|
// Facilitator string `json:"facilitator,omitempty"`
|
||
|
// Count int `json:"count,omitempty"`
|
||
|
// }
|
||
|
//
|
||
|
// client.Validators.Query().
|
||
|
// GroupBy(validators.FieldFacilitator).
|
||
|
// Aggregate(ent.Count()).
|
||
|
// Scan(ctx, &v)
|
||
|
func (vq *ValidatorsQuery) GroupBy(field string, fields ...string) *ValidatorsGroupBy {
|
||
|
vq.ctx.Fields = append([]string{field}, fields...)
|
||
|
grbuild := &ValidatorsGroupBy{build: vq}
|
||
|
grbuild.flds = &vq.ctx.Fields
|
||
|
grbuild.label = validators.Label
|
||
|
grbuild.scan = grbuild.Scan
|
||
|
return grbuild
|
||
|
}
|
||
|
|
||
|
// Select allows the selection one or more fields/columns for the given query,
|
||
|
// instead of selecting all fields in the entity.
|
||
|
//
|
||
|
// Example:
|
||
|
//
|
||
|
// var v []struct {
|
||
|
// Facilitator string `json:"facilitator,omitempty"`
|
||
|
// }
|
||
|
//
|
||
|
// client.Validators.Query().
|
||
|
// Select(validators.FieldFacilitator).
|
||
|
// Scan(ctx, &v)
|
||
|
func (vq *ValidatorsQuery) Select(fields ...string) *ValidatorsSelect {
|
||
|
vq.ctx.Fields = append(vq.ctx.Fields, fields...)
|
||
|
sbuild := &ValidatorsSelect{ValidatorsQuery: vq}
|
||
|
sbuild.label = validators.Label
|
||
|
sbuild.flds, sbuild.scan = &vq.ctx.Fields, sbuild.Scan
|
||
|
return sbuild
|
||
|
}
|
||
|
|
||
|
// Aggregate returns a ValidatorsSelect configured with the given aggregations.
|
||
|
func (vq *ValidatorsQuery) Aggregate(fns ...AggregateFunc) *ValidatorsSelect {
|
||
|
return vq.Select().Aggregate(fns...)
|
||
|
}
|
||
|
|
||
|
func (vq *ValidatorsQuery) prepareQuery(ctx context.Context) error {
|
||
|
for _, inter := range vq.inters {
|
||
|
if inter == nil {
|
||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||
|
}
|
||
|
if trv, ok := inter.(Traverser); ok {
|
||
|
if err := trv.Traverse(ctx, vq); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for _, f := range vq.ctx.Fields {
|
||
|
if !validators.ValidColumn(f) {
|
||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
}
|
||
|
}
|
||
|
if vq.path != nil {
|
||
|
prev, err := vq.path(ctx)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
vq.sql = prev
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (vq *ValidatorsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Validators, error) {
|
||
|
var (
|
||
|
nodes = []*Validators{}
|
||
|
withFKs = vq.withFKs
|
||
|
_spec = vq.querySpec()
|
||
|
loadedTypes = [1]bool{
|
||
|
vq.withKey != nil,
|
||
|
}
|
||
|
)
|
||
|
if withFKs {
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, validators.ForeignKeys...)
|
||
|
}
|
||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||
|
return (*Validators).scanValues(nil, columns)
|
||
|
}
|
||
|
_spec.Assign = func(columns []string, values []any) error {
|
||
|
node := &Validators{config: vq.config}
|
||
|
nodes = append(nodes, node)
|
||
|
node.Edges.loadedTypes = loadedTypes
|
||
|
return node.assignValues(columns, values)
|
||
|
}
|
||
|
for i := range hooks {
|
||
|
hooks[i](ctx, _spec)
|
||
|
}
|
||
|
if err := sqlgraph.QueryNodes(ctx, vq.driver, _spec); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(nodes) == 0 {
|
||
|
return nodes, nil
|
||
|
}
|
||
|
if query := vq.withKey; query != nil {
|
||
|
if err := vq.loadKey(ctx, query, nodes,
|
||
|
func(n *Validators) { n.Edges.Key = []*Key{} },
|
||
|
func(n *Validators, e *Key) { n.Edges.Key = append(n.Edges.Key, e) }); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
return nodes, nil
|
||
|
}
|
||
|
|
||
|
func (vq *ValidatorsQuery) loadKey(ctx context.Context, query *KeyQuery, nodes []*Validators, init func(*Validators), assign func(*Validators, *Key)) error {
|
||
|
fks := make([]driver.Value, 0, len(nodes))
|
||
|
nodeids := make(map[int]*Validators)
|
||
|
for i := range nodes {
|
||
|
fks = append(fks, nodes[i].ID)
|
||
|
nodeids[nodes[i].ID] = nodes[i]
|
||
|
if init != nil {
|
||
|
init(nodes[i])
|
||
|
}
|
||
|
}
|
||
|
query.withFKs = true
|
||
|
query.Where(predicate.Key(func(s *sql.Selector) {
|
||
|
s.Where(sql.InValues(s.C(validators.KeyColumn), fks...))
|
||
|
}))
|
||
|
neighbors, err := query.All(ctx)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
for _, n := range neighbors {
|
||
|
fk := n.validators_key
|
||
|
if fk == nil {
|
||
|
return fmt.Errorf(`foreign-key "validators_key" is nil for node %v`, n.ID)
|
||
|
}
|
||
|
node, ok := nodeids[*fk]
|
||
|
if !ok {
|
||
|
return fmt.Errorf(`unexpected referenced foreign-key "validators_key" returned %v for node %v`, *fk, n.ID)
|
||
|
}
|
||
|
assign(node, n)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (vq *ValidatorsQuery) sqlCount(ctx context.Context) (int, error) {
|
||
|
_spec := vq.querySpec()
|
||
|
_spec.Node.Columns = vq.ctx.Fields
|
||
|
if len(vq.ctx.Fields) > 0 {
|
||
|
_spec.Unique = vq.ctx.Unique != nil && *vq.ctx.Unique
|
||
|
}
|
||
|
return sqlgraph.CountNodes(ctx, vq.driver, _spec)
|
||
|
}
|
||
|
|
||
|
func (vq *ValidatorsQuery) querySpec() *sqlgraph.QuerySpec {
|
||
|
_spec := sqlgraph.NewQuerySpec(validators.Table, validators.Columns, sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt))
|
||
|
_spec.From = vq.sql
|
||
|
if unique := vq.ctx.Unique; unique != nil {
|
||
|
_spec.Unique = *unique
|
||
|
} else if vq.path != nil {
|
||
|
_spec.Unique = true
|
||
|
}
|
||
|
if fields := vq.ctx.Fields; len(fields) > 0 {
|
||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, validators.FieldID)
|
||
|
for i := range fields {
|
||
|
if fields[i] != validators.FieldID {
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if ps := vq.predicates; len(ps) > 0 {
|
||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if limit := vq.ctx.Limit; limit != nil {
|
||
|
_spec.Limit = *limit
|
||
|
}
|
||
|
if offset := vq.ctx.Offset; offset != nil {
|
||
|
_spec.Offset = *offset
|
||
|
}
|
||
|
if ps := vq.order; len(ps) > 0 {
|
||
|
_spec.Order = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return _spec
|
||
|
}
|
||
|
|
||
|
func (vq *ValidatorsQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||
|
builder := sql.Dialect(vq.driver.Dialect())
|
||
|
t1 := builder.Table(validators.Table)
|
||
|
columns := vq.ctx.Fields
|
||
|
if len(columns) == 0 {
|
||
|
columns = validators.Columns
|
||
|
}
|
||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||
|
if vq.sql != nil {
|
||
|
selector = vq.sql
|
||
|
selector.Select(selector.Columns(columns...)...)
|
||
|
}
|
||
|
if vq.ctx.Unique != nil && *vq.ctx.Unique {
|
||
|
selector.Distinct()
|
||
|
}
|
||
|
for _, p := range vq.predicates {
|
||
|
p(selector)
|
||
|
}
|
||
|
for _, p := range vq.order {
|
||
|
p(selector)
|
||
|
}
|
||
|
if offset := vq.ctx.Offset; offset != nil {
|
||
|
// limit is mandatory for offset clause. We start
|
||
|
// with default value, and override it below if needed.
|
||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||
|
}
|
||
|
if limit := vq.ctx.Limit; limit != nil {
|
||
|
selector.Limit(*limit)
|
||
|
}
|
||
|
return selector
|
||
|
}
|
||
|
|
||
|
// ValidatorsGroupBy is the group-by builder for Validators entities.
|
||
|
type ValidatorsGroupBy struct {
|
||
|
selector
|
||
|
build *ValidatorsQuery
|
||
|
}
|
||
|
|
||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||
|
func (vgb *ValidatorsGroupBy) Aggregate(fns ...AggregateFunc) *ValidatorsGroupBy {
|
||
|
vgb.fns = append(vgb.fns, fns...)
|
||
|
return vgb
|
||
|
}
|
||
|
|
||
|
// Scan applies the selector query and scans the result into the given value.
|
||
|
func (vgb *ValidatorsGroupBy) Scan(ctx context.Context, v any) error {
|
||
|
ctx = setContextOp(ctx, vgb.build.ctx, "GroupBy")
|
||
|
if err := vgb.build.prepareQuery(ctx); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return scanWithInterceptors[*ValidatorsQuery, *ValidatorsGroupBy](ctx, vgb.build, vgb, vgb.build.inters, v)
|
||
|
}
|
||
|
|
||
|
func (vgb *ValidatorsGroupBy) sqlScan(ctx context.Context, root *ValidatorsQuery, v any) error {
|
||
|
selector := root.sqlQuery(ctx).Select()
|
||
|
aggregation := make([]string, 0, len(vgb.fns))
|
||
|
for _, fn := range vgb.fns {
|
||
|
aggregation = append(aggregation, fn(selector))
|
||
|
}
|
||
|
if len(selector.SelectedColumns()) == 0 {
|
||
|
columns := make([]string, 0, len(*vgb.flds)+len(vgb.fns))
|
||
|
for _, f := range *vgb.flds {
|
||
|
columns = append(columns, selector.C(f))
|
||
|
}
|
||
|
columns = append(columns, aggregation...)
|
||
|
selector.Select(columns...)
|
||
|
}
|
||
|
selector.GroupBy(selector.Columns(*vgb.flds...)...)
|
||
|
if err := selector.Err(); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
rows := &sql.Rows{}
|
||
|
query, args := selector.Query()
|
||
|
if err := vgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
return sql.ScanSlice(rows, v)
|
||
|
}
|
||
|
|
||
|
// ValidatorsSelect is the builder for selecting fields of Validators entities.
|
||
|
type ValidatorsSelect struct {
|
||
|
*ValidatorsQuery
|
||
|
selector
|
||
|
}
|
||
|
|
||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||
|
func (vs *ValidatorsSelect) Aggregate(fns ...AggregateFunc) *ValidatorsSelect {
|
||
|
vs.fns = append(vs.fns, fns...)
|
||
|
return vs
|
||
|
}
|
||
|
|
||
|
// Scan applies the selector query and scans the result into the given value.
|
||
|
func (vs *ValidatorsSelect) Scan(ctx context.Context, v any) error {
|
||
|
ctx = setContextOp(ctx, vs.ctx, "Select")
|
||
|
if err := vs.prepareQuery(ctx); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return scanWithInterceptors[*ValidatorsQuery, *ValidatorsSelect](ctx, vs.ValidatorsQuery, vs, vs.inters, v)
|
||
|
}
|
||
|
|
||
|
func (vs *ValidatorsSelect) sqlScan(ctx context.Context, root *ValidatorsQuery, v any) error {
|
||
|
selector := root.sqlQuery(ctx)
|
||
|
aggregation := make([]string, 0, len(vs.fns))
|
||
|
for _, fn := range vs.fns {
|
||
|
aggregation = append(aggregation, fn(selector))
|
||
|
}
|
||
|
switch n := len(*vs.selector.flds); {
|
||
|
case n == 0 && len(aggregation) > 0:
|
||
|
selector.Select(aggregation...)
|
||
|
case n != 0 && len(aggregation) > 0:
|
||
|
selector.AppendSelect(aggregation...)
|
||
|
}
|
||
|
rows := &sql.Rows{}
|
||
|
query, args := selector.Query()
|
||
|
if err := vs.driver.Query(ctx, query, args, rows); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
return sql.ScanSlice(rows, v)
|
||
|
}
|