Files
csgowtfd/ent/matchplayer_query.go
2021-10-31 08:40:02 +01:00

1268 lines
35 KiB
Go

// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/predicate"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/spray"
"csgowtfd/ent/weapon"
"database/sql/driver"
"errors"
"fmt"
"math"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// MatchPlayerQuery is the builder for querying MatchPlayer entities.
type MatchPlayerQuery struct {
config
limit *int
offset *int
unique *bool
order []OrderFunc
fields []string
predicates []predicate.MatchPlayer
// eager-loading edges.
withMatches *MatchQuery
withPlayers *PlayerQuery
withWeaponStats *WeaponQuery
withRoundStats *RoundStatsQuery
withSpray *SprayQuery
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 MatchPlayerQuery builder.
func (mpq *MatchPlayerQuery) Where(ps ...predicate.MatchPlayer) *MatchPlayerQuery {
mpq.predicates = append(mpq.predicates, ps...)
return mpq
}
// Limit adds a limit step to the query.
func (mpq *MatchPlayerQuery) Limit(limit int) *MatchPlayerQuery {
mpq.limit = &limit
return mpq
}
// Offset adds an offset step to the query.
func (mpq *MatchPlayerQuery) Offset(offset int) *MatchPlayerQuery {
mpq.offset = &offset
return mpq
}
// 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 (mpq *MatchPlayerQuery) Unique(unique bool) *MatchPlayerQuery {
mpq.unique = &unique
return mpq
}
// Order adds an order step to the query.
func (mpq *MatchPlayerQuery) Order(o ...OrderFunc) *MatchPlayerQuery {
mpq.order = append(mpq.order, o...)
return mpq
}
// QueryMatches chains the current query on the "matches" edge.
func (mpq *MatchPlayerQuery) QueryMatches() *MatchQuery {
query := &MatchQuery{config: mpq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := mpq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := mpq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, selector),
sqlgraph.To(match.Table, match.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, matchplayer.MatchesTable, matchplayer.MatchesColumn),
)
fromU = sqlgraph.SetNeighbors(mpq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryPlayers chains the current query on the "players" edge.
func (mpq *MatchPlayerQuery) QueryPlayers() *PlayerQuery {
query := &PlayerQuery{config: mpq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := mpq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := mpq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, selector),
sqlgraph.To(player.Table, player.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, matchplayer.PlayersTable, matchplayer.PlayersColumn),
)
fromU = sqlgraph.SetNeighbors(mpq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryWeaponStats chains the current query on the "weapon_stats" edge.
func (mpq *MatchPlayerQuery) QueryWeaponStats() *WeaponQuery {
query := &WeaponQuery{config: mpq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := mpq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := mpq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, selector),
sqlgraph.To(weapon.Table, weapon.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.WeaponStatsTable, matchplayer.WeaponStatsColumn),
)
fromU = sqlgraph.SetNeighbors(mpq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryRoundStats chains the current query on the "round_stats" edge.
func (mpq *MatchPlayerQuery) QueryRoundStats() *RoundStatsQuery {
query := &RoundStatsQuery{config: mpq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := mpq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := mpq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, selector),
sqlgraph.To(roundstats.Table, roundstats.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.RoundStatsTable, matchplayer.RoundStatsColumn),
)
fromU = sqlgraph.SetNeighbors(mpq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QuerySpray chains the current query on the "spray" edge.
func (mpq *MatchPlayerQuery) QuerySpray() *SprayQuery {
query := &SprayQuery{config: mpq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := mpq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := mpq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, selector),
sqlgraph.To(spray.Table, spray.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.SprayTable, matchplayer.SprayColumn),
)
fromU = sqlgraph.SetNeighbors(mpq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first MatchPlayer entity from the query.
// Returns a *NotFoundError when no MatchPlayer was found.
func (mpq *MatchPlayerQuery) First(ctx context.Context) (*MatchPlayer, error) {
nodes, err := mpq.Limit(1).All(ctx)
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{matchplayer.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (mpq *MatchPlayerQuery) FirstX(ctx context.Context) *MatchPlayer {
node, err := mpq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first MatchPlayer ID from the query.
// Returns a *NotFoundError when no MatchPlayer ID was found.
func (mpq *MatchPlayerQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = mpq.Limit(1).IDs(ctx); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{matchplayer.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (mpq *MatchPlayerQuery) FirstIDX(ctx context.Context) int {
id, err := mpq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single MatchPlayer entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when exactly one MatchPlayer entity is not found.
// Returns a *NotFoundError when no MatchPlayer entities are found.
func (mpq *MatchPlayerQuery) Only(ctx context.Context) (*MatchPlayer, error) {
nodes, err := mpq.Limit(2).All(ctx)
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{matchplayer.Label}
default:
return nil, &NotSingularError{matchplayer.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (mpq *MatchPlayerQuery) OnlyX(ctx context.Context) *MatchPlayer {
node, err := mpq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only MatchPlayer ID in the query.
// Returns a *NotSingularError when exactly one MatchPlayer ID is not found.
// Returns a *NotFoundError when no entities are found.
func (mpq *MatchPlayerQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = mpq.Limit(2).IDs(ctx); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = &NotSingularError{matchplayer.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (mpq *MatchPlayerQuery) OnlyIDX(ctx context.Context) int {
id, err := mpq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of MatchPlayers.
func (mpq *MatchPlayerQuery) All(ctx context.Context) ([]*MatchPlayer, error) {
if err := mpq.prepareQuery(ctx); err != nil {
return nil, err
}
return mpq.sqlAll(ctx)
}
// AllX is like All, but panics if an error occurs.
func (mpq *MatchPlayerQuery) AllX(ctx context.Context) []*MatchPlayer {
nodes, err := mpq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of MatchPlayer IDs.
func (mpq *MatchPlayerQuery) IDs(ctx context.Context) ([]int, error) {
var ids []int
if err := mpq.Select(matchplayer.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (mpq *MatchPlayerQuery) IDsX(ctx context.Context) []int {
ids, err := mpq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (mpq *MatchPlayerQuery) Count(ctx context.Context) (int, error) {
if err := mpq.prepareQuery(ctx); err != nil {
return 0, err
}
return mpq.sqlCount(ctx)
}
// CountX is like Count, but panics if an error occurs.
func (mpq *MatchPlayerQuery) CountX(ctx context.Context) int {
count, err := mpq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (mpq *MatchPlayerQuery) Exist(ctx context.Context) (bool, error) {
if err := mpq.prepareQuery(ctx); err != nil {
return false, err
}
return mpq.sqlExist(ctx)
}
// ExistX is like Exist, but panics if an error occurs.
func (mpq *MatchPlayerQuery) ExistX(ctx context.Context) bool {
exist, err := mpq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the MatchPlayerQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (mpq *MatchPlayerQuery) Clone() *MatchPlayerQuery {
if mpq == nil {
return nil
}
return &MatchPlayerQuery{
config: mpq.config,
limit: mpq.limit,
offset: mpq.offset,
order: append([]OrderFunc{}, mpq.order...),
predicates: append([]predicate.MatchPlayer{}, mpq.predicates...),
withMatches: mpq.withMatches.Clone(),
withPlayers: mpq.withPlayers.Clone(),
withWeaponStats: mpq.withWeaponStats.Clone(),
withRoundStats: mpq.withRoundStats.Clone(),
withSpray: mpq.withSpray.Clone(),
// clone intermediate query.
sql: mpq.sql.Clone(),
path: mpq.path,
}
}
// WithMatches tells the query-builder to eager-load the nodes that are connected to
// the "matches" edge. The optional arguments are used to configure the query builder of the edge.
func (mpq *MatchPlayerQuery) WithMatches(opts ...func(*MatchQuery)) *MatchPlayerQuery {
query := &MatchQuery{config: mpq.config}
for _, opt := range opts {
opt(query)
}
mpq.withMatches = query
return mpq
}
// WithPlayers tells the query-builder to eager-load the nodes that are connected to
// the "players" edge. The optional arguments are used to configure the query builder of the edge.
func (mpq *MatchPlayerQuery) WithPlayers(opts ...func(*PlayerQuery)) *MatchPlayerQuery {
query := &PlayerQuery{config: mpq.config}
for _, opt := range opts {
opt(query)
}
mpq.withPlayers = query
return mpq
}
// WithWeaponStats tells the query-builder to eager-load the nodes that are connected to
// the "weapon_stats" edge. The optional arguments are used to configure the query builder of the edge.
func (mpq *MatchPlayerQuery) WithWeaponStats(opts ...func(*WeaponQuery)) *MatchPlayerQuery {
query := &WeaponQuery{config: mpq.config}
for _, opt := range opts {
opt(query)
}
mpq.withWeaponStats = query
return mpq
}
// WithRoundStats tells the query-builder to eager-load the nodes that are connected to
// the "round_stats" edge. The optional arguments are used to configure the query builder of the edge.
func (mpq *MatchPlayerQuery) WithRoundStats(opts ...func(*RoundStatsQuery)) *MatchPlayerQuery {
query := &RoundStatsQuery{config: mpq.config}
for _, opt := range opts {
opt(query)
}
mpq.withRoundStats = query
return mpq
}
// WithSpray tells the query-builder to eager-load the nodes that are connected to
// the "spray" edge. The optional arguments are used to configure the query builder of the edge.
func (mpq *MatchPlayerQuery) WithSpray(opts ...func(*SprayQuery)) *MatchPlayerQuery {
query := &SprayQuery{config: mpq.config}
for _, opt := range opts {
opt(query)
}
mpq.withSpray = query
return mpq
}
// 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 {
// TeamID int `json:"team_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.MatchPlayer.Query().
// GroupBy(matchplayer.FieldTeamID).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
//
func (mpq *MatchPlayerQuery) GroupBy(field string, fields ...string) *MatchPlayerGroupBy {
group := &MatchPlayerGroupBy{config: mpq.config}
group.fields = append([]string{field}, fields...)
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
if err := mpq.prepareQuery(ctx); err != nil {
return nil, err
}
return mpq.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 {
// TeamID int `json:"team_id,omitempty"`
// }
//
// client.MatchPlayer.Query().
// Select(matchplayer.FieldTeamID).
// Scan(ctx, &v)
//
func (mpq *MatchPlayerQuery) Select(fields ...string) *MatchPlayerSelect {
mpq.fields = append(mpq.fields, fields...)
return &MatchPlayerSelect{MatchPlayerQuery: mpq}
}
func (mpq *MatchPlayerQuery) prepareQuery(ctx context.Context) error {
for _, f := range mpq.fields {
if !matchplayer.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if mpq.path != nil {
prev, err := mpq.path(ctx)
if err != nil {
return err
}
mpq.sql = prev
}
return nil
}
func (mpq *MatchPlayerQuery) sqlAll(ctx context.Context) ([]*MatchPlayer, error) {
var (
nodes = []*MatchPlayer{}
_spec = mpq.querySpec()
loadedTypes = [5]bool{
mpq.withMatches != nil,
mpq.withPlayers != nil,
mpq.withWeaponStats != nil,
mpq.withRoundStats != nil,
mpq.withSpray != nil,
}
)
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
node := &MatchPlayer{config: mpq.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(mpq.modifiers) > 0 {
_spec.Modifiers = mpq.modifiers
}
if err := sqlgraph.QueryNodes(ctx, mpq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := mpq.withMatches; query != nil {
ids := make([]uint64, 0, len(nodes))
nodeids := make(map[uint64][]*MatchPlayer)
for i := range nodes {
fk := nodes[i].MatchStats
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
query.Where(match.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_stats" returned %v`, n.ID)
}
for i := range nodes {
nodes[i].Edges.Matches = n
}
}
}
if query := mpq.withPlayers; query != nil {
ids := make([]uint64, 0, len(nodes))
nodeids := make(map[uint64][]*MatchPlayer)
for i := range nodes {
fk := nodes[i].PlayerStats
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
query.Where(player.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 "player_stats" returned %v`, n.ID)
}
for i := range nodes {
nodes[i].Edges.Players = n
}
}
}
if query := mpq.withWeaponStats; query != nil {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int]*MatchPlayer)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
nodes[i].Edges.WeaponStats = []*Weapon{}
}
query.withFKs = true
query.Where(predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.InValues(matchplayer.WeaponStatsColumn, fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return nil, err
}
for _, n := range neighbors {
fk := n.match_player_weapon_stats
if fk == nil {
return nil, fmt.Errorf(`foreign-key "match_player_weapon_stats" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return nil, fmt.Errorf(`unexpected foreign-key "match_player_weapon_stats" returned %v for node %v`, *fk, n.ID)
}
node.Edges.WeaponStats = append(node.Edges.WeaponStats, n)
}
}
if query := mpq.withRoundStats; query != nil {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int]*MatchPlayer)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
nodes[i].Edges.RoundStats = []*RoundStats{}
}
query.withFKs = true
query.Where(predicate.RoundStats(func(s *sql.Selector) {
s.Where(sql.InValues(matchplayer.RoundStatsColumn, fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return nil, err
}
for _, n := range neighbors {
fk := n.match_player_round_stats
if fk == nil {
return nil, fmt.Errorf(`foreign-key "match_player_round_stats" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return nil, fmt.Errorf(`unexpected foreign-key "match_player_round_stats" returned %v for node %v`, *fk, n.ID)
}
node.Edges.RoundStats = append(node.Edges.RoundStats, n)
}
}
if query := mpq.withSpray; query != nil {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int]*MatchPlayer)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
nodes[i].Edges.Spray = []*Spray{}
}
query.withFKs = true
query.Where(predicate.Spray(func(s *sql.Selector) {
s.Where(sql.InValues(matchplayer.SprayColumn, fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return nil, err
}
for _, n := range neighbors {
fk := n.match_player_spray
if fk == nil {
return nil, fmt.Errorf(`foreign-key "match_player_spray" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return nil, fmt.Errorf(`unexpected foreign-key "match_player_spray" returned %v for node %v`, *fk, n.ID)
}
node.Edges.Spray = append(node.Edges.Spray, n)
}
}
return nodes, nil
}
func (mpq *MatchPlayerQuery) sqlCount(ctx context.Context) (int, error) {
_spec := mpq.querySpec()
if len(mpq.modifiers) > 0 {
_spec.Modifiers = mpq.modifiers
}
return sqlgraph.CountNodes(ctx, mpq.driver, _spec)
}
func (mpq *MatchPlayerQuery) sqlExist(ctx context.Context) (bool, error) {
n, err := mpq.sqlCount(ctx)
if err != nil {
return false, fmt.Errorf("ent: check existence: %w", err)
}
return n > 0, nil
}
func (mpq *MatchPlayerQuery) querySpec() *sqlgraph.QuerySpec {
_spec := &sqlgraph.QuerySpec{
Node: &sqlgraph.NodeSpec{
Table: matchplayer.Table,
Columns: matchplayer.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
From: mpq.sql,
Unique: true,
}
if unique := mpq.unique; unique != nil {
_spec.Unique = *unique
}
if fields := mpq.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, matchplayer.FieldID)
for i := range fields {
if fields[i] != matchplayer.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := mpq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := mpq.limit; limit != nil {
_spec.Limit = *limit
}
if offset := mpq.offset; offset != nil {
_spec.Offset = *offset
}
if ps := mpq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (mpq *MatchPlayerQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(mpq.driver.Dialect())
t1 := builder.Table(matchplayer.Table)
columns := mpq.fields
if len(columns) == 0 {
columns = matchplayer.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if mpq.sql != nil {
selector = mpq.sql
selector.Select(selector.Columns(columns...)...)
}
for _, m := range mpq.modifiers {
m(selector)
}
for _, p := range mpq.predicates {
p(selector)
}
for _, p := range mpq.order {
p(selector)
}
if offset := mpq.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 := mpq.limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// Modify adds a query modifier for attaching custom logic to queries.
func (mpq *MatchPlayerQuery) Modify(modifiers ...func(s *sql.Selector)) *MatchPlayerSelect {
mpq.modifiers = append(mpq.modifiers, modifiers...)
return mpq.Select()
}
// MatchPlayerGroupBy is the group-by builder for MatchPlayer entities.
type MatchPlayerGroupBy 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 (mpgb *MatchPlayerGroupBy) Aggregate(fns ...AggregateFunc) *MatchPlayerGroupBy {
mpgb.fns = append(mpgb.fns, fns...)
return mpgb
}
// Scan applies the group-by query and scans the result into the given value.
func (mpgb *MatchPlayerGroupBy) Scan(ctx context.Context, v interface{}) error {
query, err := mpgb.path(ctx)
if err != nil {
return err
}
mpgb.sql = query
return mpgb.sqlScan(ctx, v)
}
// ScanX is like Scan, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) ScanX(ctx context.Context, v interface{}) {
if err := mpgb.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 (mpgb *MatchPlayerGroupBy) Strings(ctx context.Context) ([]string, error) {
if len(mpgb.fields) > 1 {
return nil, errors.New("ent: MatchPlayerGroupBy.Strings is not achievable when grouping more than 1 field")
}
var v []string
if err := mpgb.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// StringsX is like Strings, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) StringsX(ctx context.Context) []string {
v, err := mpgb.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 (mpgb *MatchPlayerGroupBy) String(ctx context.Context) (_ string, err error) {
var v []string
if v, err = mpgb.Strings(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = fmt.Errorf("ent: MatchPlayerGroupBy.Strings returned %d results when one was expected", len(v))
}
return
}
// StringX is like String, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) StringX(ctx context.Context) string {
v, err := mpgb.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 (mpgb *MatchPlayerGroupBy) Ints(ctx context.Context) ([]int, error) {
if len(mpgb.fields) > 1 {
return nil, errors.New("ent: MatchPlayerGroupBy.Ints is not achievable when grouping more than 1 field")
}
var v []int
if err := mpgb.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// IntsX is like Ints, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) IntsX(ctx context.Context) []int {
v, err := mpgb.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 (mpgb *MatchPlayerGroupBy) Int(ctx context.Context) (_ int, err error) {
var v []int
if v, err = mpgb.Ints(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = fmt.Errorf("ent: MatchPlayerGroupBy.Ints returned %d results when one was expected", len(v))
}
return
}
// IntX is like Int, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) IntX(ctx context.Context) int {
v, err := mpgb.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 (mpgb *MatchPlayerGroupBy) Float64s(ctx context.Context) ([]float64, error) {
if len(mpgb.fields) > 1 {
return nil, errors.New("ent: MatchPlayerGroupBy.Float64s is not achievable when grouping more than 1 field")
}
var v []float64
if err := mpgb.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// Float64sX is like Float64s, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) Float64sX(ctx context.Context) []float64 {
v, err := mpgb.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 (mpgb *MatchPlayerGroupBy) Float64(ctx context.Context) (_ float64, err error) {
var v []float64
if v, err = mpgb.Float64s(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = fmt.Errorf("ent: MatchPlayerGroupBy.Float64s returned %d results when one was expected", len(v))
}
return
}
// Float64X is like Float64, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) Float64X(ctx context.Context) float64 {
v, err := mpgb.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 (mpgb *MatchPlayerGroupBy) Bools(ctx context.Context) ([]bool, error) {
if len(mpgb.fields) > 1 {
return nil, errors.New("ent: MatchPlayerGroupBy.Bools is not achievable when grouping more than 1 field")
}
var v []bool
if err := mpgb.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// BoolsX is like Bools, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) BoolsX(ctx context.Context) []bool {
v, err := mpgb.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 (mpgb *MatchPlayerGroupBy) Bool(ctx context.Context) (_ bool, err error) {
var v []bool
if v, err = mpgb.Bools(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = fmt.Errorf("ent: MatchPlayerGroupBy.Bools returned %d results when one was expected", len(v))
}
return
}
// BoolX is like Bool, but panics if an error occurs.
func (mpgb *MatchPlayerGroupBy) BoolX(ctx context.Context) bool {
v, err := mpgb.Bool(ctx)
if err != nil {
panic(err)
}
return v
}
func (mpgb *MatchPlayerGroupBy) sqlScan(ctx context.Context, v interface{}) error {
for _, f := range mpgb.fields {
if !matchplayer.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
}
}
selector := mpgb.sqlQuery()
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := mpgb.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
func (mpgb *MatchPlayerGroupBy) sqlQuery() *sql.Selector {
selector := mpgb.sql.Select()
aggregation := make([]string, 0, len(mpgb.fns))
for _, fn := range mpgb.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(mpgb.fields)+len(mpgb.fns))
for _, f := range mpgb.fields {
columns = append(columns, selector.C(f))
}
for _, c := range aggregation {
columns = append(columns, c)
}
selector.Select(columns...)
}
return selector.GroupBy(selector.Columns(mpgb.fields...)...)
}
// MatchPlayerSelect is the builder for selecting fields of MatchPlayer entities.
type MatchPlayerSelect struct {
*MatchPlayerQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
}
// Scan applies the selector query and scans the result into the given value.
func (mps *MatchPlayerSelect) Scan(ctx context.Context, v interface{}) error {
if err := mps.prepareQuery(ctx); err != nil {
return err
}
mps.sql = mps.MatchPlayerQuery.sqlQuery(ctx)
return mps.sqlScan(ctx, v)
}
// ScanX is like Scan, but panics if an error occurs.
func (mps *MatchPlayerSelect) ScanX(ctx context.Context, v interface{}) {
if err := mps.Scan(ctx, v); err != nil {
panic(err)
}
}
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
func (mps *MatchPlayerSelect) Strings(ctx context.Context) ([]string, error) {
if len(mps.fields) > 1 {
return nil, errors.New("ent: MatchPlayerSelect.Strings is not achievable when selecting more than 1 field")
}
var v []string
if err := mps.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// StringsX is like Strings, but panics if an error occurs.
func (mps *MatchPlayerSelect) StringsX(ctx context.Context) []string {
v, err := mps.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 (mps *MatchPlayerSelect) String(ctx context.Context) (_ string, err error) {
var v []string
if v, err = mps.Strings(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = fmt.Errorf("ent: MatchPlayerSelect.Strings returned %d results when one was expected", len(v))
}
return
}
// StringX is like String, but panics if an error occurs.
func (mps *MatchPlayerSelect) StringX(ctx context.Context) string {
v, err := mps.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 (mps *MatchPlayerSelect) Ints(ctx context.Context) ([]int, error) {
if len(mps.fields) > 1 {
return nil, errors.New("ent: MatchPlayerSelect.Ints is not achievable when selecting more than 1 field")
}
var v []int
if err := mps.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// IntsX is like Ints, but panics if an error occurs.
func (mps *MatchPlayerSelect) IntsX(ctx context.Context) []int {
v, err := mps.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 (mps *MatchPlayerSelect) Int(ctx context.Context) (_ int, err error) {
var v []int
if v, err = mps.Ints(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = fmt.Errorf("ent: MatchPlayerSelect.Ints returned %d results when one was expected", len(v))
}
return
}
// IntX is like Int, but panics if an error occurs.
func (mps *MatchPlayerSelect) IntX(ctx context.Context) int {
v, err := mps.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 (mps *MatchPlayerSelect) Float64s(ctx context.Context) ([]float64, error) {
if len(mps.fields) > 1 {
return nil, errors.New("ent: MatchPlayerSelect.Float64s is not achievable when selecting more than 1 field")
}
var v []float64
if err := mps.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// Float64sX is like Float64s, but panics if an error occurs.
func (mps *MatchPlayerSelect) Float64sX(ctx context.Context) []float64 {
v, err := mps.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 (mps *MatchPlayerSelect) Float64(ctx context.Context) (_ float64, err error) {
var v []float64
if v, err = mps.Float64s(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = fmt.Errorf("ent: MatchPlayerSelect.Float64s returned %d results when one was expected", len(v))
}
return
}
// Float64X is like Float64, but panics if an error occurs.
func (mps *MatchPlayerSelect) Float64X(ctx context.Context) float64 {
v, err := mps.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 (mps *MatchPlayerSelect) Bools(ctx context.Context) ([]bool, error) {
if len(mps.fields) > 1 {
return nil, errors.New("ent: MatchPlayerSelect.Bools is not achievable when selecting more than 1 field")
}
var v []bool
if err := mps.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// BoolsX is like Bools, but panics if an error occurs.
func (mps *MatchPlayerSelect) BoolsX(ctx context.Context) []bool {
v, err := mps.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 (mps *MatchPlayerSelect) Bool(ctx context.Context) (_ bool, err error) {
var v []bool
if v, err = mps.Bools(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{matchplayer.Label}
default:
err = fmt.Errorf("ent: MatchPlayerSelect.Bools returned %d results when one was expected", len(v))
}
return
}
// BoolX is like Bool, but panics if an error occurs.
func (mps *MatchPlayerSelect) BoolX(ctx context.Context) bool {
v, err := mps.Bool(ctx)
if err != nil {
panic(err)
}
return v
}
func (mps *MatchPlayerSelect) sqlScan(ctx context.Context, v interface{}) error {
rows := &sql.Rows{}
query, args := mps.sql.Query()
if err := mps.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 (mps *MatchPlayerSelect) Modify(modifiers ...func(s *sql.Selector)) *MatchPlayerSelect {
mps.modifiers = append(mps.modifiers, modifiers...)
return mps
}