990 lines
25 KiB
Go
990 lines
25 KiB
Go
// Code generated by entc, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"csgowtfd/ent/match"
|
|
"csgowtfd/ent/player"
|
|
"csgowtfd/ent/roundstats"
|
|
"csgowtfd/ent/stats"
|
|
"csgowtfd/ent/weaponstats"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// StatsCreate is the builder for creating a Stats entity.
|
|
type StatsCreate struct {
|
|
config
|
|
mutation *StatsMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetTeamID sets the "team_id" field.
|
|
func (sc *StatsCreate) SetTeamID(i int) *StatsCreate {
|
|
sc.mutation.SetTeamID(i)
|
|
return sc
|
|
}
|
|
|
|
// SetKills sets the "kills" field.
|
|
func (sc *StatsCreate) SetKills(i int) *StatsCreate {
|
|
sc.mutation.SetKills(i)
|
|
return sc
|
|
}
|
|
|
|
// SetDeaths sets the "deaths" field.
|
|
func (sc *StatsCreate) SetDeaths(i int) *StatsCreate {
|
|
sc.mutation.SetDeaths(i)
|
|
return sc
|
|
}
|
|
|
|
// SetAssists sets the "assists" field.
|
|
func (sc *StatsCreate) SetAssists(i int) *StatsCreate {
|
|
sc.mutation.SetAssists(i)
|
|
return sc
|
|
}
|
|
|
|
// SetHeadshot sets the "headshot" field.
|
|
func (sc *StatsCreate) SetHeadshot(i int) *StatsCreate {
|
|
sc.mutation.SetHeadshot(i)
|
|
return sc
|
|
}
|
|
|
|
// SetMvp sets the "mvp" field.
|
|
func (sc *StatsCreate) SetMvp(u uint) *StatsCreate {
|
|
sc.mutation.SetMvp(u)
|
|
return sc
|
|
}
|
|
|
|
// SetScore sets the "score" field.
|
|
func (sc *StatsCreate) SetScore(i int) *StatsCreate {
|
|
sc.mutation.SetScore(i)
|
|
return sc
|
|
}
|
|
|
|
// SetRankNew sets the "rank_new" field.
|
|
func (sc *StatsCreate) SetRankNew(i int) *StatsCreate {
|
|
sc.mutation.SetRankNew(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableRankNew sets the "rank_new" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableRankNew(i *int) *StatsCreate {
|
|
if i != nil {
|
|
sc.SetRankNew(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetRankOld sets the "rank_old" field.
|
|
func (sc *StatsCreate) SetRankOld(i int) *StatsCreate {
|
|
sc.mutation.SetRankOld(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableRankOld sets the "rank_old" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableRankOld(i *int) *StatsCreate {
|
|
if i != nil {
|
|
sc.SetRankOld(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetMk2 sets the "mk_2" field.
|
|
func (sc *StatsCreate) SetMk2(u uint) *StatsCreate {
|
|
sc.mutation.SetMk2(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableMk2 sets the "mk_2" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableMk2(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetMk2(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetMk3 sets the "mk_3" field.
|
|
func (sc *StatsCreate) SetMk3(u uint) *StatsCreate {
|
|
sc.mutation.SetMk3(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableMk3 sets the "mk_3" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableMk3(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetMk3(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetMk4 sets the "mk_4" field.
|
|
func (sc *StatsCreate) SetMk4(u uint) *StatsCreate {
|
|
sc.mutation.SetMk4(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableMk4 sets the "mk_4" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableMk4(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetMk4(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetMk5 sets the "mk_5" field.
|
|
func (sc *StatsCreate) SetMk5(u uint) *StatsCreate {
|
|
sc.mutation.SetMk5(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableMk5 sets the "mk_5" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableMk5(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetMk5(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetDmgEnemy sets the "dmg_enemy" field.
|
|
func (sc *StatsCreate) SetDmgEnemy(u uint) *StatsCreate {
|
|
sc.mutation.SetDmgEnemy(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableDmgEnemy sets the "dmg_enemy" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableDmgEnemy(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetDmgEnemy(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetDmgTeam sets the "dmg_team" field.
|
|
func (sc *StatsCreate) SetDmgTeam(u uint) *StatsCreate {
|
|
sc.mutation.SetDmgTeam(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableDmgTeam sets the "dmg_team" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableDmgTeam(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetDmgTeam(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUdHe sets the "ud_he" field.
|
|
func (sc *StatsCreate) SetUdHe(u uint) *StatsCreate {
|
|
sc.mutation.SetUdHe(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUdHe sets the "ud_he" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableUdHe(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetUdHe(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUdFlames sets the "ud_flames" field.
|
|
func (sc *StatsCreate) SetUdFlames(u uint) *StatsCreate {
|
|
sc.mutation.SetUdFlames(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUdFlames sets the "ud_flames" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableUdFlames(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetUdFlames(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUdFlash sets the "ud_flash" field.
|
|
func (sc *StatsCreate) SetUdFlash(u uint) *StatsCreate {
|
|
sc.mutation.SetUdFlash(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUdFlash sets the "ud_flash" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableUdFlash(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetUdFlash(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUdDecoy sets the "ud_decoy" field.
|
|
func (sc *StatsCreate) SetUdDecoy(u uint) *StatsCreate {
|
|
sc.mutation.SetUdDecoy(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUdDecoy sets the "ud_decoy" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableUdDecoy(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetUdDecoy(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUdSmoke sets the "ud_smoke" field.
|
|
func (sc *StatsCreate) SetUdSmoke(u uint) *StatsCreate {
|
|
sc.mutation.SetUdSmoke(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUdSmoke sets the "ud_smoke" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableUdSmoke(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetUdSmoke(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetCrosshair sets the "crosshair" field.
|
|
func (sc *StatsCreate) SetCrosshair(s string) *StatsCreate {
|
|
sc.mutation.SetCrosshair(s)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableCrosshair sets the "crosshair" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableCrosshair(s *string) *StatsCreate {
|
|
if s != nil {
|
|
sc.SetCrosshair(*s)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetColor sets the "color" field.
|
|
func (sc *StatsCreate) SetColor(s stats.Color) *StatsCreate {
|
|
sc.mutation.SetColor(s)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableColor sets the "color" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableColor(s *stats.Color) *StatsCreate {
|
|
if s != nil {
|
|
sc.SetColor(*s)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetKast sets the "kast" field.
|
|
func (sc *StatsCreate) SetKast(i int) *StatsCreate {
|
|
sc.mutation.SetKast(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableKast sets the "kast" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableKast(i *int) *StatsCreate {
|
|
if i != nil {
|
|
sc.SetKast(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetFlashDurationSelf sets the "flash_duration_self" field.
|
|
func (sc *StatsCreate) SetFlashDurationSelf(f float32) *StatsCreate {
|
|
sc.mutation.SetFlashDurationSelf(f)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableFlashDurationSelf sets the "flash_duration_self" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableFlashDurationSelf(f *float32) *StatsCreate {
|
|
if f != nil {
|
|
sc.SetFlashDurationSelf(*f)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetFlashDurationTeam sets the "flash_duration_team" field.
|
|
func (sc *StatsCreate) SetFlashDurationTeam(f float32) *StatsCreate {
|
|
sc.mutation.SetFlashDurationTeam(f)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableFlashDurationTeam sets the "flash_duration_team" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableFlashDurationTeam(f *float32) *StatsCreate {
|
|
if f != nil {
|
|
sc.SetFlashDurationTeam(*f)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetFlashDurationEnemy sets the "flash_duration_enemy" field.
|
|
func (sc *StatsCreate) SetFlashDurationEnemy(f float32) *StatsCreate {
|
|
sc.mutation.SetFlashDurationEnemy(f)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableFlashDurationEnemy sets the "flash_duration_enemy" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableFlashDurationEnemy(f *float32) *StatsCreate {
|
|
if f != nil {
|
|
sc.SetFlashDurationEnemy(*f)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetFlashTotalSelf sets the "flash_total_self" field.
|
|
func (sc *StatsCreate) SetFlashTotalSelf(u uint) *StatsCreate {
|
|
sc.mutation.SetFlashTotalSelf(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableFlashTotalSelf sets the "flash_total_self" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableFlashTotalSelf(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetFlashTotalSelf(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetFlashTotalTeam sets the "flash_total_team" field.
|
|
func (sc *StatsCreate) SetFlashTotalTeam(u uint) *StatsCreate {
|
|
sc.mutation.SetFlashTotalTeam(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableFlashTotalTeam sets the "flash_total_team" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableFlashTotalTeam(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetFlashTotalTeam(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetFlashTotalEnemy sets the "flash_total_enemy" field.
|
|
func (sc *StatsCreate) SetFlashTotalEnemy(u uint) *StatsCreate {
|
|
sc.mutation.SetFlashTotalEnemy(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableFlashTotalEnemy sets the "flash_total_enemy" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableFlashTotalEnemy(u *uint) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetFlashTotalEnemy(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetMatchStats sets the "match_stats" field.
|
|
func (sc *StatsCreate) SetMatchStats(u uint64) *StatsCreate {
|
|
sc.mutation.SetMatchStats(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableMatchStats sets the "match_stats" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableMatchStats(u *uint64) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetMatchStats(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetPlayerStats sets the "player_stats" field.
|
|
func (sc *StatsCreate) SetPlayerStats(u uint64) *StatsCreate {
|
|
sc.mutation.SetPlayerStats(u)
|
|
return sc
|
|
}
|
|
|
|
// SetNillablePlayerStats sets the "player_stats" field if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillablePlayerStats(u *uint64) *StatsCreate {
|
|
if u != nil {
|
|
sc.SetPlayerStats(*u)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetMatchesID sets the "matches" edge to the Match entity by ID.
|
|
func (sc *StatsCreate) SetMatchesID(id uint64) *StatsCreate {
|
|
sc.mutation.SetMatchesID(id)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableMatchesID sets the "matches" edge to the Match entity by ID if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillableMatchesID(id *uint64) *StatsCreate {
|
|
if id != nil {
|
|
sc = sc.SetMatchesID(*id)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetMatches sets the "matches" edge to the Match entity.
|
|
func (sc *StatsCreate) SetMatches(m *Match) *StatsCreate {
|
|
return sc.SetMatchesID(m.ID)
|
|
}
|
|
|
|
// SetPlayersID sets the "players" edge to the Player entity by ID.
|
|
func (sc *StatsCreate) SetPlayersID(id uint64) *StatsCreate {
|
|
sc.mutation.SetPlayersID(id)
|
|
return sc
|
|
}
|
|
|
|
// SetNillablePlayersID sets the "players" edge to the Player entity by ID if the given value is not nil.
|
|
func (sc *StatsCreate) SetNillablePlayersID(id *uint64) *StatsCreate {
|
|
if id != nil {
|
|
sc = sc.SetPlayersID(*id)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetPlayers sets the "players" edge to the Player entity.
|
|
func (sc *StatsCreate) SetPlayers(p *Player) *StatsCreate {
|
|
return sc.SetPlayersID(p.ID)
|
|
}
|
|
|
|
// AddWeaponStatIDs adds the "weapon_stats" edge to the WeaponStats entity by IDs.
|
|
func (sc *StatsCreate) AddWeaponStatIDs(ids ...int) *StatsCreate {
|
|
sc.mutation.AddWeaponStatIDs(ids...)
|
|
return sc
|
|
}
|
|
|
|
// AddWeaponStats adds the "weapon_stats" edges to the WeaponStats entity.
|
|
func (sc *StatsCreate) AddWeaponStats(w ...*WeaponStats) *StatsCreate {
|
|
ids := make([]int, len(w))
|
|
for i := range w {
|
|
ids[i] = w[i].ID
|
|
}
|
|
return sc.AddWeaponStatIDs(ids...)
|
|
}
|
|
|
|
// AddRoundStatIDs adds the "round_stats" edge to the RoundStats entity by IDs.
|
|
func (sc *StatsCreate) AddRoundStatIDs(ids ...int) *StatsCreate {
|
|
sc.mutation.AddRoundStatIDs(ids...)
|
|
return sc
|
|
}
|
|
|
|
// AddRoundStats adds the "round_stats" edges to the RoundStats entity.
|
|
func (sc *StatsCreate) AddRoundStats(r ...*RoundStats) *StatsCreate {
|
|
ids := make([]int, len(r))
|
|
for i := range r {
|
|
ids[i] = r[i].ID
|
|
}
|
|
return sc.AddRoundStatIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the StatsMutation object of the builder.
|
|
func (sc *StatsCreate) Mutation() *StatsMutation {
|
|
return sc.mutation
|
|
}
|
|
|
|
// Save creates the Stats in the database.
|
|
func (sc *StatsCreate) Save(ctx context.Context) (*Stats, error) {
|
|
var (
|
|
err error
|
|
node *Stats
|
|
)
|
|
if len(sc.hooks) == 0 {
|
|
if err = sc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
node, err = sc.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*StatsMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err = sc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
sc.mutation = mutation
|
|
if node, err = sc.sqlSave(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &node.ID
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(sc.hooks) - 1; i >= 0; i-- {
|
|
if sc.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = sc.hooks[i](mut)
|
|
}
|
|
if _, err := mut.Mutate(ctx, sc.mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (sc *StatsCreate) SaveX(ctx context.Context) *Stats {
|
|
v, err := sc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sc *StatsCreate) Exec(ctx context.Context) error {
|
|
_, err := sc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sc *StatsCreate) ExecX(ctx context.Context) {
|
|
if err := sc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (sc *StatsCreate) check() error {
|
|
if _, ok := sc.mutation.TeamID(); !ok {
|
|
return &ValidationError{Name: "team_id", err: errors.New(`ent: missing required field "team_id"`)}
|
|
}
|
|
if _, ok := sc.mutation.Kills(); !ok {
|
|
return &ValidationError{Name: "kills", err: errors.New(`ent: missing required field "kills"`)}
|
|
}
|
|
if _, ok := sc.mutation.Deaths(); !ok {
|
|
return &ValidationError{Name: "deaths", err: errors.New(`ent: missing required field "deaths"`)}
|
|
}
|
|
if _, ok := sc.mutation.Assists(); !ok {
|
|
return &ValidationError{Name: "assists", err: errors.New(`ent: missing required field "assists"`)}
|
|
}
|
|
if _, ok := sc.mutation.Headshot(); !ok {
|
|
return &ValidationError{Name: "headshot", err: errors.New(`ent: missing required field "headshot"`)}
|
|
}
|
|
if _, ok := sc.mutation.Mvp(); !ok {
|
|
return &ValidationError{Name: "mvp", err: errors.New(`ent: missing required field "mvp"`)}
|
|
}
|
|
if _, ok := sc.mutation.Score(); !ok {
|
|
return &ValidationError{Name: "score", err: errors.New(`ent: missing required field "score"`)}
|
|
}
|
|
if v, ok := sc.mutation.Color(); ok {
|
|
if err := stats.ColorValidator(v); err != nil {
|
|
return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "color": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sc *StatsCreate) sqlSave(ctx context.Context) (*Stats, error) {
|
|
_node, _spec := sc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{err.Error(), err}
|
|
}
|
|
return nil, err
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
return _node, nil
|
|
}
|
|
|
|
func (sc *StatsCreate) createSpec() (*Stats, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Stats{config: sc.config}
|
|
_spec = &sqlgraph.CreateSpec{
|
|
Table: stats.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: stats.FieldID,
|
|
},
|
|
}
|
|
)
|
|
if value, ok := sc.mutation.TeamID(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldTeamID,
|
|
})
|
|
_node.TeamID = value
|
|
}
|
|
if value, ok := sc.mutation.Kills(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldKills,
|
|
})
|
|
_node.Kills = value
|
|
}
|
|
if value, ok := sc.mutation.Deaths(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldDeaths,
|
|
})
|
|
_node.Deaths = value
|
|
}
|
|
if value, ok := sc.mutation.Assists(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldAssists,
|
|
})
|
|
_node.Assists = value
|
|
}
|
|
if value, ok := sc.mutation.Headshot(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldHeadshot,
|
|
})
|
|
_node.Headshot = value
|
|
}
|
|
if value, ok := sc.mutation.Mvp(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldMvp,
|
|
})
|
|
_node.Mvp = value
|
|
}
|
|
if value, ok := sc.mutation.Score(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldScore,
|
|
})
|
|
_node.Score = value
|
|
}
|
|
if value, ok := sc.mutation.RankNew(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldRankNew,
|
|
})
|
|
_node.RankNew = value
|
|
}
|
|
if value, ok := sc.mutation.RankOld(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldRankOld,
|
|
})
|
|
_node.RankOld = value
|
|
}
|
|
if value, ok := sc.mutation.Mk2(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldMk2,
|
|
})
|
|
_node.Mk2 = value
|
|
}
|
|
if value, ok := sc.mutation.Mk3(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldMk3,
|
|
})
|
|
_node.Mk3 = value
|
|
}
|
|
if value, ok := sc.mutation.Mk4(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldMk4,
|
|
})
|
|
_node.Mk4 = value
|
|
}
|
|
if value, ok := sc.mutation.Mk5(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldMk5,
|
|
})
|
|
_node.Mk5 = value
|
|
}
|
|
if value, ok := sc.mutation.DmgEnemy(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldDmgEnemy,
|
|
})
|
|
_node.DmgEnemy = value
|
|
}
|
|
if value, ok := sc.mutation.DmgTeam(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldDmgTeam,
|
|
})
|
|
_node.DmgTeam = value
|
|
}
|
|
if value, ok := sc.mutation.UdHe(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldUdHe,
|
|
})
|
|
_node.UdHe = value
|
|
}
|
|
if value, ok := sc.mutation.UdFlames(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldUdFlames,
|
|
})
|
|
_node.UdFlames = value
|
|
}
|
|
if value, ok := sc.mutation.UdFlash(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldUdFlash,
|
|
})
|
|
_node.UdFlash = value
|
|
}
|
|
if value, ok := sc.mutation.UdDecoy(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldUdDecoy,
|
|
})
|
|
_node.UdDecoy = value
|
|
}
|
|
if value, ok := sc.mutation.UdSmoke(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldUdSmoke,
|
|
})
|
|
_node.UdSmoke = value
|
|
}
|
|
if value, ok := sc.mutation.Crosshair(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: stats.FieldCrosshair,
|
|
})
|
|
_node.Crosshair = value
|
|
}
|
|
if value, ok := sc.mutation.Color(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeEnum,
|
|
Value: value,
|
|
Column: stats.FieldColor,
|
|
})
|
|
_node.Color = value
|
|
}
|
|
if value, ok := sc.mutation.Kast(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: stats.FieldKast,
|
|
})
|
|
_node.Kast = value
|
|
}
|
|
if value, ok := sc.mutation.FlashDurationSelf(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeFloat32,
|
|
Value: value,
|
|
Column: stats.FieldFlashDurationSelf,
|
|
})
|
|
_node.FlashDurationSelf = value
|
|
}
|
|
if value, ok := sc.mutation.FlashDurationTeam(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeFloat32,
|
|
Value: value,
|
|
Column: stats.FieldFlashDurationTeam,
|
|
})
|
|
_node.FlashDurationTeam = value
|
|
}
|
|
if value, ok := sc.mutation.FlashDurationEnemy(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeFloat32,
|
|
Value: value,
|
|
Column: stats.FieldFlashDurationEnemy,
|
|
})
|
|
_node.FlashDurationEnemy = value
|
|
}
|
|
if value, ok := sc.mutation.FlashTotalSelf(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldFlashTotalSelf,
|
|
})
|
|
_node.FlashTotalSelf = value
|
|
}
|
|
if value, ok := sc.mutation.FlashTotalTeam(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldFlashTotalTeam,
|
|
})
|
|
_node.FlashTotalTeam = value
|
|
}
|
|
if value, ok := sc.mutation.FlashTotalEnemy(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: stats.FieldFlashTotalEnemy,
|
|
})
|
|
_node.FlashTotalEnemy = value
|
|
}
|
|
if nodes := sc.mutation.MatchesIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: stats.MatchesTable,
|
|
Columns: []string{stats.MatchesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint64,
|
|
Column: match.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.MatchStats = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := sc.mutation.PlayersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: stats.PlayersTable,
|
|
Columns: []string{stats.PlayersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint64,
|
|
Column: player.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.PlayerStats = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := sc.mutation.WeaponStatsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: stats.WeaponStatsTable,
|
|
Columns: []string{stats.WeaponStatsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: weaponstats.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := sc.mutation.RoundStatsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: stats.RoundStatsTable,
|
|
Columns: []string{stats.RoundStatsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: roundstats.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// StatsCreateBulk is the builder for creating many Stats entities in bulk.
|
|
type StatsCreateBulk struct {
|
|
config
|
|
builders []*StatsCreate
|
|
}
|
|
|
|
// Save creates the Stats entities in the database.
|
|
func (scb *StatsCreateBulk) Save(ctx context.Context) ([]*Stats, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
|
nodes := make([]*Stats, len(scb.builders))
|
|
mutators := make([]Mutator, len(scb.builders))
|
|
for i := range scb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := scb.builders[i]
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*StatsMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
var err error
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, scb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, scb.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{err.Error(), err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
mutation.done = true
|
|
if specs[i].ID.Value != nil {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int(id)
|
|
}
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, scb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (scb *StatsCreateBulk) SaveX(ctx context.Context) []*Stats {
|
|
v, err := scb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (scb *StatsCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := scb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (scb *StatsCreateBulk) ExecX(ctx context.Context) {
|
|
if err := scb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|