Debian Codegraph @

ent/attestationcollection_query.go

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