Files
csgowtfd/ent/matchplayer_query.go

1014 lines
30 KiB
Go

// 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.harting.dev/csgowtf/csgowtfd/ent/match"
"git.harting.dev/csgowtf/csgowtfd/ent/matchplayer"
"git.harting.dev/csgowtf/csgowtfd/ent/messages"
"git.harting.dev/csgowtf/csgowtfd/ent/player"
"git.harting.dev/csgowtf/csgowtfd/ent/predicate"
"git.harting.dev/csgowtf/csgowtfd/ent/roundstats"
"git.harting.dev/csgowtf/csgowtfd/ent/spray"
"git.harting.dev/csgowtf/csgowtfd/ent/weapon"
)
// 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
withMatches *MatchQuery
withPlayers *PlayerQuery
withWeaponStats *WeaponQuery
withRoundStats *RoundStatsQuery
withSpray *SprayQuery
withMessages *MessagesQuery
modifiers []func(*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
}
// QueryMessages chains the current query on the "messages" edge.
func (mpq *MatchPlayerQuery) QueryMessages() *MessagesQuery {
query := &MessagesQuery{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(messages.Table, messages.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.MessagesTable, matchplayer.MessagesColumn),
)
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 more than one MatchPlayer entity is 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 more than one MatchPlayer ID is 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(),
withMessages: mpq.withMessages.Clone(),
// clone intermediate query.
sql: mpq.sql.Clone(),
path: mpq.path,
unique: mpq.unique,
}
}
// 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
}
// WithMessages tells the query-builder to eager-load the nodes that are connected to
// the "messages" edge. The optional arguments are used to configure the query builder of the edge.
func (mpq *MatchPlayerQuery) WithMessages(opts ...func(*MessagesQuery)) *MatchPlayerQuery {
query := &MessagesQuery{config: mpq.config}
for _, opt := range opts {
opt(query)
}
mpq.withMessages = 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 {
grbuild := &MatchPlayerGroupBy{config: mpq.config}
grbuild.fields = append([]string{field}, fields...)
grbuild.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
}
grbuild.label = matchplayer.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 {
// 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...)
selbuild := &MatchPlayerSelect{MatchPlayerQuery: mpq}
selbuild.label = matchplayer.Label
selbuild.flds, selbuild.scan = &mpq.fields, selbuild.Scan
return selbuild
}
// Aggregate returns a MatchPlayerSelect configured with the given aggregations.
func (mpq *MatchPlayerQuery) Aggregate(fns ...AggregateFunc) *MatchPlayerSelect {
return mpq.Select().Aggregate(fns...)
}
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, hooks ...queryHook) ([]*MatchPlayer, error) {
var (
nodes = []*MatchPlayer{}
_spec = mpq.querySpec()
loadedTypes = [6]bool{
mpq.withMatches != nil,
mpq.withPlayers != nil,
mpq.withWeaponStats != nil,
mpq.withRoundStats != nil,
mpq.withSpray != nil,
mpq.withMessages != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*MatchPlayer).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &MatchPlayer{config: mpq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
if len(mpq.modifiers) > 0 {
_spec.Modifiers = mpq.modifiers
}
for i := range hooks {
hooks[i](ctx, _spec)
}
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 {
if err := mpq.loadMatches(ctx, query, nodes, nil,
func(n *MatchPlayer, e *Match) { n.Edges.Matches = e }); err != nil {
return nil, err
}
}
if query := mpq.withPlayers; query != nil {
if err := mpq.loadPlayers(ctx, query, nodes, nil,
func(n *MatchPlayer, e *Player) { n.Edges.Players = e }); err != nil {
return nil, err
}
}
if query := mpq.withWeaponStats; query != nil {
if err := mpq.loadWeaponStats(ctx, query, nodes,
func(n *MatchPlayer) { n.Edges.WeaponStats = []*Weapon{} },
func(n *MatchPlayer, e *Weapon) { n.Edges.WeaponStats = append(n.Edges.WeaponStats, e) }); err != nil {
return nil, err
}
}
if query := mpq.withRoundStats; query != nil {
if err := mpq.loadRoundStats(ctx, query, nodes,
func(n *MatchPlayer) { n.Edges.RoundStats = []*RoundStats{} },
func(n *MatchPlayer, e *RoundStats) { n.Edges.RoundStats = append(n.Edges.RoundStats, e) }); err != nil {
return nil, err
}
}
if query := mpq.withSpray; query != nil {
if err := mpq.loadSpray(ctx, query, nodes,
func(n *MatchPlayer) { n.Edges.Spray = []*Spray{} },
func(n *MatchPlayer, e *Spray) { n.Edges.Spray = append(n.Edges.Spray, e) }); err != nil {
return nil, err
}
}
if query := mpq.withMessages; query != nil {
if err := mpq.loadMessages(ctx, query, nodes,
func(n *MatchPlayer) { n.Edges.Messages = []*Messages{} },
func(n *MatchPlayer, e *Messages) { n.Edges.Messages = append(n.Edges.Messages, e) }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (mpq *MatchPlayerQuery) loadMatches(ctx context.Context, query *MatchQuery, nodes []*MatchPlayer, init func(*MatchPlayer), assign func(*MatchPlayer, *Match)) error {
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 err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "match_stats" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (mpq *MatchPlayerQuery) loadPlayers(ctx context.Context, query *PlayerQuery, nodes []*MatchPlayer, init func(*MatchPlayer), assign func(*MatchPlayer, *Player)) error {
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 err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "player_stats" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (mpq *MatchPlayerQuery) loadWeaponStats(ctx context.Context, query *WeaponQuery, nodes []*MatchPlayer, init func(*MatchPlayer), assign func(*MatchPlayer, *Weapon)) error {
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]
if init != nil {
init(nodes[i])
}
}
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 err
}
for _, n := range neighbors {
fk := n.match_player_weapon_stats
if fk == nil {
return fmt.Errorf(`foreign-key "match_player_weapon_stats" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected foreign-key "match_player_weapon_stats" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (mpq *MatchPlayerQuery) loadRoundStats(ctx context.Context, query *RoundStatsQuery, nodes []*MatchPlayer, init func(*MatchPlayer), assign func(*MatchPlayer, *RoundStats)) error {
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]
if init != nil {
init(nodes[i])
}
}
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 err
}
for _, n := range neighbors {
fk := n.match_player_round_stats
if fk == nil {
return fmt.Errorf(`foreign-key "match_player_round_stats" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected foreign-key "match_player_round_stats" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (mpq *MatchPlayerQuery) loadSpray(ctx context.Context, query *SprayQuery, nodes []*MatchPlayer, init func(*MatchPlayer), assign func(*MatchPlayer, *Spray)) error {
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]
if init != nil {
init(nodes[i])
}
}
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 err
}
for _, n := range neighbors {
fk := n.match_player_spray
if fk == nil {
return fmt.Errorf(`foreign-key "match_player_spray" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected foreign-key "match_player_spray" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (mpq *MatchPlayerQuery) loadMessages(ctx context.Context, query *MessagesQuery, nodes []*MatchPlayer, init func(*MatchPlayer), assign func(*MatchPlayer, *Messages)) error {
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]
if init != nil {
init(nodes[i])
}
}
query.withFKs = true
query.Where(predicate.Messages(func(s *sql.Selector) {
s.Where(sql.InValues(matchplayer.MessagesColumn, fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.match_player_messages
if fk == nil {
return fmt.Errorf(`foreign-key "match_player_messages" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected foreign-key "match_player_messages" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (mpq *MatchPlayerQuery) sqlCount(ctx context.Context) (int, error) {
_spec := mpq.querySpec()
if len(mpq.modifiers) > 0 {
_spec.Modifiers = mpq.modifiers
}
_spec.Node.Columns = mpq.fields
if len(mpq.fields) > 0 {
_spec.Unique = mpq.unique != nil && *mpq.unique
}
return sqlgraph.CountNodes(ctx, mpq.driver, _spec)
}
func (mpq *MatchPlayerQuery) sqlExist(ctx context.Context) (bool, error) {
switch _, err := mpq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, 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...)...)
}
if mpq.unique != nil && *mpq.unique {
selector.Distinct()
}
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
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 (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 any) error {
query, err := mpgb.path(ctx)
if err != nil {
return err
}
mpgb.sql = query
return mpgb.sqlScan(ctx, v)
}
func (mpgb *MatchPlayerGroupBy) sqlScan(ctx context.Context, v any) 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 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))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
return selector.GroupBy(selector.Columns(mpgb.fields...)...)
}
// MatchPlayerSelect is the builder for selecting fields of MatchPlayer entities.
type MatchPlayerSelect struct {
*MatchPlayerQuery
selector
// intermediate query (i.e. traversal path).
sql *sql.Selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (mps *MatchPlayerSelect) Aggregate(fns ...AggregateFunc) *MatchPlayerSelect {
mps.fns = append(mps.fns, fns...)
return mps
}
// Scan applies the selector query and scans the result into the given value.
func (mps *MatchPlayerSelect) Scan(ctx context.Context, v any) error {
if err := mps.prepareQuery(ctx); err != nil {
return err
}
mps.sql = mps.MatchPlayerQuery.sqlQuery(ctx)
return mps.sqlScan(ctx, v)
}
func (mps *MatchPlayerSelect) sqlScan(ctx context.Context, v any) error {
aggregation := make([]string, 0, len(mps.fns))
for _, fn := range mps.fns {
aggregation = append(aggregation, fn(mps.sql))
}
switch n := len(*mps.selector.flds); {
case n == 0 && len(aggregation) > 0:
mps.sql.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
mps.sql.AppendSelect(aggregation...)
}
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
}