998 lines
30 KiB
Go
998 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
|
|
ctx *QueryContext
|
|
order []OrderFunc
|
|
inters []Interceptor
|
|
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 the number of records to be returned by this query.
|
|
func (mpq *MatchPlayerQuery) Limit(limit int) *MatchPlayerQuery {
|
|
mpq.ctx.Limit = &limit
|
|
return mpq
|
|
}
|
|
|
|
// Offset to start from.
|
|
func (mpq *MatchPlayerQuery) Offset(offset int) *MatchPlayerQuery {
|
|
mpq.ctx.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.ctx.Unique = &unique
|
|
return mpq
|
|
}
|
|
|
|
// Order specifies how the records should be ordered.
|
|
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 := (&MatchClient{config: mpq.config}).Query()
|
|
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 := (&PlayerClient{config: mpq.config}).Query()
|
|
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 := (&WeaponClient{config: mpq.config}).Query()
|
|
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 := (&RoundStatsClient{config: mpq.config}).Query()
|
|
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 := (&SprayClient{config: mpq.config}).Query()
|
|
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 := (&MessagesClient{config: mpq.config}).Query()
|
|
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(setContextOp(ctx, mpq.ctx, "First"))
|
|
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(setContextOp(ctx, mpq.ctx, "FirstID")); 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(setContextOp(ctx, mpq.ctx, "Only"))
|
|
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(setContextOp(ctx, mpq.ctx, "OnlyID")); 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) {
|
|
ctx = setContextOp(ctx, mpq.ctx, "All")
|
|
if err := mpq.prepareQuery(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
qr := querierAll[[]*MatchPlayer, *MatchPlayerQuery]()
|
|
return withInterceptors[[]*MatchPlayer](ctx, mpq, qr, mpq.inters)
|
|
}
|
|
|
|
// 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) (ids []int, err error) {
|
|
if mpq.ctx.Unique == nil && mpq.path != nil {
|
|
mpq.Unique(true)
|
|
}
|
|
ctx = setContextOp(ctx, mpq.ctx, "IDs")
|
|
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) {
|
|
ctx = setContextOp(ctx, mpq.ctx, "Count")
|
|
if err := mpq.prepareQuery(ctx); err != nil {
|
|
return 0, err
|
|
}
|
|
return withInterceptors[int](ctx, mpq, querierCount[*MatchPlayerQuery](), mpq.inters)
|
|
}
|
|
|
|
// 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) {
|
|
ctx = setContextOp(ctx, mpq.ctx, "Exist")
|
|
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
|
|
}
|
|
}
|
|
|
|
// 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,
|
|
ctx: mpq.ctx.Clone(),
|
|
order: append([]OrderFunc{}, mpq.order...),
|
|
inters: append([]Interceptor{}, mpq.inters...),
|
|
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,
|
|
}
|
|
}
|
|
|
|
// 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 := (&MatchClient{config: mpq.config}).Query()
|
|
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 := (&PlayerClient{config: mpq.config}).Query()
|
|
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 := (&WeaponClient{config: mpq.config}).Query()
|
|
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 := (&RoundStatsClient{config: mpq.config}).Query()
|
|
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 := (&SprayClient{config: mpq.config}).Query()
|
|
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 := (&MessagesClient{config: mpq.config}).Query()
|
|
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 {
|
|
mpq.ctx.Fields = append([]string{field}, fields...)
|
|
grbuild := &MatchPlayerGroupBy{build: mpq}
|
|
grbuild.flds = &mpq.ctx.Fields
|
|
grbuild.label = matchplayer.Label
|
|
grbuild.scan = grbuild.Scan
|
|
return grbuild
|
|
}
|
|
|
|
// Select allows the selection one or more fields/columns for the given query,
|
|
// instead of selecting all fields in the entity.
|
|
//
|
|
// Example:
|
|
//
|
|
// var v []struct {
|
|
// TeamID int `json:"team_id,omitempty"`
|
|
// }
|
|
//
|
|
// client.MatchPlayer.Query().
|
|
// Select(matchplayer.FieldTeamID).
|
|
// Scan(ctx, &v)
|
|
func (mpq *MatchPlayerQuery) Select(fields ...string) *MatchPlayerSelect {
|
|
mpq.ctx.Fields = append(mpq.ctx.Fields, fields...)
|
|
sbuild := &MatchPlayerSelect{MatchPlayerQuery: mpq}
|
|
sbuild.label = matchplayer.Label
|
|
sbuild.flds, sbuild.scan = &mpq.ctx.Fields, sbuild.Scan
|
|
return sbuild
|
|
}
|
|
|
|
// 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 _, inter := range mpq.inters {
|
|
if inter == nil {
|
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
|
}
|
|
if trv, ok := inter.(Traverser); ok {
|
|
if err := trv.Traverse(ctx, mpq); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
for _, f := range mpq.ctx.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])
|
|
}
|
|
if len(ids) == 0 {
|
|
return nil
|
|
}
|
|
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])
|
|
}
|
|
if len(ids) == 0 {
|
|
return nil
|
|
}
|
|
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.ctx.Fields
|
|
if len(mpq.ctx.Fields) > 0 {
|
|
_spec.Unique = mpq.ctx.Unique != nil && *mpq.ctx.Unique
|
|
}
|
|
return sqlgraph.CountNodes(ctx, mpq.driver, _spec)
|
|
}
|
|
|
|
func (mpq *MatchPlayerQuery) querySpec() *sqlgraph.QuerySpec {
|
|
_spec := sqlgraph.NewQuerySpec(matchplayer.Table, matchplayer.Columns, sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt))
|
|
_spec.From = mpq.sql
|
|
if unique := mpq.ctx.Unique; unique != nil {
|
|
_spec.Unique = *unique
|
|
} else if mpq.path != nil {
|
|
_spec.Unique = true
|
|
}
|
|
if fields := mpq.ctx.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.ctx.Limit; limit != nil {
|
|
_spec.Limit = *limit
|
|
}
|
|
if offset := mpq.ctx.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.ctx.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.ctx.Unique != nil && *mpq.ctx.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.ctx.Offset; offset != nil {
|
|
// limit is mandatory for offset clause. We start
|
|
// with default value, and override it below if needed.
|
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
|
}
|
|
if limit := mpq.ctx.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 {
|
|
selector
|
|
build *MatchPlayerQuery
|
|
}
|
|
|
|
// 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 selector query and scans the result into the given value.
|
|
func (mpgb *MatchPlayerGroupBy) Scan(ctx context.Context, v any) error {
|
|
ctx = setContextOp(ctx, mpgb.build.ctx, "GroupBy")
|
|
if err := mpgb.build.prepareQuery(ctx); err != nil {
|
|
return err
|
|
}
|
|
return scanWithInterceptors[*MatchPlayerQuery, *MatchPlayerGroupBy](ctx, mpgb.build, mpgb, mpgb.build.inters, v)
|
|
}
|
|
|
|
func (mpgb *MatchPlayerGroupBy) sqlScan(ctx context.Context, root *MatchPlayerQuery, v any) error {
|
|
selector := root.sqlQuery(ctx).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.flds)+len(mpgb.fns))
|
|
for _, f := range *mpgb.flds {
|
|
columns = append(columns, selector.C(f))
|
|
}
|
|
columns = append(columns, aggregation...)
|
|
selector.Select(columns...)
|
|
}
|
|
selector.GroupBy(selector.Columns(*mpgb.flds...)...)
|
|
if err := selector.Err(); err != nil {
|
|
return err
|
|
}
|
|
rows := &sql.Rows{}
|
|
query, args := selector.Query()
|
|
if err := mpgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
return sql.ScanSlice(rows, v)
|
|
}
|
|
|
|
// MatchPlayerSelect is the builder for selecting fields of MatchPlayer entities.
|
|
type MatchPlayerSelect struct {
|
|
*MatchPlayerQuery
|
|
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 {
|
|
ctx = setContextOp(ctx, mps.ctx, "Select")
|
|
if err := mps.prepareQuery(ctx); err != nil {
|
|
return err
|
|
}
|
|
return scanWithInterceptors[*MatchPlayerQuery, *MatchPlayerSelect](ctx, mps.MatchPlayerQuery, mps, mps.inters, v)
|
|
}
|
|
|
|
func (mps *MatchPlayerSelect) sqlScan(ctx context.Context, root *MatchPlayerQuery, v any) error {
|
|
selector := root.sqlQuery(ctx)
|
|
aggregation := make([]string, 0, len(mps.fns))
|
|
for _, fn := range mps.fns {
|
|
aggregation = append(aggregation, fn(selector))
|
|
}
|
|
switch n := len(*mps.selector.flds); {
|
|
case n == 0 && len(aggregation) > 0:
|
|
selector.Select(aggregation...)
|
|
case n != 0 && len(aggregation) > 0:
|
|
selector.AppendSelect(aggregation...)
|
|
}
|
|
rows := &sql.Rows{}
|
|
query, args := selector.Query()
|
|
if err := 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
|
|
}
|