/ ent / subscription_query.go
subscription_query.go
  1  // Code generated by ent, DO NOT EDIT.
  2  
  3  package ent
  4  
  5  import (
  6  	"context"
  7  	"fmt"
  8  	"math"
  9  
 10  	"entgo.io/ent/dialect/sql"
 11  	"entgo.io/ent/dialect/sql/sqlgraph"
 12  	"entgo.io/ent/schema/field"
 13  	"github.com/google/uuid"
 14  	"github.com/mrusme/journalist/ent/feed"
 15  	"github.com/mrusme/journalist/ent/predicate"
 16  	"github.com/mrusme/journalist/ent/subscription"
 17  	"github.com/mrusme/journalist/ent/user"
 18  )
 19  
 20  // SubscriptionQuery is the builder for querying Subscription entities.
 21  type SubscriptionQuery struct {
 22  	config
 23  	ctx        *QueryContext
 24  	order      []subscription.OrderOption
 25  	inters     []Interceptor
 26  	predicates []predicate.Subscription
 27  	withUser   *UserQuery
 28  	withFeed   *FeedQuery
 29  	// intermediate query (i.e. traversal path).
 30  	sql  *sql.Selector
 31  	path func(context.Context) (*sql.Selector, error)
 32  }
 33  
 34  // Where adds a new predicate for the SubscriptionQuery builder.
 35  func (sq *SubscriptionQuery) Where(ps ...predicate.Subscription) *SubscriptionQuery {
 36  	sq.predicates = append(sq.predicates, ps...)
 37  	return sq
 38  }
 39  
 40  // Limit the number of records to be returned by this query.
 41  func (sq *SubscriptionQuery) Limit(limit int) *SubscriptionQuery {
 42  	sq.ctx.Limit = &limit
 43  	return sq
 44  }
 45  
 46  // Offset to start from.
 47  func (sq *SubscriptionQuery) Offset(offset int) *SubscriptionQuery {
 48  	sq.ctx.Offset = &offset
 49  	return sq
 50  }
 51  
 52  // Unique configures the query builder to filter duplicate records on query.
 53  // By default, unique is set to true, and can be disabled using this method.
 54  func (sq *SubscriptionQuery) Unique(unique bool) *SubscriptionQuery {
 55  	sq.ctx.Unique = &unique
 56  	return sq
 57  }
 58  
 59  // Order specifies how the records should be ordered.
 60  func (sq *SubscriptionQuery) Order(o ...subscription.OrderOption) *SubscriptionQuery {
 61  	sq.order = append(sq.order, o...)
 62  	return sq
 63  }
 64  
 65  // QueryUser chains the current query on the "user" edge.
 66  func (sq *SubscriptionQuery) QueryUser() *UserQuery {
 67  	query := (&UserClient{config: sq.config}).Query()
 68  	query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
 69  		if err := sq.prepareQuery(ctx); err != nil {
 70  			return nil, err
 71  		}
 72  		selector := sq.sqlQuery(ctx)
 73  		if err := selector.Err(); err != nil {
 74  			return nil, err
 75  		}
 76  		step := sqlgraph.NewStep(
 77  			sqlgraph.From(subscription.Table, subscription.FieldID, selector),
 78  			sqlgraph.To(user.Table, user.FieldID),
 79  			sqlgraph.Edge(sqlgraph.M2O, false, subscription.UserTable, subscription.UserColumn),
 80  		)
 81  		fromU = sqlgraph.SetNeighbors(sq.driver.Dialect(), step)
 82  		return fromU, nil
 83  	}
 84  	return query
 85  }
 86  
 87  // QueryFeed chains the current query on the "feed" edge.
 88  func (sq *SubscriptionQuery) QueryFeed() *FeedQuery {
 89  	query := (&FeedClient{config: sq.config}).Query()
 90  	query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
 91  		if err := sq.prepareQuery(ctx); err != nil {
 92  			return nil, err
 93  		}
 94  		selector := sq.sqlQuery(ctx)
 95  		if err := selector.Err(); err != nil {
 96  			return nil, err
 97  		}
 98  		step := sqlgraph.NewStep(
 99  			sqlgraph.From(subscription.Table, subscription.FieldID, selector),
100  			sqlgraph.To(feed.Table, feed.FieldID),
101  			sqlgraph.Edge(sqlgraph.M2O, false, subscription.FeedTable, subscription.FeedColumn),
102  		)
103  		fromU = sqlgraph.SetNeighbors(sq.driver.Dialect(), step)
104  		return fromU, nil
105  	}
106  	return query
107  }
108  
109  // First returns the first Subscription entity from the query.
110  // Returns a *NotFoundError when no Subscription was found.
111  func (sq *SubscriptionQuery) First(ctx context.Context) (*Subscription, error) {
112  	nodes, err := sq.Limit(1).All(setContextOp(ctx, sq.ctx, "First"))
113  	if err != nil {
114  		return nil, err
115  	}
116  	if len(nodes) == 0 {
117  		return nil, &NotFoundError{subscription.Label}
118  	}
119  	return nodes[0], nil
120  }
121  
122  // FirstX is like First, but panics if an error occurs.
123  func (sq *SubscriptionQuery) FirstX(ctx context.Context) *Subscription {
124  	node, err := sq.First(ctx)
125  	if err != nil && !IsNotFound(err) {
126  		panic(err)
127  	}
128  	return node
129  }
130  
131  // FirstID returns the first Subscription ID from the query.
132  // Returns a *NotFoundError when no Subscription ID was found.
133  func (sq *SubscriptionQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
134  	var ids []uuid.UUID
135  	if ids, err = sq.Limit(1).IDs(setContextOp(ctx, sq.ctx, "FirstID")); err != nil {
136  		return
137  	}
138  	if len(ids) == 0 {
139  		err = &NotFoundError{subscription.Label}
140  		return
141  	}
142  	return ids[0], nil
143  }
144  
145  // FirstIDX is like FirstID, but panics if an error occurs.
146  func (sq *SubscriptionQuery) FirstIDX(ctx context.Context) uuid.UUID {
147  	id, err := sq.FirstID(ctx)
148  	if err != nil && !IsNotFound(err) {
149  		panic(err)
150  	}
151  	return id
152  }
153  
154  // Only returns a single Subscription entity found by the query, ensuring it only returns one.
155  // Returns a *NotSingularError when more than one Subscription entity is found.
156  // Returns a *NotFoundError when no Subscription entities are found.
157  func (sq *SubscriptionQuery) Only(ctx context.Context) (*Subscription, error) {
158  	nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, "Only"))
159  	if err != nil {
160  		return nil, err
161  	}
162  	switch len(nodes) {
163  	case 1:
164  		return nodes[0], nil
165  	case 0:
166  		return nil, &NotFoundError{subscription.Label}
167  	default:
168  		return nil, &NotSingularError{subscription.Label}
169  	}
170  }
171  
172  // OnlyX is like Only, but panics if an error occurs.
173  func (sq *SubscriptionQuery) OnlyX(ctx context.Context) *Subscription {
174  	node, err := sq.Only(ctx)
175  	if err != nil {
176  		panic(err)
177  	}
178  	return node
179  }
180  
181  // OnlyID is like Only, but returns the only Subscription ID in the query.
182  // Returns a *NotSingularError when more than one Subscription ID is found.
183  // Returns a *NotFoundError when no entities are found.
184  func (sq *SubscriptionQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
185  	var ids []uuid.UUID
186  	if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil {
187  		return
188  	}
189  	switch len(ids) {
190  	case 1:
191  		id = ids[0]
192  	case 0:
193  		err = &NotFoundError{subscription.Label}
194  	default:
195  		err = &NotSingularError{subscription.Label}
196  	}
197  	return
198  }
199  
200  // OnlyIDX is like OnlyID, but panics if an error occurs.
201  func (sq *SubscriptionQuery) OnlyIDX(ctx context.Context) uuid.UUID {
202  	id, err := sq.OnlyID(ctx)
203  	if err != nil {
204  		panic(err)
205  	}
206  	return id
207  }
208  
209  // All executes the query and returns a list of Subscriptions.
210  func (sq *SubscriptionQuery) All(ctx context.Context) ([]*Subscription, error) {
211  	ctx = setContextOp(ctx, sq.ctx, "All")
212  	if err := sq.prepareQuery(ctx); err != nil {
213  		return nil, err
214  	}
215  	qr := querierAll[[]*Subscription, *SubscriptionQuery]()
216  	return withInterceptors[[]*Subscription](ctx, sq, qr, sq.inters)
217  }
218  
219  // AllX is like All, but panics if an error occurs.
220  func (sq *SubscriptionQuery) AllX(ctx context.Context) []*Subscription {
221  	nodes, err := sq.All(ctx)
222  	if err != nil {
223  		panic(err)
224  	}
225  	return nodes
226  }
227  
228  // IDs executes the query and returns a list of Subscription IDs.
229  func (sq *SubscriptionQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
230  	if sq.ctx.Unique == nil && sq.path != nil {
231  		sq.Unique(true)
232  	}
233  	ctx = setContextOp(ctx, sq.ctx, "IDs")
234  	if err = sq.Select(subscription.FieldID).Scan(ctx, &ids); err != nil {
235  		return nil, err
236  	}
237  	return ids, nil
238  }
239  
240  // IDsX is like IDs, but panics if an error occurs.
241  func (sq *SubscriptionQuery) IDsX(ctx context.Context) []uuid.UUID {
242  	ids, err := sq.IDs(ctx)
243  	if err != nil {
244  		panic(err)
245  	}
246  	return ids
247  }
248  
249  // Count returns the count of the given query.
250  func (sq *SubscriptionQuery) Count(ctx context.Context) (int, error) {
251  	ctx = setContextOp(ctx, sq.ctx, "Count")
252  	if err := sq.prepareQuery(ctx); err != nil {
253  		return 0, err
254  	}
255  	return withInterceptors[int](ctx, sq, querierCount[*SubscriptionQuery](), sq.inters)
256  }
257  
258  // CountX is like Count, but panics if an error occurs.
259  func (sq *SubscriptionQuery) CountX(ctx context.Context) int {
260  	count, err := sq.Count(ctx)
261  	if err != nil {
262  		panic(err)
263  	}
264  	return count
265  }
266  
267  // Exist returns true if the query has elements in the graph.
268  func (sq *SubscriptionQuery) Exist(ctx context.Context) (bool, error) {
269  	ctx = setContextOp(ctx, sq.ctx, "Exist")
270  	switch _, err := sq.FirstID(ctx); {
271  	case IsNotFound(err):
272  		return false, nil
273  	case err != nil:
274  		return false, fmt.Errorf("ent: check existence: %w", err)
275  	default:
276  		return true, nil
277  	}
278  }
279  
280  // ExistX is like Exist, but panics if an error occurs.
281  func (sq *SubscriptionQuery) ExistX(ctx context.Context) bool {
282  	exist, err := sq.Exist(ctx)
283  	if err != nil {
284  		panic(err)
285  	}
286  	return exist
287  }
288  
289  // Clone returns a duplicate of the SubscriptionQuery builder, including all associated steps. It can be
290  // used to prepare common query builders and use them differently after the clone is made.
291  func (sq *SubscriptionQuery) Clone() *SubscriptionQuery {
292  	if sq == nil {
293  		return nil
294  	}
295  	return &SubscriptionQuery{
296  		config:     sq.config,
297  		ctx:        sq.ctx.Clone(),
298  		order:      append([]subscription.OrderOption{}, sq.order...),
299  		inters:     append([]Interceptor{}, sq.inters...),
300  		predicates: append([]predicate.Subscription{}, sq.predicates...),
301  		withUser:   sq.withUser.Clone(),
302  		withFeed:   sq.withFeed.Clone(),
303  		// clone intermediate query.
304  		sql:  sq.sql.Clone(),
305  		path: sq.path,
306  	}
307  }
308  
309  // WithUser tells the query-builder to eager-load the nodes that are connected to
310  // the "user" edge. The optional arguments are used to configure the query builder of the edge.
311  func (sq *SubscriptionQuery) WithUser(opts ...func(*UserQuery)) *SubscriptionQuery {
312  	query := (&UserClient{config: sq.config}).Query()
313  	for _, opt := range opts {
314  		opt(query)
315  	}
316  	sq.withUser = query
317  	return sq
318  }
319  
320  // WithFeed tells the query-builder to eager-load the nodes that are connected to
321  // the "feed" edge. The optional arguments are used to configure the query builder of the edge.
322  func (sq *SubscriptionQuery) WithFeed(opts ...func(*FeedQuery)) *SubscriptionQuery {
323  	query := (&FeedClient{config: sq.config}).Query()
324  	for _, opt := range opts {
325  		opt(query)
326  	}
327  	sq.withFeed = query
328  	return sq
329  }
330  
331  // GroupBy is used to group vertices by one or more fields/columns.
332  // It is often used with aggregate functions, like: count, max, mean, min, sum.
333  //
334  // Example:
335  //
336  //	var v []struct {
337  //		UserID uuid.UUID `json:"user_id,omitempty"`
338  //		Count int `json:"count,omitempty"`
339  //	}
340  //
341  //	client.Subscription.Query().
342  //		GroupBy(subscription.FieldUserID).
343  //		Aggregate(ent.Count()).
344  //		Scan(ctx, &v)
345  func (sq *SubscriptionQuery) GroupBy(field string, fields ...string) *SubscriptionGroupBy {
346  	sq.ctx.Fields = append([]string{field}, fields...)
347  	grbuild := &SubscriptionGroupBy{build: sq}
348  	grbuild.flds = &sq.ctx.Fields
349  	grbuild.label = subscription.Label
350  	grbuild.scan = grbuild.Scan
351  	return grbuild
352  }
353  
354  // Select allows the selection one or more fields/columns for the given query,
355  // instead of selecting all fields in the entity.
356  //
357  // Example:
358  //
359  //	var v []struct {
360  //		UserID uuid.UUID `json:"user_id,omitempty"`
361  //	}
362  //
363  //	client.Subscription.Query().
364  //		Select(subscription.FieldUserID).
365  //		Scan(ctx, &v)
366  func (sq *SubscriptionQuery) Select(fields ...string) *SubscriptionSelect {
367  	sq.ctx.Fields = append(sq.ctx.Fields, fields...)
368  	sbuild := &SubscriptionSelect{SubscriptionQuery: sq}
369  	sbuild.label = subscription.Label
370  	sbuild.flds, sbuild.scan = &sq.ctx.Fields, sbuild.Scan
371  	return sbuild
372  }
373  
374  // Aggregate returns a SubscriptionSelect configured with the given aggregations.
375  func (sq *SubscriptionQuery) Aggregate(fns ...AggregateFunc) *SubscriptionSelect {
376  	return sq.Select().Aggregate(fns...)
377  }
378  
379  func (sq *SubscriptionQuery) prepareQuery(ctx context.Context) error {
380  	for _, inter := range sq.inters {
381  		if inter == nil {
382  			return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
383  		}
384  		if trv, ok := inter.(Traverser); ok {
385  			if err := trv.Traverse(ctx, sq); err != nil {
386  				return err
387  			}
388  		}
389  	}
390  	for _, f := range sq.ctx.Fields {
391  		if !subscription.ValidColumn(f) {
392  			return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
393  		}
394  	}
395  	if sq.path != nil {
396  		prev, err := sq.path(ctx)
397  		if err != nil {
398  			return err
399  		}
400  		sq.sql = prev
401  	}
402  	return nil
403  }
404  
405  func (sq *SubscriptionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Subscription, error) {
406  	var (
407  		nodes       = []*Subscription{}
408  		_spec       = sq.querySpec()
409  		loadedTypes = [2]bool{
410  			sq.withUser != nil,
411  			sq.withFeed != nil,
412  		}
413  	)
414  	_spec.ScanValues = func(columns []string) ([]any, error) {
415  		return (*Subscription).scanValues(nil, columns)
416  	}
417  	_spec.Assign = func(columns []string, values []any) error {
418  		node := &Subscription{config: sq.config}
419  		nodes = append(nodes, node)
420  		node.Edges.loadedTypes = loadedTypes
421  		return node.assignValues(columns, values)
422  	}
423  	for i := range hooks {
424  		hooks[i](ctx, _spec)
425  	}
426  	if err := sqlgraph.QueryNodes(ctx, sq.driver, _spec); err != nil {
427  		return nil, err
428  	}
429  	if len(nodes) == 0 {
430  		return nodes, nil
431  	}
432  	if query := sq.withUser; query != nil {
433  		if err := sq.loadUser(ctx, query, nodes, nil,
434  			func(n *Subscription, e *User) { n.Edges.User = e }); err != nil {
435  			return nil, err
436  		}
437  	}
438  	if query := sq.withFeed; query != nil {
439  		if err := sq.loadFeed(ctx, query, nodes, nil,
440  			func(n *Subscription, e *Feed) { n.Edges.Feed = e }); err != nil {
441  			return nil, err
442  		}
443  	}
444  	return nodes, nil
445  }
446  
447  func (sq *SubscriptionQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Subscription, init func(*Subscription), assign func(*Subscription, *User)) error {
448  	ids := make([]uuid.UUID, 0, len(nodes))
449  	nodeids := make(map[uuid.UUID][]*Subscription)
450  	for i := range nodes {
451  		fk := nodes[i].UserID
452  		if _, ok := nodeids[fk]; !ok {
453  			ids = append(ids, fk)
454  		}
455  		nodeids[fk] = append(nodeids[fk], nodes[i])
456  	}
457  	if len(ids) == 0 {
458  		return nil
459  	}
460  	query.Where(user.IDIn(ids...))
461  	neighbors, err := query.All(ctx)
462  	if err != nil {
463  		return err
464  	}
465  	for _, n := range neighbors {
466  		nodes, ok := nodeids[n.ID]
467  		if !ok {
468  			return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
469  		}
470  		for i := range nodes {
471  			assign(nodes[i], n)
472  		}
473  	}
474  	return nil
475  }
476  func (sq *SubscriptionQuery) loadFeed(ctx context.Context, query *FeedQuery, nodes []*Subscription, init func(*Subscription), assign func(*Subscription, *Feed)) error {
477  	ids := make([]uuid.UUID, 0, len(nodes))
478  	nodeids := make(map[uuid.UUID][]*Subscription)
479  	for i := range nodes {
480  		fk := nodes[i].FeedID
481  		if _, ok := nodeids[fk]; !ok {
482  			ids = append(ids, fk)
483  		}
484  		nodeids[fk] = append(nodeids[fk], nodes[i])
485  	}
486  	if len(ids) == 0 {
487  		return nil
488  	}
489  	query.Where(feed.IDIn(ids...))
490  	neighbors, err := query.All(ctx)
491  	if err != nil {
492  		return err
493  	}
494  	for _, n := range neighbors {
495  		nodes, ok := nodeids[n.ID]
496  		if !ok {
497  			return fmt.Errorf(`unexpected foreign-key "feed_id" returned %v`, n.ID)
498  		}
499  		for i := range nodes {
500  			assign(nodes[i], n)
501  		}
502  	}
503  	return nil
504  }
505  
506  func (sq *SubscriptionQuery) sqlCount(ctx context.Context) (int, error) {
507  	_spec := sq.querySpec()
508  	_spec.Node.Columns = sq.ctx.Fields
509  	if len(sq.ctx.Fields) > 0 {
510  		_spec.Unique = sq.ctx.Unique != nil && *sq.ctx.Unique
511  	}
512  	return sqlgraph.CountNodes(ctx, sq.driver, _spec)
513  }
514  
515  func (sq *SubscriptionQuery) querySpec() *sqlgraph.QuerySpec {
516  	_spec := sqlgraph.NewQuerySpec(subscription.Table, subscription.Columns, sqlgraph.NewFieldSpec(subscription.FieldID, field.TypeUUID))
517  	_spec.From = sq.sql
518  	if unique := sq.ctx.Unique; unique != nil {
519  		_spec.Unique = *unique
520  	} else if sq.path != nil {
521  		_spec.Unique = true
522  	}
523  	if fields := sq.ctx.Fields; len(fields) > 0 {
524  		_spec.Node.Columns = make([]string, 0, len(fields))
525  		_spec.Node.Columns = append(_spec.Node.Columns, subscription.FieldID)
526  		for i := range fields {
527  			if fields[i] != subscription.FieldID {
528  				_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
529  			}
530  		}
531  		if sq.withUser != nil {
532  			_spec.Node.AddColumnOnce(subscription.FieldUserID)
533  		}
534  		if sq.withFeed != nil {
535  			_spec.Node.AddColumnOnce(subscription.FieldFeedID)
536  		}
537  	}
538  	if ps := sq.predicates; len(ps) > 0 {
539  		_spec.Predicate = func(selector *sql.Selector) {
540  			for i := range ps {
541  				ps[i](selector)
542  			}
543  		}
544  	}
545  	if limit := sq.ctx.Limit; limit != nil {
546  		_spec.Limit = *limit
547  	}
548  	if offset := sq.ctx.Offset; offset != nil {
549  		_spec.Offset = *offset
550  	}
551  	if ps := sq.order; len(ps) > 0 {
552  		_spec.Order = func(selector *sql.Selector) {
553  			for i := range ps {
554  				ps[i](selector)
555  			}
556  		}
557  	}
558  	return _spec
559  }
560  
561  func (sq *SubscriptionQuery) sqlQuery(ctx context.Context) *sql.Selector {
562  	builder := sql.Dialect(sq.driver.Dialect())
563  	t1 := builder.Table(subscription.Table)
564  	columns := sq.ctx.Fields
565  	if len(columns) == 0 {
566  		columns = subscription.Columns
567  	}
568  	selector := builder.Select(t1.Columns(columns...)...).From(t1)
569  	if sq.sql != nil {
570  		selector = sq.sql
571  		selector.Select(selector.Columns(columns...)...)
572  	}
573  	if sq.ctx.Unique != nil && *sq.ctx.Unique {
574  		selector.Distinct()
575  	}
576  	for _, p := range sq.predicates {
577  		p(selector)
578  	}
579  	for _, p := range sq.order {
580  		p(selector)
581  	}
582  	if offset := sq.ctx.Offset; offset != nil {
583  		// limit is mandatory for offset clause. We start
584  		// with default value, and override it below if needed.
585  		selector.Offset(*offset).Limit(math.MaxInt32)
586  	}
587  	if limit := sq.ctx.Limit; limit != nil {
588  		selector.Limit(*limit)
589  	}
590  	return selector
591  }
592  
593  // SubscriptionGroupBy is the group-by builder for Subscription entities.
594  type SubscriptionGroupBy struct {
595  	selector
596  	build *SubscriptionQuery
597  }
598  
599  // Aggregate adds the given aggregation functions to the group-by query.
600  func (sgb *SubscriptionGroupBy) Aggregate(fns ...AggregateFunc) *SubscriptionGroupBy {
601  	sgb.fns = append(sgb.fns, fns...)
602  	return sgb
603  }
604  
605  // Scan applies the selector query and scans the result into the given value.
606  func (sgb *SubscriptionGroupBy) Scan(ctx context.Context, v any) error {
607  	ctx = setContextOp(ctx, sgb.build.ctx, "GroupBy")
608  	if err := sgb.build.prepareQuery(ctx); err != nil {
609  		return err
610  	}
611  	return scanWithInterceptors[*SubscriptionQuery, *SubscriptionGroupBy](ctx, sgb.build, sgb, sgb.build.inters, v)
612  }
613  
614  func (sgb *SubscriptionGroupBy) sqlScan(ctx context.Context, root *SubscriptionQuery, v any) error {
615  	selector := root.sqlQuery(ctx).Select()
616  	aggregation := make([]string, 0, len(sgb.fns))
617  	for _, fn := range sgb.fns {
618  		aggregation = append(aggregation, fn(selector))
619  	}
620  	if len(selector.SelectedColumns()) == 0 {
621  		columns := make([]string, 0, len(*sgb.flds)+len(sgb.fns))
622  		for _, f := range *sgb.flds {
623  			columns = append(columns, selector.C(f))
624  		}
625  		columns = append(columns, aggregation...)
626  		selector.Select(columns...)
627  	}
628  	selector.GroupBy(selector.Columns(*sgb.flds...)...)
629  	if err := selector.Err(); err != nil {
630  		return err
631  	}
632  	rows := &sql.Rows{}
633  	query, args := selector.Query()
634  	if err := sgb.build.driver.Query(ctx, query, args, rows); err != nil {
635  		return err
636  	}
637  	defer rows.Close()
638  	return sql.ScanSlice(rows, v)
639  }
640  
641  // SubscriptionSelect is the builder for selecting fields of Subscription entities.
642  type SubscriptionSelect struct {
643  	*SubscriptionQuery
644  	selector
645  }
646  
647  // Aggregate adds the given aggregation functions to the selector query.
648  func (ss *SubscriptionSelect) Aggregate(fns ...AggregateFunc) *SubscriptionSelect {
649  	ss.fns = append(ss.fns, fns...)
650  	return ss
651  }
652  
653  // Scan applies the selector query and scans the result into the given value.
654  func (ss *SubscriptionSelect) Scan(ctx context.Context, v any) error {
655  	ctx = setContextOp(ctx, ss.ctx, "Select")
656  	if err := ss.prepareQuery(ctx); err != nil {
657  		return err
658  	}
659  	return scanWithInterceptors[*SubscriptionQuery, *SubscriptionSelect](ctx, ss.SubscriptionQuery, ss, ss.inters, v)
660  }
661  
662  func (ss *SubscriptionSelect) sqlScan(ctx context.Context, root *SubscriptionQuery, v any) error {
663  	selector := root.sqlQuery(ctx)
664  	aggregation := make([]string, 0, len(ss.fns))
665  	for _, fn := range ss.fns {
666  		aggregation = append(aggregation, fn(selector))
667  	}
668  	switch n := len(*ss.selector.flds); {
669  	case n == 0 && len(aggregation) > 0:
670  		selector.Select(aggregation...)
671  	case n != 0 && len(aggregation) > 0:
672  		selector.AppendSelect(aggregation...)
673  	}
674  	rows := &sql.Rows{}
675  	query, args := selector.Query()
676  	if err := ss.driver.Query(ctx, query, args, rows); err != nil {
677  		return err
678  	}
679  	defer rows.Close()
680  	return sql.ScanSlice(rows, v)
681  }