// Code generated by ent, DO NOT EDIT. package ent import ( "context" "fmt" "math" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/FrankenBotDev/FrankenAPI/ent/actions" "github.com/FrankenBotDev/FrankenAPI/ent/predicate" ) // ActionsQuery is the builder for querying Actions entities. type ActionsQuery struct { config limit *int offset *int unique *bool order []OrderFunc fields []string predicates []predicate.Actions // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } // Where adds a new predicate for the ActionsQuery builder. func (aq *ActionsQuery) Where(ps ...predicate.Actions) *ActionsQuery { aq.predicates = append(aq.predicates, ps...) return aq } // Limit adds a limit step to the query. func (aq *ActionsQuery) Limit(limit int) *ActionsQuery { aq.limit = &limit return aq } // Offset adds an offset step to the query. func (aq *ActionsQuery) Offset(offset int) *ActionsQuery { aq.offset = &offset return aq } // 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 (aq *ActionsQuery) Unique(unique bool) *ActionsQuery { aq.unique = &unique return aq } // Order adds an order step to the query. func (aq *ActionsQuery) Order(o ...OrderFunc) *ActionsQuery { aq.order = append(aq.order, o...) return aq } // First returns the first Actions entity from the query. // Returns a *NotFoundError when no Actions was found. func (aq *ActionsQuery) First(ctx context.Context) (*Actions, error) { nodes, err := aq.Limit(1).All(ctx) if err != nil { return nil, err } if len(nodes) == 0 { return nil, &NotFoundError{actions.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. func (aq *ActionsQuery) FirstX(ctx context.Context) *Actions { node, err := aq.First(ctx) if err != nil && !IsNotFound(err) { panic(err) } return node } // FirstID returns the first Actions ID from the query. // Returns a *NotFoundError when no Actions ID was found. func (aq *ActionsQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = aq.Limit(1).IDs(ctx); err != nil { return } if len(ids) == 0 { err = &NotFoundError{actions.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. func (aq *ActionsQuery) FirstIDX(ctx context.Context) int { id, err := aq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) } return id } // Only returns a single Actions entity found by the query, ensuring it only returns one. // Returns a *NotSingularError when more than one Actions entity is found. // Returns a *NotFoundError when no Actions entities are found. func (aq *ActionsQuery) Only(ctx context.Context) (*Actions, error) { nodes, err := aq.Limit(2).All(ctx) if err != nil { return nil, err } switch len(nodes) { case 1: return nodes[0], nil case 0: return nil, &NotFoundError{actions.Label} default: return nil, &NotSingularError{actions.Label} } } // OnlyX is like Only, but panics if an error occurs. func (aq *ActionsQuery) OnlyX(ctx context.Context) *Actions { node, err := aq.Only(ctx) if err != nil { panic(err) } return node } // OnlyID is like Only, but returns the only Actions ID in the query. // Returns a *NotSingularError when more than one Actions ID is found. // Returns a *NotFoundError when no entities are found. func (aq *ActionsQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = aq.Limit(2).IDs(ctx); err != nil { return } switch len(ids) { case 1: id = ids[0] case 0: err = &NotFoundError{actions.Label} default: err = &NotSingularError{actions.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. func (aq *ActionsQuery) OnlyIDX(ctx context.Context) int { id, err := aq.OnlyID(ctx) if err != nil { panic(err) } return id } // All executes the query and returns a list of ActionsSlice. func (aq *ActionsQuery) All(ctx context.Context) ([]*Actions, error) { if err := aq.prepareQuery(ctx); err != nil { return nil, err } return aq.sqlAll(ctx) } // AllX is like All, but panics if an error occurs. func (aq *ActionsQuery) AllX(ctx context.Context) []*Actions { nodes, err := aq.All(ctx) if err != nil { panic(err) } return nodes } // IDs executes the query and returns a list of Actions IDs. func (aq *ActionsQuery) IDs(ctx context.Context) ([]int, error) { var ids []int if err := aq.Select(actions.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. func (aq *ActionsQuery) IDsX(ctx context.Context) []int { ids, err := aq.IDs(ctx) if err != nil { panic(err) } return ids } // Count returns the count of the given query. func (aq *ActionsQuery) Count(ctx context.Context) (int, error) { if err := aq.prepareQuery(ctx); err != nil { return 0, err } return aq.sqlCount(ctx) } // CountX is like Count, but panics if an error occurs. func (aq *ActionsQuery) CountX(ctx context.Context) int { count, err := aq.Count(ctx) if err != nil { panic(err) } return count } // Exist returns true if the query has elements in the graph. func (aq *ActionsQuery) Exist(ctx context.Context) (bool, error) { if err := aq.prepareQuery(ctx); err != nil { return false, err } return aq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. func (aq *ActionsQuery) ExistX(ctx context.Context) bool { exist, err := aq.Exist(ctx) if err != nil { panic(err) } return exist } // Clone returns a duplicate of the ActionsQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (aq *ActionsQuery) Clone() *ActionsQuery { if aq == nil { return nil } return &ActionsQuery{ config: aq.config, limit: aq.limit, offset: aq.offset, order: append([]OrderFunc{}, aq.order...), predicates: append([]predicate.Actions{}, aq.predicates...), // clone intermediate query. sql: aq.sql.Clone(), path: aq.path, unique: aq.unique, } } // 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 { // Refid string `json:"refid,omitempty"` // Count int `json:"count,omitempty"` // } // // client.Actions.Query(). // GroupBy(actions.FieldRefid). // Aggregate(ent.Count()). // Scan(ctx, &v) // func (aq *ActionsQuery) GroupBy(field string, fields ...string) *ActionsGroupBy { grbuild := &ActionsGroupBy{config: aq.config} grbuild.fields = append([]string{field}, fields...) grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { if err := aq.prepareQuery(ctx); err != nil { return nil, err } return aq.sqlQuery(ctx), nil } grbuild.label = actions.Label grbuild.flds, grbuild.scan = &grbuild.fields, 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 { // Refid string `json:"refid,omitempty"` // } // // client.Actions.Query(). // Select(actions.FieldRefid). // Scan(ctx, &v) // func (aq *ActionsQuery) Select(fields ...string) *ActionsSelect { aq.fields = append(aq.fields, fields...) selbuild := &ActionsSelect{ActionsQuery: aq} selbuild.label = actions.Label selbuild.flds, selbuild.scan = &aq.fields, selbuild.Scan return selbuild } func (aq *ActionsQuery) prepareQuery(ctx context.Context) error { for _, f := range aq.fields { if !actions.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } if aq.path != nil { prev, err := aq.path(ctx) if err != nil { return err } aq.sql = prev } return nil } func (aq *ActionsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Actions, error) { var ( nodes = []*Actions{} _spec = aq.querySpec() ) _spec.ScanValues = func(columns []string) ([]interface{}, error) { return (*Actions).scanValues(nil, columns) } _spec.Assign = func(columns []string, values []interface{}) error { node := &Actions{config: aq.config} nodes = append(nodes, node) return node.assignValues(columns, values) } for i := range hooks { hooks[i](ctx, _spec) } if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil { return nil, err } if len(nodes) == 0 { return nodes, nil } return nodes, nil } func (aq *ActionsQuery) sqlCount(ctx context.Context) (int, error) { _spec := aq.querySpec() _spec.Node.Columns = aq.fields if len(aq.fields) > 0 { _spec.Unique = aq.unique != nil && *aq.unique } return sqlgraph.CountNodes(ctx, aq.driver, _spec) } func (aq *ActionsQuery) sqlExist(ctx context.Context) (bool, error) { n, err := aq.sqlCount(ctx) if err != nil { return false, fmt.Errorf("ent: check existence: %w", err) } return n > 0, nil } func (aq *ActionsQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ Table: actions.Table, Columns: actions.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: actions.FieldID, }, }, From: aq.sql, Unique: true, } if unique := aq.unique; unique != nil { _spec.Unique = *unique } if fields := aq.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, actions.FieldID) for i := range fields { if fields[i] != actions.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } } if ps := aq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if limit := aq.limit; limit != nil { _spec.Limit = *limit } if offset := aq.offset; offset != nil { _spec.Offset = *offset } if ps := aq.order; len(ps) > 0 { _spec.Order = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } return _spec } func (aq *ActionsQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(aq.driver.Dialect()) t1 := builder.Table(actions.Table) columns := aq.fields if len(columns) == 0 { columns = actions.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) if aq.sql != nil { selector = aq.sql selector.Select(selector.Columns(columns...)...) } if aq.unique != nil && *aq.unique { selector.Distinct() } for _, p := range aq.predicates { p(selector) } for _, p := range aq.order { p(selector) } if offset := aq.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 := aq.limit; limit != nil { selector.Limit(*limit) } return selector } // ActionsGroupBy is the group-by builder for Actions entities. type ActionsGroupBy struct { config selector fields []string fns []AggregateFunc // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } // Aggregate adds the given aggregation functions to the group-by query. func (agb *ActionsGroupBy) Aggregate(fns ...AggregateFunc) *ActionsGroupBy { agb.fns = append(agb.fns, fns...) return agb } // Scan applies the group-by query and scans the result into the given value. func (agb *ActionsGroupBy) Scan(ctx context.Context, v interface{}) error { query, err := agb.path(ctx) if err != nil { return err } agb.sql = query return agb.sqlScan(ctx, v) } func (agb *ActionsGroupBy) sqlScan(ctx context.Context, v interface{}) error { for _, f := range agb.fields { if !actions.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} } } selector := agb.sqlQuery() if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() if err := agb.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } func (agb *ActionsGroupBy) sqlQuery() *sql.Selector { selector := agb.sql.Select() aggregation := make([]string, 0, len(agb.fns)) for _, fn := range agb.fns { aggregation = append(aggregation, fn(selector)) } // If no columns were selected in a custom aggregation function, the default // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { columns := make([]string, 0, len(agb.fields)+len(agb.fns)) for _, f := range agb.fields { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(agb.fields...)...) } // ActionsSelect is the builder for selecting fields of Actions entities. type ActionsSelect struct { *ActionsQuery selector // intermediate query (i.e. traversal path). sql *sql.Selector } // Scan applies the selector query and scans the result into the given value. func (as *ActionsSelect) Scan(ctx context.Context, v interface{}) error { if err := as.prepareQuery(ctx); err != nil { return err } as.sql = as.ActionsQuery.sqlQuery(ctx) return as.sqlScan(ctx, v) } func (as *ActionsSelect) sqlScan(ctx context.Context, v interface{}) error { rows := &sql.Rows{} query, args := as.sql.Query() if err := as.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) }