// Code generated by ent, DO NOT EDIT. package ent import ( "context" "fmt" "math" "polaris/ent/downloadclients" "polaris/ent/predicate" "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // DownloadClientsQuery is the builder for querying DownloadClients entities. type DownloadClientsQuery struct { config ctx *QueryContext order []downloadclients.OrderOption inters []Interceptor predicates []predicate.DownloadClients // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } // Where adds a new predicate for the DownloadClientsQuery builder. func (dcq *DownloadClientsQuery) Where(ps ...predicate.DownloadClients) *DownloadClientsQuery { dcq.predicates = append(dcq.predicates, ps...) return dcq } // Limit the number of records to be returned by this query. func (dcq *DownloadClientsQuery) Limit(limit int) *DownloadClientsQuery { dcq.ctx.Limit = &limit return dcq } // Offset to start from. func (dcq *DownloadClientsQuery) Offset(offset int) *DownloadClientsQuery { dcq.ctx.Offset = &offset return dcq } // 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 (dcq *DownloadClientsQuery) Unique(unique bool) *DownloadClientsQuery { dcq.ctx.Unique = &unique return dcq } // Order specifies how the records should be ordered. func (dcq *DownloadClientsQuery) Order(o ...downloadclients.OrderOption) *DownloadClientsQuery { dcq.order = append(dcq.order, o...) return dcq } // First returns the first DownloadClients entity from the query. // Returns a *NotFoundError when no DownloadClients was found. func (dcq *DownloadClientsQuery) First(ctx context.Context) (*DownloadClients, error) { nodes, err := dcq.Limit(1).All(setContextOp(ctx, dcq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } if len(nodes) == 0 { return nil, &NotFoundError{downloadclients.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. func (dcq *DownloadClientsQuery) FirstX(ctx context.Context) *DownloadClients { node, err := dcq.First(ctx) if err != nil && !IsNotFound(err) { panic(err) } return node } // FirstID returns the first DownloadClients ID from the query. // Returns a *NotFoundError when no DownloadClients ID was found. func (dcq *DownloadClientsQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = dcq.Limit(1).IDs(setContextOp(ctx, dcq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { err = &NotFoundError{downloadclients.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. func (dcq *DownloadClientsQuery) FirstIDX(ctx context.Context) int { id, err := dcq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) } return id } // Only returns a single DownloadClients entity found by the query, ensuring it only returns one. // Returns a *NotSingularError when more than one DownloadClients entity is found. // Returns a *NotFoundError when no DownloadClients entities are found. func (dcq *DownloadClientsQuery) Only(ctx context.Context) (*DownloadClients, error) { nodes, err := dcq.Limit(2).All(setContextOp(ctx, dcq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } switch len(nodes) { case 1: return nodes[0], nil case 0: return nil, &NotFoundError{downloadclients.Label} default: return nil, &NotSingularError{downloadclients.Label} } } // OnlyX is like Only, but panics if an error occurs. func (dcq *DownloadClientsQuery) OnlyX(ctx context.Context) *DownloadClients { node, err := dcq.Only(ctx) if err != nil { panic(err) } return node } // OnlyID is like Only, but returns the only DownloadClients ID in the query. // Returns a *NotSingularError when more than one DownloadClients ID is found. // Returns a *NotFoundError when no entities are found. func (dcq *DownloadClientsQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = dcq.Limit(2).IDs(setContextOp(ctx, dcq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { case 1: id = ids[0] case 0: err = &NotFoundError{downloadclients.Label} default: err = &NotSingularError{downloadclients.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. func (dcq *DownloadClientsQuery) OnlyIDX(ctx context.Context) int { id, err := dcq.OnlyID(ctx) if err != nil { panic(err) } return id } // All executes the query and returns a list of DownloadClientsSlice. func (dcq *DownloadClientsQuery) All(ctx context.Context) ([]*DownloadClients, error) { ctx = setContextOp(ctx, dcq.ctx, ent.OpQueryAll) if err := dcq.prepareQuery(ctx); err != nil { return nil, err } qr := querierAll[[]*DownloadClients, *DownloadClientsQuery]() return withInterceptors[[]*DownloadClients](ctx, dcq, qr, dcq.inters) } // AllX is like All, but panics if an error occurs. func (dcq *DownloadClientsQuery) AllX(ctx context.Context) []*DownloadClients { nodes, err := dcq.All(ctx) if err != nil { panic(err) } return nodes } // IDs executes the query and returns a list of DownloadClients IDs. func (dcq *DownloadClientsQuery) IDs(ctx context.Context) (ids []int, err error) { if dcq.ctx.Unique == nil && dcq.path != nil { dcq.Unique(true) } ctx = setContextOp(ctx, dcq.ctx, ent.OpQueryIDs) if err = dcq.Select(downloadclients.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. func (dcq *DownloadClientsQuery) IDsX(ctx context.Context) []int { ids, err := dcq.IDs(ctx) if err != nil { panic(err) } return ids } // Count returns the count of the given query. func (dcq *DownloadClientsQuery) Count(ctx context.Context) (int, error) { ctx = setContextOp(ctx, dcq.ctx, ent.OpQueryCount) if err := dcq.prepareQuery(ctx); err != nil { return 0, err } return withInterceptors[int](ctx, dcq, querierCount[*DownloadClientsQuery](), dcq.inters) } // CountX is like Count, but panics if an error occurs. func (dcq *DownloadClientsQuery) CountX(ctx context.Context) int { count, err := dcq.Count(ctx) if err != nil { panic(err) } return count } // Exist returns true if the query has elements in the graph. func (dcq *DownloadClientsQuery) Exist(ctx context.Context) (bool, error) { ctx = setContextOp(ctx, dcq.ctx, ent.OpQueryExist) switch _, err := dcq.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 (dcq *DownloadClientsQuery) ExistX(ctx context.Context) bool { exist, err := dcq.Exist(ctx) if err != nil { panic(err) } return exist } // Clone returns a duplicate of the DownloadClientsQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (dcq *DownloadClientsQuery) Clone() *DownloadClientsQuery { if dcq == nil { return nil } return &DownloadClientsQuery{ config: dcq.config, ctx: dcq.ctx.Clone(), order: append([]downloadclients.OrderOption{}, dcq.order...), inters: append([]Interceptor{}, dcq.inters...), predicates: append([]predicate.DownloadClients{}, dcq.predicates...), // clone intermediate query. sql: dcq.sql.Clone(), path: dcq.path, } } // 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 { // Enable bool `json:"enable,omitempty"` // Count int `json:"count,omitempty"` // } // // client.DownloadClients.Query(). // GroupBy(downloadclients.FieldEnable). // Aggregate(ent.Count()). // Scan(ctx, &v) func (dcq *DownloadClientsQuery) GroupBy(field string, fields ...string) *DownloadClientsGroupBy { dcq.ctx.Fields = append([]string{field}, fields...) grbuild := &DownloadClientsGroupBy{build: dcq} grbuild.flds = &dcq.ctx.Fields grbuild.label = downloadclients.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 { // Enable bool `json:"enable,omitempty"` // } // // client.DownloadClients.Query(). // Select(downloadclients.FieldEnable). // Scan(ctx, &v) func (dcq *DownloadClientsQuery) Select(fields ...string) *DownloadClientsSelect { dcq.ctx.Fields = append(dcq.ctx.Fields, fields...) sbuild := &DownloadClientsSelect{DownloadClientsQuery: dcq} sbuild.label = downloadclients.Label sbuild.flds, sbuild.scan = &dcq.ctx.Fields, sbuild.Scan return sbuild } // Aggregate returns a DownloadClientsSelect configured with the given aggregations. func (dcq *DownloadClientsQuery) Aggregate(fns ...AggregateFunc) *DownloadClientsSelect { return dcq.Select().Aggregate(fns...) } func (dcq *DownloadClientsQuery) prepareQuery(ctx context.Context) error { for _, inter := range dcq.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, dcq); err != nil { return err } } } for _, f := range dcq.ctx.Fields { if !downloadclients.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } if dcq.path != nil { prev, err := dcq.path(ctx) if err != nil { return err } dcq.sql = prev } return nil } func (dcq *DownloadClientsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*DownloadClients, error) { var ( nodes = []*DownloadClients{} _spec = dcq.querySpec() ) _spec.ScanValues = func(columns []string) ([]any, error) { return (*DownloadClients).scanValues(nil, columns) } _spec.Assign = func(columns []string, values []any) error { node := &DownloadClients{config: dcq.config} nodes = append(nodes, node) return node.assignValues(columns, values) } for i := range hooks { hooks[i](ctx, _spec) } if err := sqlgraph.QueryNodes(ctx, dcq.driver, _spec); err != nil { return nil, err } if len(nodes) == 0 { return nodes, nil } return nodes, nil } func (dcq *DownloadClientsQuery) sqlCount(ctx context.Context) (int, error) { _spec := dcq.querySpec() _spec.Node.Columns = dcq.ctx.Fields if len(dcq.ctx.Fields) > 0 { _spec.Unique = dcq.ctx.Unique != nil && *dcq.ctx.Unique } return sqlgraph.CountNodes(ctx, dcq.driver, _spec) } func (dcq *DownloadClientsQuery) querySpec() *sqlgraph.QuerySpec { _spec := sqlgraph.NewQuerySpec(downloadclients.Table, downloadclients.Columns, sqlgraph.NewFieldSpec(downloadclients.FieldID, field.TypeInt)) _spec.From = dcq.sql if unique := dcq.ctx.Unique; unique != nil { _spec.Unique = *unique } else if dcq.path != nil { _spec.Unique = true } if fields := dcq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, downloadclients.FieldID) for i := range fields { if fields[i] != downloadclients.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } } if ps := dcq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if limit := dcq.ctx.Limit; limit != nil { _spec.Limit = *limit } if offset := dcq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := dcq.order; len(ps) > 0 { _spec.Order = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } return _spec } func (dcq *DownloadClientsQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(dcq.driver.Dialect()) t1 := builder.Table(downloadclients.Table) columns := dcq.ctx.Fields if len(columns) == 0 { columns = downloadclients.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) if dcq.sql != nil { selector = dcq.sql selector.Select(selector.Columns(columns...)...) } if dcq.ctx.Unique != nil && *dcq.ctx.Unique { selector.Distinct() } for _, p := range dcq.predicates { p(selector) } for _, p := range dcq.order { p(selector) } if offset := dcq.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 := dcq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector } // DownloadClientsGroupBy is the group-by builder for DownloadClients entities. type DownloadClientsGroupBy struct { selector build *DownloadClientsQuery } // Aggregate adds the given aggregation functions to the group-by query. func (dcgb *DownloadClientsGroupBy) Aggregate(fns ...AggregateFunc) *DownloadClientsGroupBy { dcgb.fns = append(dcgb.fns, fns...) return dcgb } // Scan applies the selector query and scans the result into the given value. func (dcgb *DownloadClientsGroupBy) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, dcgb.build.ctx, ent.OpQueryGroupBy) if err := dcgb.build.prepareQuery(ctx); err != nil { return err } return scanWithInterceptors[*DownloadClientsQuery, *DownloadClientsGroupBy](ctx, dcgb.build, dcgb, dcgb.build.inters, v) } func (dcgb *DownloadClientsGroupBy) sqlScan(ctx context.Context, root *DownloadClientsQuery, v any) error { selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(dcgb.fns)) for _, fn := range dcgb.fns { aggregation = append(aggregation, fn(selector)) } if len(selector.SelectedColumns()) == 0 { columns := make([]string, 0, len(*dcgb.flds)+len(dcgb.fns)) for _, f := range *dcgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } selector.GroupBy(selector.Columns(*dcgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() if err := dcgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } // DownloadClientsSelect is the builder for selecting fields of DownloadClients entities. type DownloadClientsSelect struct { *DownloadClientsQuery selector } // Aggregate adds the given aggregation functions to the selector query. func (dcs *DownloadClientsSelect) Aggregate(fns ...AggregateFunc) *DownloadClientsSelect { dcs.fns = append(dcs.fns, fns...) return dcs } // Scan applies the selector query and scans the result into the given value. func (dcs *DownloadClientsSelect) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, dcs.ctx, ent.OpQuerySelect) if err := dcs.prepareQuery(ctx); err != nil { return err } return scanWithInterceptors[*DownloadClientsQuery, *DownloadClientsSelect](ctx, dcs.DownloadClientsQuery, dcs, dcs.inters, v) } func (dcs *DownloadClientsSelect) sqlScan(ctx context.Context, root *DownloadClientsQuery, v any) error { selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(dcs.fns)) for _, fn := range dcs.fns { aggregation = append(aggregation, fn(selector)) } switch n := len(*dcs.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 := dcs.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) }