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