// Code generated by entc, DO NOT EDIT. package ent import ( "context" "csgowtfd/ent/matchplayer" "csgowtfd/ent/predicate" "csgowtfd/ent/weapon" "errors" "fmt" "math" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // WeaponQuery is the builder for querying Weapon entities. type WeaponQuery struct { config limit *int offset *int unique *bool order []OrderFunc fields []string predicates []predicate.Weapon // eager-loading edges. withStat *MatchPlayerQuery withFKs bool modifiers []func(s *sql.Selector) // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } // Where adds a new predicate for the WeaponQuery builder. func (wq *WeaponQuery) Where(ps ...predicate.Weapon) *WeaponQuery { wq.predicates = append(wq.predicates, ps...) return wq } // Limit adds a limit step to the query. func (wq *WeaponQuery) Limit(limit int) *WeaponQuery { wq.limit = &limit return wq } // Offset adds an offset step to the query. func (wq *WeaponQuery) Offset(offset int) *WeaponQuery { wq.offset = &offset return wq } // 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 (wq *WeaponQuery) Unique(unique bool) *WeaponQuery { wq.unique = &unique return wq } // Order adds an order step to the query. func (wq *WeaponQuery) Order(o ...OrderFunc) *WeaponQuery { wq.order = append(wq.order, o...) return wq } // QueryStat chains the current query on the "stat" edge. func (wq *WeaponQuery) QueryStat() *MatchPlayerQuery { query := &MatchPlayerQuery{config: wq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := wq.prepareQuery(ctx); err != nil { return nil, err } selector := wq.sqlQuery(ctx) if err := selector.Err(); err != nil { return nil, err } step := sqlgraph.NewStep( sqlgraph.From(weapon.Table, weapon.FieldID, selector), sqlgraph.To(matchplayer.Table, matchplayer.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, weapon.StatTable, weapon.StatColumn), ) fromU = sqlgraph.SetNeighbors(wq.driver.Dialect(), step) return fromU, nil } return query } // First returns the first Weapon entity from the query. // Returns a *NotFoundError when no Weapon was found. func (wq *WeaponQuery) First(ctx context.Context) (*Weapon, error) { nodes, err := wq.Limit(1).All(ctx) if err != nil { return nil, err } if len(nodes) == 0 { return nil, &NotFoundError{weapon.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. func (wq *WeaponQuery) FirstX(ctx context.Context) *Weapon { node, err := wq.First(ctx) if err != nil && !IsNotFound(err) { panic(err) } return node } // FirstID returns the first Weapon ID from the query. // Returns a *NotFoundError when no Weapon ID was found. func (wq *WeaponQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = wq.Limit(1).IDs(ctx); err != nil { return } if len(ids) == 0 { err = &NotFoundError{weapon.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. func (wq *WeaponQuery) FirstIDX(ctx context.Context) int { id, err := wq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) } return id } // Only returns a single Weapon entity found by the query, ensuring it only returns one. // Returns a *NotSingularError when exactly one Weapon entity is not found. // Returns a *NotFoundError when no Weapon entities are found. func (wq *WeaponQuery) Only(ctx context.Context) (*Weapon, error) { nodes, err := wq.Limit(2).All(ctx) if err != nil { return nil, err } switch len(nodes) { case 1: return nodes[0], nil case 0: return nil, &NotFoundError{weapon.Label} default: return nil, &NotSingularError{weapon.Label} } } // OnlyX is like Only, but panics if an error occurs. func (wq *WeaponQuery) OnlyX(ctx context.Context) *Weapon { node, err := wq.Only(ctx) if err != nil { panic(err) } return node } // OnlyID is like Only, but returns the only Weapon ID in the query. // Returns a *NotSingularError when exactly one Weapon ID is not found. // Returns a *NotFoundError when no entities are found. func (wq *WeaponQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = wq.Limit(2).IDs(ctx); err != nil { return } switch len(ids) { case 1: id = ids[0] case 0: err = &NotFoundError{weapon.Label} default: err = &NotSingularError{weapon.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. func (wq *WeaponQuery) OnlyIDX(ctx context.Context) int { id, err := wq.OnlyID(ctx) if err != nil { panic(err) } return id } // All executes the query and returns a list of Weapons. func (wq *WeaponQuery) All(ctx context.Context) ([]*Weapon, error) { if err := wq.prepareQuery(ctx); err != nil { return nil, err } return wq.sqlAll(ctx) } // AllX is like All, but panics if an error occurs. func (wq *WeaponQuery) AllX(ctx context.Context) []*Weapon { nodes, err := wq.All(ctx) if err != nil { panic(err) } return nodes } // IDs executes the query and returns a list of Weapon IDs. func (wq *WeaponQuery) IDs(ctx context.Context) ([]int, error) { var ids []int if err := wq.Select(weapon.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. func (wq *WeaponQuery) IDsX(ctx context.Context) []int { ids, err := wq.IDs(ctx) if err != nil { panic(err) } return ids } // Count returns the count of the given query. func (wq *WeaponQuery) Count(ctx context.Context) (int, error) { if err := wq.prepareQuery(ctx); err != nil { return 0, err } return wq.sqlCount(ctx) } // CountX is like Count, but panics if an error occurs. func (wq *WeaponQuery) CountX(ctx context.Context) int { count, err := wq.Count(ctx) if err != nil { panic(err) } return count } // Exist returns true if the query has elements in the graph. func (wq *WeaponQuery) Exist(ctx context.Context) (bool, error) { if err := wq.prepareQuery(ctx); err != nil { return false, err } return wq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. func (wq *WeaponQuery) ExistX(ctx context.Context) bool { exist, err := wq.Exist(ctx) if err != nil { panic(err) } return exist } // Clone returns a duplicate of the WeaponQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (wq *WeaponQuery) Clone() *WeaponQuery { if wq == nil { return nil } return &WeaponQuery{ config: wq.config, limit: wq.limit, offset: wq.offset, order: append([]OrderFunc{}, wq.order...), predicates: append([]predicate.Weapon{}, wq.predicates...), withStat: wq.withStat.Clone(), // clone intermediate query. sql: wq.sql.Clone(), path: wq.path, } } // WithStat tells the query-builder to eager-load the nodes that are connected to // the "stat" edge. The optional arguments are used to configure the query builder of the edge. func (wq *WeaponQuery) WithStat(opts ...func(*MatchPlayerQuery)) *WeaponQuery { query := &MatchPlayerQuery{config: wq.config} for _, opt := range opts { opt(query) } wq.withStat = query return wq } // 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 { // Victim uint64 `json:"victim,omitempty"` // Count int `json:"count,omitempty"` // } // // client.Weapon.Query(). // GroupBy(weapon.FieldVictim). // Aggregate(ent.Count()). // Scan(ctx, &v) // func (wq *WeaponQuery) GroupBy(field string, fields ...string) *WeaponGroupBy { group := &WeaponGroupBy{config: wq.config} group.fields = append([]string{field}, fields...) group.path = func(ctx context.Context) (prev *sql.Selector, err error) { if err := wq.prepareQuery(ctx); err != nil { return nil, err } return wq.sqlQuery(ctx), nil } return group } // 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 { // Victim uint64 `json:"victim,omitempty"` // } // // client.Weapon.Query(). // Select(weapon.FieldVictim). // Scan(ctx, &v) // func (wq *WeaponQuery) Select(fields ...string) *WeaponSelect { wq.fields = append(wq.fields, fields...) return &WeaponSelect{WeaponQuery: wq} } func (wq *WeaponQuery) prepareQuery(ctx context.Context) error { for _, f := range wq.fields { if !weapon.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } if wq.path != nil { prev, err := wq.path(ctx) if err != nil { return err } wq.sql = prev } return nil } func (wq *WeaponQuery) sqlAll(ctx context.Context) ([]*Weapon, error) { var ( nodes = []*Weapon{} withFKs = wq.withFKs _spec = wq.querySpec() loadedTypes = [1]bool{ wq.withStat != nil, } ) if wq.withStat != nil { withFKs = true } if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, weapon.ForeignKeys...) } _spec.ScanValues = func(columns []string) ([]interface{}, error) { node := &Weapon{config: wq.config} nodes = append(nodes, node) return node.scanValues(columns) } _spec.Assign = func(columns []string, values []interface{}) error { if len(nodes) == 0 { return fmt.Errorf("ent: Assign called without calling ScanValues") } node := nodes[len(nodes)-1] node.Edges.loadedTypes = loadedTypes return node.assignValues(columns, values) } if len(wq.modifiers) > 0 { _spec.Modifiers = wq.modifiers } if err := sqlgraph.QueryNodes(ctx, wq.driver, _spec); err != nil { return nil, err } if len(nodes) == 0 { return nodes, nil } if query := wq.withStat; query != nil { ids := make([]int, 0, len(nodes)) nodeids := make(map[int][]*Weapon) for i := range nodes { if nodes[i].match_player_weapon_stats == nil { continue } fk := *nodes[i].match_player_weapon_stats if _, ok := nodeids[fk]; !ok { ids = append(ids, fk) } nodeids[fk] = append(nodeids[fk], nodes[i]) } query.Where(matchplayer.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { return nil, err } for _, n := range neighbors { nodes, ok := nodeids[n.ID] if !ok { return nil, fmt.Errorf(`unexpected foreign-key "match_player_weapon_stats" returned %v`, n.ID) } for i := range nodes { nodes[i].Edges.Stat = n } } } return nodes, nil } func (wq *WeaponQuery) sqlCount(ctx context.Context) (int, error) { _spec := wq.querySpec() if len(wq.modifiers) > 0 { _spec.Modifiers = wq.modifiers } _spec.Node.Columns = wq.fields if len(wq.fields) > 0 { _spec.Unique = wq.unique != nil && *wq.unique } return sqlgraph.CountNodes(ctx, wq.driver, _spec) } func (wq *WeaponQuery) sqlExist(ctx context.Context) (bool, error) { n, err := wq.sqlCount(ctx) if err != nil { return false, fmt.Errorf("ent: check existence: %w", err) } return n > 0, nil } func (wq *WeaponQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ Table: weapon.Table, Columns: weapon.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: weapon.FieldID, }, }, From: wq.sql, Unique: true, } if unique := wq.unique; unique != nil { _spec.Unique = *unique } if fields := wq.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, weapon.FieldID) for i := range fields { if fields[i] != weapon.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } } if ps := wq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if limit := wq.limit; limit != nil { _spec.Limit = *limit } if offset := wq.offset; offset != nil { _spec.Offset = *offset } if ps := wq.order; len(ps) > 0 { _spec.Order = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } return _spec } func (wq *WeaponQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(wq.driver.Dialect()) t1 := builder.Table(weapon.Table) columns := wq.fields if len(columns) == 0 { columns = weapon.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) if wq.sql != nil { selector = wq.sql selector.Select(selector.Columns(columns...)...) } if wq.unique != nil && *wq.unique { selector.Distinct() } for _, m := range wq.modifiers { m(selector) } for _, p := range wq.predicates { p(selector) } for _, p := range wq.order { p(selector) } if offset := wq.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 := wq.limit; limit != nil { selector.Limit(*limit) } return selector } // Modify adds a query modifier for attaching custom logic to queries. func (wq *WeaponQuery) Modify(modifiers ...func(s *sql.Selector)) *WeaponSelect { wq.modifiers = append(wq.modifiers, modifiers...) return wq.Select() } // WeaponGroupBy is the group-by builder for Weapon entities. type WeaponGroupBy struct { config 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 (wgb *WeaponGroupBy) Aggregate(fns ...AggregateFunc) *WeaponGroupBy { wgb.fns = append(wgb.fns, fns...) return wgb } // Scan applies the group-by query and scans the result into the given value. func (wgb *WeaponGroupBy) Scan(ctx context.Context, v interface{}) error { query, err := wgb.path(ctx) if err != nil { return err } wgb.sql = query return wgb.sqlScan(ctx, v) } // ScanX is like Scan, but panics if an error occurs. func (wgb *WeaponGroupBy) ScanX(ctx context.Context, v interface{}) { if err := wgb.Scan(ctx, v); err != nil { panic(err) } } // Strings returns list of strings from group-by. // It is only allowed when executing a group-by query with one field. func (wgb *WeaponGroupBy) Strings(ctx context.Context) ([]string, error) { if len(wgb.fields) > 1 { return nil, errors.New("ent: WeaponGroupBy.Strings is not achievable when grouping more than 1 field") } var v []string if err := wgb.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // StringsX is like Strings, but panics if an error occurs. func (wgb *WeaponGroupBy) StringsX(ctx context.Context) []string { v, err := wgb.Strings(ctx) if err != nil { panic(err) } return v } // String returns a single string from a group-by query. // It is only allowed when executing a group-by query with one field. func (wgb *WeaponGroupBy) String(ctx context.Context) (_ string, err error) { var v []string if v, err = wgb.Strings(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: err = &NotFoundError{weapon.Label} default: err = fmt.Errorf("ent: WeaponGroupBy.Strings returned %d results when one was expected", len(v)) } return } // StringX is like String, but panics if an error occurs. func (wgb *WeaponGroupBy) StringX(ctx context.Context) string { v, err := wgb.String(ctx) if err != nil { panic(err) } return v } // Ints returns list of ints from group-by. // It is only allowed when executing a group-by query with one field. func (wgb *WeaponGroupBy) Ints(ctx context.Context) ([]int, error) { if len(wgb.fields) > 1 { return nil, errors.New("ent: WeaponGroupBy.Ints is not achievable when grouping more than 1 field") } var v []int if err := wgb.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // IntsX is like Ints, but panics if an error occurs. func (wgb *WeaponGroupBy) IntsX(ctx context.Context) []int { v, err := wgb.Ints(ctx) if err != nil { panic(err) } return v } // Int returns a single int from a group-by query. // It is only allowed when executing a group-by query with one field. func (wgb *WeaponGroupBy) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = wgb.Ints(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: err = &NotFoundError{weapon.Label} default: err = fmt.Errorf("ent: WeaponGroupBy.Ints returned %d results when one was expected", len(v)) } return } // IntX is like Int, but panics if an error occurs. func (wgb *WeaponGroupBy) IntX(ctx context.Context) int { v, err := wgb.Int(ctx) if err != nil { panic(err) } return v } // Float64s returns list of float64s from group-by. // It is only allowed when executing a group-by query with one field. func (wgb *WeaponGroupBy) Float64s(ctx context.Context) ([]float64, error) { if len(wgb.fields) > 1 { return nil, errors.New("ent: WeaponGroupBy.Float64s is not achievable when grouping more than 1 field") } var v []float64 if err := wgb.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // Float64sX is like Float64s, but panics if an error occurs. func (wgb *WeaponGroupBy) Float64sX(ctx context.Context) []float64 { v, err := wgb.Float64s(ctx) if err != nil { panic(err) } return v } // Float64 returns a single float64 from a group-by query. // It is only allowed when executing a group-by query with one field. func (wgb *WeaponGroupBy) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = wgb.Float64s(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: err = &NotFoundError{weapon.Label} default: err = fmt.Errorf("ent: WeaponGroupBy.Float64s returned %d results when one was expected", len(v)) } return } // Float64X is like Float64, but panics if an error occurs. func (wgb *WeaponGroupBy) Float64X(ctx context.Context) float64 { v, err := wgb.Float64(ctx) if err != nil { panic(err) } return v } // Bools returns list of bools from group-by. // It is only allowed when executing a group-by query with one field. func (wgb *WeaponGroupBy) Bools(ctx context.Context) ([]bool, error) { if len(wgb.fields) > 1 { return nil, errors.New("ent: WeaponGroupBy.Bools is not achievable when grouping more than 1 field") } var v []bool if err := wgb.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // BoolsX is like Bools, but panics if an error occurs. func (wgb *WeaponGroupBy) BoolsX(ctx context.Context) []bool { v, err := wgb.Bools(ctx) if err != nil { panic(err) } return v } // Bool returns a single bool from a group-by query. // It is only allowed when executing a group-by query with one field. func (wgb *WeaponGroupBy) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = wgb.Bools(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: err = &NotFoundError{weapon.Label} default: err = fmt.Errorf("ent: WeaponGroupBy.Bools returned %d results when one was expected", len(v)) } return } // BoolX is like Bool, but panics if an error occurs. func (wgb *WeaponGroupBy) BoolX(ctx context.Context) bool { v, err := wgb.Bool(ctx) if err != nil { panic(err) } return v } func (wgb *WeaponGroupBy) sqlScan(ctx context.Context, v interface{}) error { for _, f := range wgb.fields { if !weapon.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} } } selector := wgb.sqlQuery() if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() if err := wgb.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } func (wgb *WeaponGroupBy) sqlQuery() *sql.Selector { selector := wgb.sql.Select() aggregation := make([]string, 0, len(wgb.fns)) for _, fn := range wgb.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(wgb.fields)+len(wgb.fns)) for _, f := range wgb.fields { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(wgb.fields...)...) } // WeaponSelect is the builder for selecting fields of Weapon entities. type WeaponSelect struct { *WeaponQuery // intermediate query (i.e. traversal path). sql *sql.Selector } // Scan applies the selector query and scans the result into the given value. func (ws *WeaponSelect) Scan(ctx context.Context, v interface{}) error { if err := ws.prepareQuery(ctx); err != nil { return err } ws.sql = ws.WeaponQuery.sqlQuery(ctx) return ws.sqlScan(ctx, v) } // ScanX is like Scan, but panics if an error occurs. func (ws *WeaponSelect) ScanX(ctx context.Context, v interface{}) { if err := ws.Scan(ctx, v); err != nil { panic(err) } } // Strings returns list of strings from a selector. It is only allowed when selecting one field. func (ws *WeaponSelect) Strings(ctx context.Context) ([]string, error) { if len(ws.fields) > 1 { return nil, errors.New("ent: WeaponSelect.Strings is not achievable when selecting more than 1 field") } var v []string if err := ws.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // StringsX is like Strings, but panics if an error occurs. func (ws *WeaponSelect) StringsX(ctx context.Context) []string { v, err := ws.Strings(ctx) if err != nil { panic(err) } return v } // String returns a single string from a selector. It is only allowed when selecting one field. func (ws *WeaponSelect) String(ctx context.Context) (_ string, err error) { var v []string if v, err = ws.Strings(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: err = &NotFoundError{weapon.Label} default: err = fmt.Errorf("ent: WeaponSelect.Strings returned %d results when one was expected", len(v)) } return } // StringX is like String, but panics if an error occurs. func (ws *WeaponSelect) StringX(ctx context.Context) string { v, err := ws.String(ctx) if err != nil { panic(err) } return v } // Ints returns list of ints from a selector. It is only allowed when selecting one field. func (ws *WeaponSelect) Ints(ctx context.Context) ([]int, error) { if len(ws.fields) > 1 { return nil, errors.New("ent: WeaponSelect.Ints is not achievable when selecting more than 1 field") } var v []int if err := ws.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // IntsX is like Ints, but panics if an error occurs. func (ws *WeaponSelect) IntsX(ctx context.Context) []int { v, err := ws.Ints(ctx) if err != nil { panic(err) } return v } // Int returns a single int from a selector. It is only allowed when selecting one field. func (ws *WeaponSelect) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = ws.Ints(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: err = &NotFoundError{weapon.Label} default: err = fmt.Errorf("ent: WeaponSelect.Ints returned %d results when one was expected", len(v)) } return } // IntX is like Int, but panics if an error occurs. func (ws *WeaponSelect) IntX(ctx context.Context) int { v, err := ws.Int(ctx) if err != nil { panic(err) } return v } // Float64s returns list of float64s from a selector. It is only allowed when selecting one field. func (ws *WeaponSelect) Float64s(ctx context.Context) ([]float64, error) { if len(ws.fields) > 1 { return nil, errors.New("ent: WeaponSelect.Float64s is not achievable when selecting more than 1 field") } var v []float64 if err := ws.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // Float64sX is like Float64s, but panics if an error occurs. func (ws *WeaponSelect) Float64sX(ctx context.Context) []float64 { v, err := ws.Float64s(ctx) if err != nil { panic(err) } return v } // Float64 returns a single float64 from a selector. It is only allowed when selecting one field. func (ws *WeaponSelect) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = ws.Float64s(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: err = &NotFoundError{weapon.Label} default: err = fmt.Errorf("ent: WeaponSelect.Float64s returned %d results when one was expected", len(v)) } return } // Float64X is like Float64, but panics if an error occurs. func (ws *WeaponSelect) Float64X(ctx context.Context) float64 { v, err := ws.Float64(ctx) if err != nil { panic(err) } return v } // Bools returns list of bools from a selector. It is only allowed when selecting one field. func (ws *WeaponSelect) Bools(ctx context.Context) ([]bool, error) { if len(ws.fields) > 1 { return nil, errors.New("ent: WeaponSelect.Bools is not achievable when selecting more than 1 field") } var v []bool if err := ws.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // BoolsX is like Bools, but panics if an error occurs. func (ws *WeaponSelect) BoolsX(ctx context.Context) []bool { v, err := ws.Bools(ctx) if err != nil { panic(err) } return v } // Bool returns a single bool from a selector. It is only allowed when selecting one field. func (ws *WeaponSelect) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = ws.Bools(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: err = &NotFoundError{weapon.Label} default: err = fmt.Errorf("ent: WeaponSelect.Bools returned %d results when one was expected", len(v)) } return } // BoolX is like Bool, but panics if an error occurs. func (ws *WeaponSelect) BoolX(ctx context.Context) bool { v, err := ws.Bool(ctx) if err != nil { panic(err) } return v } func (ws *WeaponSelect) sqlScan(ctx context.Context, v interface{}) error { rows := &sql.Rows{} query, args := ws.sql.Query() if err := ws.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } // Modify adds a query modifier for attaching custom logic to queries. func (ws *WeaponSelect) Modify(modifiers ...func(s *sql.Selector)) *WeaponSelect { ws.modifiers = append(ws.modifiers, modifiers...) return ws }