// Code generated by ent, DO NOT EDIT. package ent import ( "context" "database/sql/driver" "fmt" "math" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "git.dotya.ml/mirre-mt/pcmt/ent/hibp" "git.dotya.ml/mirre-mt/pcmt/ent/localbreach" "git.dotya.ml/mirre-mt/pcmt/ent/predicate" "git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches" "git.dotya.ml/mirre-mt/pcmt/ent/user" "github.com/google/uuid" ) // TrackedBreachesQuery is the builder for querying TrackedBreaches entities. type TrackedBreachesQuery struct { config ctx *QueryContext order []trackedbreaches.OrderOption inters []Interceptor predicates []predicate.TrackedBreaches withUser *UserQuery withLocalbreach *LocalBreachQuery withHibp *HIBPQuery // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } // Where adds a new predicate for the TrackedBreachesQuery builder. func (tbq *TrackedBreachesQuery) Where(ps ...predicate.TrackedBreaches) *TrackedBreachesQuery { tbq.predicates = append(tbq.predicates, ps...) return tbq } // Limit the number of records to be returned by this query. func (tbq *TrackedBreachesQuery) Limit(limit int) *TrackedBreachesQuery { tbq.ctx.Limit = &limit return tbq } // Offset to start from. func (tbq *TrackedBreachesQuery) Offset(offset int) *TrackedBreachesQuery { tbq.ctx.Offset = &offset return tbq } // 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 (tbq *TrackedBreachesQuery) Unique(unique bool) *TrackedBreachesQuery { tbq.ctx.Unique = &unique return tbq } // Order specifies how the records should be ordered. func (tbq *TrackedBreachesQuery) Order(o ...trackedbreaches.OrderOption) *TrackedBreachesQuery { tbq.order = append(tbq.order, o...) return tbq } // QueryUser chains the current query on the "user" edge. func (tbq *TrackedBreachesQuery) QueryUser() *UserQuery { query := (&UserClient{config: tbq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := tbq.prepareQuery(ctx); err != nil { return nil, err } selector := tbq.sqlQuery(ctx) if err := selector.Err(); err != nil { return nil, err } step := sqlgraph.NewStep( sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, selector), sqlgraph.To(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, trackedbreaches.UserTable, trackedbreaches.UserColumn), ) fromU = sqlgraph.SetNeighbors(tbq.driver.Dialect(), step) return fromU, nil } return query } // QueryLocalbreach chains the current query on the "localbreach" edge. func (tbq *TrackedBreachesQuery) QueryLocalbreach() *LocalBreachQuery { query := (&LocalBreachClient{config: tbq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := tbq.prepareQuery(ctx); err != nil { return nil, err } selector := tbq.sqlQuery(ctx) if err := selector.Err(); err != nil { return nil, err } step := sqlgraph.NewStep( sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, selector), sqlgraph.To(localbreach.Table, localbreach.FieldID), sqlgraph.Edge(sqlgraph.M2M, false, trackedbreaches.LocalbreachTable, trackedbreaches.LocalbreachPrimaryKey...), ) fromU = sqlgraph.SetNeighbors(tbq.driver.Dialect(), step) return fromU, nil } return query } // QueryHibp chains the current query on the "hibp" edge. func (tbq *TrackedBreachesQuery) QueryHibp() *HIBPQuery { query := (&HIBPClient{config: tbq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := tbq.prepareQuery(ctx); err != nil { return nil, err } selector := tbq.sqlQuery(ctx) if err := selector.Err(); err != nil { return nil, err } step := sqlgraph.NewStep( sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, selector), sqlgraph.To(hibp.Table, hibp.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, trackedbreaches.HibpTable, trackedbreaches.HibpColumn), ) fromU = sqlgraph.SetNeighbors(tbq.driver.Dialect(), step) return fromU, nil } return query } // First returns the first TrackedBreaches entity from the query. // Returns a *NotFoundError when no TrackedBreaches was found. func (tbq *TrackedBreachesQuery) First(ctx context.Context) (*TrackedBreaches, error) { nodes, err := tbq.Limit(1).All(setContextOp(ctx, tbq.ctx, "First")) if err != nil { return nil, err } if len(nodes) == 0 { return nil, &NotFoundError{trackedbreaches.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. func (tbq *TrackedBreachesQuery) FirstX(ctx context.Context) *TrackedBreaches { node, err := tbq.First(ctx) if err != nil && !IsNotFound(err) { panic(err) } return node } // FirstID returns the first TrackedBreaches ID from the query. // Returns a *NotFoundError when no TrackedBreaches ID was found. func (tbq *TrackedBreachesQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID if ids, err = tbq.Limit(1).IDs(setContextOp(ctx, tbq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { err = &NotFoundError{trackedbreaches.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. func (tbq *TrackedBreachesQuery) FirstIDX(ctx context.Context) uuid.UUID { id, err := tbq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) } return id } // Only returns a single TrackedBreaches entity found by the query, ensuring it only returns one. // Returns a *NotSingularError when more than one TrackedBreaches entity is found. // Returns a *NotFoundError when no TrackedBreaches entities are found. func (tbq *TrackedBreachesQuery) Only(ctx context.Context) (*TrackedBreaches, error) { nodes, err := tbq.Limit(2).All(setContextOp(ctx, tbq.ctx, "Only")) if err != nil { return nil, err } switch len(nodes) { case 1: return nodes[0], nil case 0: return nil, &NotFoundError{trackedbreaches.Label} default: return nil, &NotSingularError{trackedbreaches.Label} } } // OnlyX is like Only, but panics if an error occurs. func (tbq *TrackedBreachesQuery) OnlyX(ctx context.Context) *TrackedBreaches { node, err := tbq.Only(ctx) if err != nil { panic(err) } return node } // OnlyID is like Only, but returns the only TrackedBreaches ID in the query. // Returns a *NotSingularError when more than one TrackedBreaches ID is found. // Returns a *NotFoundError when no entities are found. func (tbq *TrackedBreachesQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID if ids, err = tbq.Limit(2).IDs(setContextOp(ctx, tbq.ctx, "OnlyID")); err != nil { return } switch len(ids) { case 1: id = ids[0] case 0: err = &NotFoundError{trackedbreaches.Label} default: err = &NotSingularError{trackedbreaches.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. func (tbq *TrackedBreachesQuery) OnlyIDX(ctx context.Context) uuid.UUID { id, err := tbq.OnlyID(ctx) if err != nil { panic(err) } return id } // All executes the query and returns a list of TrackedBreachesSlice. func (tbq *TrackedBreachesQuery) All(ctx context.Context) ([]*TrackedBreaches, error) { ctx = setContextOp(ctx, tbq.ctx, "All") if err := tbq.prepareQuery(ctx); err != nil { return nil, err } qr := querierAll[[]*TrackedBreaches, *TrackedBreachesQuery]() return withInterceptors[[]*TrackedBreaches](ctx, tbq, qr, tbq.inters) } // AllX is like All, but panics if an error occurs. func (tbq *TrackedBreachesQuery) AllX(ctx context.Context) []*TrackedBreaches { nodes, err := tbq.All(ctx) if err != nil { panic(err) } return nodes } // IDs executes the query and returns a list of TrackedBreaches IDs. func (tbq *TrackedBreachesQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if tbq.ctx.Unique == nil && tbq.path != nil { tbq.Unique(true) } ctx = setContextOp(ctx, tbq.ctx, "IDs") if err = tbq.Select(trackedbreaches.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. func (tbq *TrackedBreachesQuery) IDsX(ctx context.Context) []uuid.UUID { ids, err := tbq.IDs(ctx) if err != nil { panic(err) } return ids } // Count returns the count of the given query. func (tbq *TrackedBreachesQuery) Count(ctx context.Context) (int, error) { ctx = setContextOp(ctx, tbq.ctx, "Count") if err := tbq.prepareQuery(ctx); err != nil { return 0, err } return withInterceptors[int](ctx, tbq, querierCount[*TrackedBreachesQuery](), tbq.inters) } // CountX is like Count, but panics if an error occurs. func (tbq *TrackedBreachesQuery) CountX(ctx context.Context) int { count, err := tbq.Count(ctx) if err != nil { panic(err) } return count } // Exist returns true if the query has elements in the graph. func (tbq *TrackedBreachesQuery) Exist(ctx context.Context) (bool, error) { ctx = setContextOp(ctx, tbq.ctx, "Exist") switch _, err := tbq.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 (tbq *TrackedBreachesQuery) ExistX(ctx context.Context) bool { exist, err := tbq.Exist(ctx) if err != nil { panic(err) } return exist } // Clone returns a duplicate of the TrackedBreachesQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (tbq *TrackedBreachesQuery) Clone() *TrackedBreachesQuery { if tbq == nil { return nil } return &TrackedBreachesQuery{ config: tbq.config, ctx: tbq.ctx.Clone(), order: append([]trackedbreaches.OrderOption{}, tbq.order...), inters: append([]Interceptor{}, tbq.inters...), predicates: append([]predicate.TrackedBreaches{}, tbq.predicates...), withUser: tbq.withUser.Clone(), withLocalbreach: tbq.withLocalbreach.Clone(), withHibp: tbq.withHibp.Clone(), // clone intermediate query. sql: tbq.sql.Clone(), path: tbq.path, } } // WithUser tells the query-builder to eager-load the nodes that are connected to // the "user" edge. The optional arguments are used to configure the query builder of the edge. func (tbq *TrackedBreachesQuery) WithUser(opts ...func(*UserQuery)) *TrackedBreachesQuery { query := (&UserClient{config: tbq.config}).Query() for _, opt := range opts { opt(query) } tbq.withUser = query return tbq } // WithLocalbreach tells the query-builder to eager-load the nodes that are connected to // the "localbreach" edge. The optional arguments are used to configure the query builder of the edge. func (tbq *TrackedBreachesQuery) WithLocalbreach(opts ...func(*LocalBreachQuery)) *TrackedBreachesQuery { query := (&LocalBreachClient{config: tbq.config}).Query() for _, opt := range opts { opt(query) } tbq.withLocalbreach = query return tbq } // WithHibp tells the query-builder to eager-load the nodes that are connected to // the "hibp" edge. The optional arguments are used to configure the query builder of the edge. func (tbq *TrackedBreachesQuery) WithHibp(opts ...func(*HIBPQuery)) *TrackedBreachesQuery { query := (&HIBPClient{config: tbq.config}).Query() for _, opt := range opts { opt(query) } tbq.withHibp = query return tbq } // 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 { // Breach uuid.UUID `json:"breach,omitempty"` // Count int `json:"count,omitempty"` // } // // client.TrackedBreaches.Query(). // GroupBy(trackedbreaches.FieldBreach). // Aggregate(ent.Count()). // Scan(ctx, &v) func (tbq *TrackedBreachesQuery) GroupBy(field string, fields ...string) *TrackedBreachesGroupBy { tbq.ctx.Fields = append([]string{field}, fields...) grbuild := &TrackedBreachesGroupBy{build: tbq} grbuild.flds = &tbq.ctx.Fields grbuild.label = trackedbreaches.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 { // Breach uuid.UUID `json:"breach,omitempty"` // } // // client.TrackedBreaches.Query(). // Select(trackedbreaches.FieldBreach). // Scan(ctx, &v) func (tbq *TrackedBreachesQuery) Select(fields ...string) *TrackedBreachesSelect { tbq.ctx.Fields = append(tbq.ctx.Fields, fields...) sbuild := &TrackedBreachesSelect{TrackedBreachesQuery: tbq} sbuild.label = trackedbreaches.Label sbuild.flds, sbuild.scan = &tbq.ctx.Fields, sbuild.Scan return sbuild } // Aggregate returns a TrackedBreachesSelect configured with the given aggregations. func (tbq *TrackedBreachesQuery) Aggregate(fns ...AggregateFunc) *TrackedBreachesSelect { return tbq.Select().Aggregate(fns...) } func (tbq *TrackedBreachesQuery) prepareQuery(ctx context.Context) error { for _, inter := range tbq.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, tbq); err != nil { return err } } } for _, f := range tbq.ctx.Fields { if !trackedbreaches.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } if tbq.path != nil { prev, err := tbq.path(ctx) if err != nil { return err } tbq.sql = prev } return nil } func (tbq *TrackedBreachesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TrackedBreaches, error) { var ( nodes = []*TrackedBreaches{} _spec = tbq.querySpec() loadedTypes = [3]bool{ tbq.withUser != nil, tbq.withLocalbreach != nil, tbq.withHibp != nil, } ) _spec.ScanValues = func(columns []string) ([]any, error) { return (*TrackedBreaches).scanValues(nil, columns) } _spec.Assign = func(columns []string, values []any) error { node := &TrackedBreaches{config: tbq.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, tbq.driver, _spec); err != nil { return nil, err } if len(nodes) == 0 { return nodes, nil } if query := tbq.withUser; query != nil { if err := tbq.loadUser(ctx, query, nodes, nil, func(n *TrackedBreaches, e *User) { n.Edges.User = e }); err != nil { return nil, err } } if query := tbq.withLocalbreach; query != nil { if err := tbq.loadLocalbreach(ctx, query, nodes, func(n *TrackedBreaches) { n.Edges.Localbreach = []*LocalBreach{} }, func(n *TrackedBreaches, e *LocalBreach) { n.Edges.Localbreach = append(n.Edges.Localbreach, e) }); err != nil { return nil, err } } if query := tbq.withHibp; query != nil { if err := tbq.loadHibp(ctx, query, nodes, func(n *TrackedBreaches) { n.Edges.Hibp = []*HIBP{} }, func(n *TrackedBreaches, e *HIBP) { n.Edges.Hibp = append(n.Edges.Hibp, e) }); err != nil { return nil, err } } return nodes, nil } func (tbq *TrackedBreachesQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*TrackedBreaches, init func(*TrackedBreaches), assign func(*TrackedBreaches, *User)) error { ids := make([]uuid.UUID, 0, len(nodes)) nodeids := make(map[uuid.UUID][]*TrackedBreaches) for i := range nodes { fk := nodes[i].Owner if _, ok := nodeids[fk]; !ok { ids = append(ids, fk) } nodeids[fk] = append(nodeids[fk], nodes[i]) } if len(ids) == 0 { return nil } query.Where(user.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { return err } for _, n := range neighbors { nodes, ok := nodeids[n.ID] if !ok { return fmt.Errorf(`unexpected foreign-key "owner" returned %v`, n.ID) } for i := range nodes { assign(nodes[i], n) } } return nil } func (tbq *TrackedBreachesQuery) loadLocalbreach(ctx context.Context, query *LocalBreachQuery, nodes []*TrackedBreaches, init func(*TrackedBreaches), assign func(*TrackedBreaches, *LocalBreach)) error { edgeIDs := make([]driver.Value, len(nodes)) byID := make(map[uuid.UUID]*TrackedBreaches) nids := make(map[uuid.UUID]map[*TrackedBreaches]struct{}) for i, node := range nodes { edgeIDs[i] = node.ID byID[node.ID] = node if init != nil { init(node) } } query.Where(func(s *sql.Selector) { joinT := sql.Table(trackedbreaches.LocalbreachTable) s.Join(joinT).On(s.C(localbreach.FieldID), joinT.C(trackedbreaches.LocalbreachPrimaryKey[1])) s.Where(sql.InValues(joinT.C(trackedbreaches.LocalbreachPrimaryKey[0]), edgeIDs...)) columns := s.SelectedColumns() s.Select(joinT.C(trackedbreaches.LocalbreachPrimaryKey[0])) s.AppendSelect(columns...) s.SetDistinct(false) }) if err := query.prepareQuery(ctx); err != nil { return err } qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { assign := spec.Assign values := spec.ScanValues spec.ScanValues = func(columns []string) ([]any, error) { values, err := values(columns[1:]) if err != nil { return nil, err } return append([]any{new(uuid.UUID)}, values...), nil } spec.Assign = func(columns []string, values []any) error { outValue := *values[0].(*uuid.UUID) inValue := *values[1].(*uuid.UUID) if nids[inValue] == nil { nids[inValue] = map[*TrackedBreaches]struct{}{byID[outValue]: {}} return assign(columns[1:], values[1:]) } nids[inValue][byID[outValue]] = struct{}{} return nil } }) }) neighbors, err := withInterceptors[[]*LocalBreach](ctx, query, qr, query.inters) if err != nil { return err } for _, n := range neighbors { nodes, ok := nids[n.ID] if !ok { return fmt.Errorf(`unexpected "localbreach" node returned %v`, n.ID) } for kn := range nodes { assign(kn, n) } } return nil } func (tbq *TrackedBreachesQuery) loadHibp(ctx context.Context, query *HIBPQuery, nodes []*TrackedBreaches, init func(*TrackedBreaches), assign func(*TrackedBreaches, *HIBP)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[uuid.UUID]*TrackedBreaches) 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.HIBP(func(s *sql.Selector) { s.Where(sql.InValues(s.C(trackedbreaches.HibpColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { return err } for _, n := range neighbors { fk := n.tracked_breaches_hibp if fk == nil { return fmt.Errorf(`foreign-key "tracked_breaches_hibp" is nil for node %v`, n.ID) } node, ok := nodeids[*fk] if !ok { return fmt.Errorf(`unexpected referenced foreign-key "tracked_breaches_hibp" returned %v for node %v`, *fk, n.ID) } assign(node, n) } return nil } func (tbq *TrackedBreachesQuery) sqlCount(ctx context.Context) (int, error) { _spec := tbq.querySpec() _spec.Node.Columns = tbq.ctx.Fields if len(tbq.ctx.Fields) > 0 { _spec.Unique = tbq.ctx.Unique != nil && *tbq.ctx.Unique } return sqlgraph.CountNodes(ctx, tbq.driver, _spec) } func (tbq *TrackedBreachesQuery) querySpec() *sqlgraph.QuerySpec { _spec := sqlgraph.NewQuerySpec(trackedbreaches.Table, trackedbreaches.Columns, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID)) _spec.From = tbq.sql if unique := tbq.ctx.Unique; unique != nil { _spec.Unique = *unique } else if tbq.path != nil { _spec.Unique = true } if fields := tbq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, trackedbreaches.FieldID) for i := range fields { if fields[i] != trackedbreaches.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } if tbq.withUser != nil { _spec.Node.AddColumnOnce(trackedbreaches.FieldOwner) } } if ps := tbq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if limit := tbq.ctx.Limit; limit != nil { _spec.Limit = *limit } if offset := tbq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := tbq.order; len(ps) > 0 { _spec.Order = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } return _spec } func (tbq *TrackedBreachesQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(tbq.driver.Dialect()) t1 := builder.Table(trackedbreaches.Table) columns := tbq.ctx.Fields if len(columns) == 0 { columns = trackedbreaches.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) if tbq.sql != nil { selector = tbq.sql selector.Select(selector.Columns(columns...)...) } if tbq.ctx.Unique != nil && *tbq.ctx.Unique { selector.Distinct() } for _, p := range tbq.predicates { p(selector) } for _, p := range tbq.order { p(selector) } if offset := tbq.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 := tbq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector } // TrackedBreachesGroupBy is the group-by builder for TrackedBreaches entities. type TrackedBreachesGroupBy struct { selector build *TrackedBreachesQuery } // Aggregate adds the given aggregation functions to the group-by query. func (tbgb *TrackedBreachesGroupBy) Aggregate(fns ...AggregateFunc) *TrackedBreachesGroupBy { tbgb.fns = append(tbgb.fns, fns...) return tbgb } // Scan applies the selector query and scans the result into the given value. func (tbgb *TrackedBreachesGroupBy) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, tbgb.build.ctx, "GroupBy") if err := tbgb.build.prepareQuery(ctx); err != nil { return err } return scanWithInterceptors[*TrackedBreachesQuery, *TrackedBreachesGroupBy](ctx, tbgb.build, tbgb, tbgb.build.inters, v) } func (tbgb *TrackedBreachesGroupBy) sqlScan(ctx context.Context, root *TrackedBreachesQuery, v any) error { selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(tbgb.fns)) for _, fn := range tbgb.fns { aggregation = append(aggregation, fn(selector)) } if len(selector.SelectedColumns()) == 0 { columns := make([]string, 0, len(*tbgb.flds)+len(tbgb.fns)) for _, f := range *tbgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } selector.GroupBy(selector.Columns(*tbgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() if err := tbgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } // TrackedBreachesSelect is the builder for selecting fields of TrackedBreaches entities. type TrackedBreachesSelect struct { *TrackedBreachesQuery selector } // Aggregate adds the given aggregation functions to the selector query. func (tbs *TrackedBreachesSelect) Aggregate(fns ...AggregateFunc) *TrackedBreachesSelect { tbs.fns = append(tbs.fns, fns...) return tbs } // Scan applies the selector query and scans the result into the given value. func (tbs *TrackedBreachesSelect) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, tbs.ctx, "Select") if err := tbs.prepareQuery(ctx); err != nil { return err } return scanWithInterceptors[*TrackedBreachesQuery, *TrackedBreachesSelect](ctx, tbs.TrackedBreachesQuery, tbs, tbs.inters, v) } func (tbs *TrackedBreachesSelect) sqlScan(ctx context.Context, root *TrackedBreachesQuery, v any) error { selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(tbs.fns)) for _, fn := range tbs.fns { aggregation = append(aggregation, fn(selector)) } switch n := len(*tbs.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 := tbs.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) }