Files
csgowtfd/ent/match_update.go

1165 lines
32 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"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/player"
"git.harting.dev/csgowtf/csgowtfd/ent/predicate"
)
// MatchUpdate is the builder for updating Match entities.
type MatchUpdate struct {
config
hooks []Hook
mutation *MatchMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the MatchUpdate builder.
func (mu *MatchUpdate) Where(ps ...predicate.Match) *MatchUpdate {
mu.mutation.Where(ps...)
return mu
}
// SetShareCode sets the "share_code" field.
func (mu *MatchUpdate) SetShareCode(s string) *MatchUpdate {
mu.mutation.SetShareCode(s)
return mu
}
// SetMap sets the "map" field.
func (mu *MatchUpdate) SetMap(s string) *MatchUpdate {
mu.mutation.SetMap(s)
return mu
}
// SetNillableMap sets the "map" field if the given value is not nil.
func (mu *MatchUpdate) SetNillableMap(s *string) *MatchUpdate {
if s != nil {
mu.SetMap(*s)
}
return mu
}
// ClearMap clears the value of the "map" field.
func (mu *MatchUpdate) ClearMap() *MatchUpdate {
mu.mutation.ClearMap()
return mu
}
// SetDate sets the "date" field.
func (mu *MatchUpdate) SetDate(t time.Time) *MatchUpdate {
mu.mutation.SetDate(t)
return mu
}
// SetScoreTeamA sets the "score_team_a" field.
func (mu *MatchUpdate) SetScoreTeamA(i int) *MatchUpdate {
mu.mutation.ResetScoreTeamA()
mu.mutation.SetScoreTeamA(i)
return mu
}
// AddScoreTeamA adds i to the "score_team_a" field.
func (mu *MatchUpdate) AddScoreTeamA(i int) *MatchUpdate {
mu.mutation.AddScoreTeamA(i)
return mu
}
// SetScoreTeamB sets the "score_team_b" field.
func (mu *MatchUpdate) SetScoreTeamB(i int) *MatchUpdate {
mu.mutation.ResetScoreTeamB()
mu.mutation.SetScoreTeamB(i)
return mu
}
// AddScoreTeamB adds i to the "score_team_b" field.
func (mu *MatchUpdate) AddScoreTeamB(i int) *MatchUpdate {
mu.mutation.AddScoreTeamB(i)
return mu
}
// SetReplayURL sets the "replay_url" field.
func (mu *MatchUpdate) SetReplayURL(s string) *MatchUpdate {
mu.mutation.SetReplayURL(s)
return mu
}
// SetNillableReplayURL sets the "replay_url" field if the given value is not nil.
func (mu *MatchUpdate) SetNillableReplayURL(s *string) *MatchUpdate {
if s != nil {
mu.SetReplayURL(*s)
}
return mu
}
// ClearReplayURL clears the value of the "replay_url" field.
func (mu *MatchUpdate) ClearReplayURL() *MatchUpdate {
mu.mutation.ClearReplayURL()
return mu
}
// SetDuration sets the "duration" field.
func (mu *MatchUpdate) SetDuration(i int) *MatchUpdate {
mu.mutation.ResetDuration()
mu.mutation.SetDuration(i)
return mu
}
// AddDuration adds i to the "duration" field.
func (mu *MatchUpdate) AddDuration(i int) *MatchUpdate {
mu.mutation.AddDuration(i)
return mu
}
// SetMatchResult sets the "match_result" field.
func (mu *MatchUpdate) SetMatchResult(i int) *MatchUpdate {
mu.mutation.ResetMatchResult()
mu.mutation.SetMatchResult(i)
return mu
}
// AddMatchResult adds i to the "match_result" field.
func (mu *MatchUpdate) AddMatchResult(i int) *MatchUpdate {
mu.mutation.AddMatchResult(i)
return mu
}
// SetMaxRounds sets the "max_rounds" field.
func (mu *MatchUpdate) SetMaxRounds(i int) *MatchUpdate {
mu.mutation.ResetMaxRounds()
mu.mutation.SetMaxRounds(i)
return mu
}
// AddMaxRounds adds i to the "max_rounds" field.
func (mu *MatchUpdate) AddMaxRounds(i int) *MatchUpdate {
mu.mutation.AddMaxRounds(i)
return mu
}
// SetDemoParsed sets the "demo_parsed" field.
func (mu *MatchUpdate) SetDemoParsed(b bool) *MatchUpdate {
mu.mutation.SetDemoParsed(b)
return mu
}
// SetNillableDemoParsed sets the "demo_parsed" field if the given value is not nil.
func (mu *MatchUpdate) SetNillableDemoParsed(b *bool) *MatchUpdate {
if b != nil {
mu.SetDemoParsed(*b)
}
return mu
}
// SetVacPresent sets the "vac_present" field.
func (mu *MatchUpdate) SetVacPresent(b bool) *MatchUpdate {
mu.mutation.SetVacPresent(b)
return mu
}
// SetNillableVacPresent sets the "vac_present" field if the given value is not nil.
func (mu *MatchUpdate) SetNillableVacPresent(b *bool) *MatchUpdate {
if b != nil {
mu.SetVacPresent(*b)
}
return mu
}
// SetGamebanPresent sets the "gameban_present" field.
func (mu *MatchUpdate) SetGamebanPresent(b bool) *MatchUpdate {
mu.mutation.SetGamebanPresent(b)
return mu
}
// SetNillableGamebanPresent sets the "gameban_present" field if the given value is not nil.
func (mu *MatchUpdate) SetNillableGamebanPresent(b *bool) *MatchUpdate {
if b != nil {
mu.SetGamebanPresent(*b)
}
return mu
}
// SetDecryptionKey sets the "decryption_key" field.
func (mu *MatchUpdate) SetDecryptionKey(b []byte) *MatchUpdate {
mu.mutation.SetDecryptionKey(b)
return mu
}
// ClearDecryptionKey clears the value of the "decryption_key" field.
func (mu *MatchUpdate) ClearDecryptionKey() *MatchUpdate {
mu.mutation.ClearDecryptionKey()
return mu
}
// SetTickRate sets the "tick_rate" field.
func (mu *MatchUpdate) SetTickRate(f float64) *MatchUpdate {
mu.mutation.ResetTickRate()
mu.mutation.SetTickRate(f)
return mu
}
// SetNillableTickRate sets the "tick_rate" field if the given value is not nil.
func (mu *MatchUpdate) SetNillableTickRate(f *float64) *MatchUpdate {
if f != nil {
mu.SetTickRate(*f)
}
return mu
}
// AddTickRate adds f to the "tick_rate" field.
func (mu *MatchUpdate) AddTickRate(f float64) *MatchUpdate {
mu.mutation.AddTickRate(f)
return mu
}
// ClearTickRate clears the value of the "tick_rate" field.
func (mu *MatchUpdate) ClearTickRate() *MatchUpdate {
mu.mutation.ClearTickRate()
return mu
}
// AddStatIDs adds the "stats" edge to the MatchPlayer entity by IDs.
func (mu *MatchUpdate) AddStatIDs(ids ...int) *MatchUpdate {
mu.mutation.AddStatIDs(ids...)
return mu
}
// AddStats adds the "stats" edges to the MatchPlayer entity.
func (mu *MatchUpdate) AddStats(m ...*MatchPlayer) *MatchUpdate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return mu.AddStatIDs(ids...)
}
// AddPlayerIDs adds the "players" edge to the Player entity by IDs.
func (mu *MatchUpdate) AddPlayerIDs(ids ...uint64) *MatchUpdate {
mu.mutation.AddPlayerIDs(ids...)
return mu
}
// AddPlayers adds the "players" edges to the Player entity.
func (mu *MatchUpdate) AddPlayers(p ...*Player) *MatchUpdate {
ids := make([]uint64, len(p))
for i := range p {
ids[i] = p[i].ID
}
return mu.AddPlayerIDs(ids...)
}
// Mutation returns the MatchMutation object of the builder.
func (mu *MatchUpdate) Mutation() *MatchMutation {
return mu.mutation
}
// ClearStats clears all "stats" edges to the MatchPlayer entity.
func (mu *MatchUpdate) ClearStats() *MatchUpdate {
mu.mutation.ClearStats()
return mu
}
// RemoveStatIDs removes the "stats" edge to MatchPlayer entities by IDs.
func (mu *MatchUpdate) RemoveStatIDs(ids ...int) *MatchUpdate {
mu.mutation.RemoveStatIDs(ids...)
return mu
}
// RemoveStats removes "stats" edges to MatchPlayer entities.
func (mu *MatchUpdate) RemoveStats(m ...*MatchPlayer) *MatchUpdate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return mu.RemoveStatIDs(ids...)
}
// ClearPlayers clears all "players" edges to the Player entity.
func (mu *MatchUpdate) ClearPlayers() *MatchUpdate {
mu.mutation.ClearPlayers()
return mu
}
// RemovePlayerIDs removes the "players" edge to Player entities by IDs.
func (mu *MatchUpdate) RemovePlayerIDs(ids ...uint64) *MatchUpdate {
mu.mutation.RemovePlayerIDs(ids...)
return mu
}
// RemovePlayers removes "players" edges to Player entities.
func (mu *MatchUpdate) RemovePlayers(p ...*Player) *MatchUpdate {
ids := make([]uint64, len(p))
for i := range p {
ids[i] = p[i].ID
}
return mu.RemovePlayerIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (mu *MatchUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(mu.hooks) == 0 {
affected, err = mu.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*MatchMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
mu.mutation = mutation
affected, err = mu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(mu.hooks) - 1; i >= 0; i-- {
if mu.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = mu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, mu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (mu *MatchUpdate) SaveX(ctx context.Context) int {
affected, err := mu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (mu *MatchUpdate) Exec(ctx context.Context) error {
_, err := mu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (mu *MatchUpdate) ExecX(ctx context.Context) {
if err := mu.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (mu *MatchUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MatchUpdate {
mu.modifiers = append(mu.modifiers, modifiers...)
return mu
}
func (mu *MatchUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: match.Table,
Columns: match.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Column: match.FieldID,
},
},
}
if ps := mu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := mu.mutation.ShareCode(); ok {
_spec.SetField(match.FieldShareCode, field.TypeString, value)
}
if value, ok := mu.mutation.Map(); ok {
_spec.SetField(match.FieldMap, field.TypeString, value)
}
if mu.mutation.MapCleared() {
_spec.ClearField(match.FieldMap, field.TypeString)
}
if value, ok := mu.mutation.Date(); ok {
_spec.SetField(match.FieldDate, field.TypeTime, value)
}
if value, ok := mu.mutation.ScoreTeamA(); ok {
_spec.SetField(match.FieldScoreTeamA, field.TypeInt, value)
}
if value, ok := mu.mutation.AddedScoreTeamA(); ok {
_spec.AddField(match.FieldScoreTeamA, field.TypeInt, value)
}
if value, ok := mu.mutation.ScoreTeamB(); ok {
_spec.SetField(match.FieldScoreTeamB, field.TypeInt, value)
}
if value, ok := mu.mutation.AddedScoreTeamB(); ok {
_spec.AddField(match.FieldScoreTeamB, field.TypeInt, value)
}
if value, ok := mu.mutation.ReplayURL(); ok {
_spec.SetField(match.FieldReplayURL, field.TypeString, value)
}
if mu.mutation.ReplayURLCleared() {
_spec.ClearField(match.FieldReplayURL, field.TypeString)
}
if value, ok := mu.mutation.Duration(); ok {
_spec.SetField(match.FieldDuration, field.TypeInt, value)
}
if value, ok := mu.mutation.AddedDuration(); ok {
_spec.AddField(match.FieldDuration, field.TypeInt, value)
}
if value, ok := mu.mutation.MatchResult(); ok {
_spec.SetField(match.FieldMatchResult, field.TypeInt, value)
}
if value, ok := mu.mutation.AddedMatchResult(); ok {
_spec.AddField(match.FieldMatchResult, field.TypeInt, value)
}
if value, ok := mu.mutation.MaxRounds(); ok {
_spec.SetField(match.FieldMaxRounds, field.TypeInt, value)
}
if value, ok := mu.mutation.AddedMaxRounds(); ok {
_spec.AddField(match.FieldMaxRounds, field.TypeInt, value)
}
if value, ok := mu.mutation.DemoParsed(); ok {
_spec.SetField(match.FieldDemoParsed, field.TypeBool, value)
}
if value, ok := mu.mutation.VacPresent(); ok {
_spec.SetField(match.FieldVacPresent, field.TypeBool, value)
}
if value, ok := mu.mutation.GamebanPresent(); ok {
_spec.SetField(match.FieldGamebanPresent, field.TypeBool, value)
}
if value, ok := mu.mutation.DecryptionKey(); ok {
_spec.SetField(match.FieldDecryptionKey, field.TypeBytes, value)
}
if mu.mutation.DecryptionKeyCleared() {
_spec.ClearField(match.FieldDecryptionKey, field.TypeBytes)
}
if value, ok := mu.mutation.TickRate(); ok {
_spec.SetField(match.FieldTickRate, field.TypeFloat64, value)
}
if value, ok := mu.mutation.AddedTickRate(); ok {
_spec.AddField(match.FieldTickRate, field.TypeFloat64, value)
}
if mu.mutation.TickRateCleared() {
_spec.ClearField(match.FieldTickRate, field.TypeFloat64)
}
if mu.mutation.StatsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: match.StatsTable,
Columns: []string{match.StatsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := mu.mutation.RemovedStatsIDs(); len(nodes) > 0 && !mu.mutation.StatsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: match.StatsTable,
Columns: []string{match.StatsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := mu.mutation.StatsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: match.StatsTable,
Columns: []string{match.StatsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if mu.mutation.PlayersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: match.PlayersTable,
Columns: match.PlayersPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Column: player.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := mu.mutation.RemovedPlayersIDs(); len(nodes) > 0 && !mu.mutation.PlayersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: match.PlayersTable,
Columns: match.PlayersPrimaryKey,
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)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := mu.mutation.PlayersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: match.PlayersTable,
Columns: match.PlayersPrimaryKey,
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)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(mu.modifiers...)
if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{match.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
return n, nil
}
// MatchUpdateOne is the builder for updating a single Match entity.
type MatchUpdateOne struct {
config
fields []string
hooks []Hook
mutation *MatchMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetShareCode sets the "share_code" field.
func (muo *MatchUpdateOne) SetShareCode(s string) *MatchUpdateOne {
muo.mutation.SetShareCode(s)
return muo
}
// SetMap sets the "map" field.
func (muo *MatchUpdateOne) SetMap(s string) *MatchUpdateOne {
muo.mutation.SetMap(s)
return muo
}
// SetNillableMap sets the "map" field if the given value is not nil.
func (muo *MatchUpdateOne) SetNillableMap(s *string) *MatchUpdateOne {
if s != nil {
muo.SetMap(*s)
}
return muo
}
// ClearMap clears the value of the "map" field.
func (muo *MatchUpdateOne) ClearMap() *MatchUpdateOne {
muo.mutation.ClearMap()
return muo
}
// SetDate sets the "date" field.
func (muo *MatchUpdateOne) SetDate(t time.Time) *MatchUpdateOne {
muo.mutation.SetDate(t)
return muo
}
// SetScoreTeamA sets the "score_team_a" field.
func (muo *MatchUpdateOne) SetScoreTeamA(i int) *MatchUpdateOne {
muo.mutation.ResetScoreTeamA()
muo.mutation.SetScoreTeamA(i)
return muo
}
// AddScoreTeamA adds i to the "score_team_a" field.
func (muo *MatchUpdateOne) AddScoreTeamA(i int) *MatchUpdateOne {
muo.mutation.AddScoreTeamA(i)
return muo
}
// SetScoreTeamB sets the "score_team_b" field.
func (muo *MatchUpdateOne) SetScoreTeamB(i int) *MatchUpdateOne {
muo.mutation.ResetScoreTeamB()
muo.mutation.SetScoreTeamB(i)
return muo
}
// AddScoreTeamB adds i to the "score_team_b" field.
func (muo *MatchUpdateOne) AddScoreTeamB(i int) *MatchUpdateOne {
muo.mutation.AddScoreTeamB(i)
return muo
}
// SetReplayURL sets the "replay_url" field.
func (muo *MatchUpdateOne) SetReplayURL(s string) *MatchUpdateOne {
muo.mutation.SetReplayURL(s)
return muo
}
// SetNillableReplayURL sets the "replay_url" field if the given value is not nil.
func (muo *MatchUpdateOne) SetNillableReplayURL(s *string) *MatchUpdateOne {
if s != nil {
muo.SetReplayURL(*s)
}
return muo
}
// ClearReplayURL clears the value of the "replay_url" field.
func (muo *MatchUpdateOne) ClearReplayURL() *MatchUpdateOne {
muo.mutation.ClearReplayURL()
return muo
}
// SetDuration sets the "duration" field.
func (muo *MatchUpdateOne) SetDuration(i int) *MatchUpdateOne {
muo.mutation.ResetDuration()
muo.mutation.SetDuration(i)
return muo
}
// AddDuration adds i to the "duration" field.
func (muo *MatchUpdateOne) AddDuration(i int) *MatchUpdateOne {
muo.mutation.AddDuration(i)
return muo
}
// SetMatchResult sets the "match_result" field.
func (muo *MatchUpdateOne) SetMatchResult(i int) *MatchUpdateOne {
muo.mutation.ResetMatchResult()
muo.mutation.SetMatchResult(i)
return muo
}
// AddMatchResult adds i to the "match_result" field.
func (muo *MatchUpdateOne) AddMatchResult(i int) *MatchUpdateOne {
muo.mutation.AddMatchResult(i)
return muo
}
// SetMaxRounds sets the "max_rounds" field.
func (muo *MatchUpdateOne) SetMaxRounds(i int) *MatchUpdateOne {
muo.mutation.ResetMaxRounds()
muo.mutation.SetMaxRounds(i)
return muo
}
// AddMaxRounds adds i to the "max_rounds" field.
func (muo *MatchUpdateOne) AddMaxRounds(i int) *MatchUpdateOne {
muo.mutation.AddMaxRounds(i)
return muo
}
// SetDemoParsed sets the "demo_parsed" field.
func (muo *MatchUpdateOne) SetDemoParsed(b bool) *MatchUpdateOne {
muo.mutation.SetDemoParsed(b)
return muo
}
// SetNillableDemoParsed sets the "demo_parsed" field if the given value is not nil.
func (muo *MatchUpdateOne) SetNillableDemoParsed(b *bool) *MatchUpdateOne {
if b != nil {
muo.SetDemoParsed(*b)
}
return muo
}
// SetVacPresent sets the "vac_present" field.
func (muo *MatchUpdateOne) SetVacPresent(b bool) *MatchUpdateOne {
muo.mutation.SetVacPresent(b)
return muo
}
// SetNillableVacPresent sets the "vac_present" field if the given value is not nil.
func (muo *MatchUpdateOne) SetNillableVacPresent(b *bool) *MatchUpdateOne {
if b != nil {
muo.SetVacPresent(*b)
}
return muo
}
// SetGamebanPresent sets the "gameban_present" field.
func (muo *MatchUpdateOne) SetGamebanPresent(b bool) *MatchUpdateOne {
muo.mutation.SetGamebanPresent(b)
return muo
}
// SetNillableGamebanPresent sets the "gameban_present" field if the given value is not nil.
func (muo *MatchUpdateOne) SetNillableGamebanPresent(b *bool) *MatchUpdateOne {
if b != nil {
muo.SetGamebanPresent(*b)
}
return muo
}
// SetDecryptionKey sets the "decryption_key" field.
func (muo *MatchUpdateOne) SetDecryptionKey(b []byte) *MatchUpdateOne {
muo.mutation.SetDecryptionKey(b)
return muo
}
// ClearDecryptionKey clears the value of the "decryption_key" field.
func (muo *MatchUpdateOne) ClearDecryptionKey() *MatchUpdateOne {
muo.mutation.ClearDecryptionKey()
return muo
}
// SetTickRate sets the "tick_rate" field.
func (muo *MatchUpdateOne) SetTickRate(f float64) *MatchUpdateOne {
muo.mutation.ResetTickRate()
muo.mutation.SetTickRate(f)
return muo
}
// SetNillableTickRate sets the "tick_rate" field if the given value is not nil.
func (muo *MatchUpdateOne) SetNillableTickRate(f *float64) *MatchUpdateOne {
if f != nil {
muo.SetTickRate(*f)
}
return muo
}
// AddTickRate adds f to the "tick_rate" field.
func (muo *MatchUpdateOne) AddTickRate(f float64) *MatchUpdateOne {
muo.mutation.AddTickRate(f)
return muo
}
// ClearTickRate clears the value of the "tick_rate" field.
func (muo *MatchUpdateOne) ClearTickRate() *MatchUpdateOne {
muo.mutation.ClearTickRate()
return muo
}
// AddStatIDs adds the "stats" edge to the MatchPlayer entity by IDs.
func (muo *MatchUpdateOne) AddStatIDs(ids ...int) *MatchUpdateOne {
muo.mutation.AddStatIDs(ids...)
return muo
}
// AddStats adds the "stats" edges to the MatchPlayer entity.
func (muo *MatchUpdateOne) AddStats(m ...*MatchPlayer) *MatchUpdateOne {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return muo.AddStatIDs(ids...)
}
// AddPlayerIDs adds the "players" edge to the Player entity by IDs.
func (muo *MatchUpdateOne) AddPlayerIDs(ids ...uint64) *MatchUpdateOne {
muo.mutation.AddPlayerIDs(ids...)
return muo
}
// AddPlayers adds the "players" edges to the Player entity.
func (muo *MatchUpdateOne) AddPlayers(p ...*Player) *MatchUpdateOne {
ids := make([]uint64, len(p))
for i := range p {
ids[i] = p[i].ID
}
return muo.AddPlayerIDs(ids...)
}
// Mutation returns the MatchMutation object of the builder.
func (muo *MatchUpdateOne) Mutation() *MatchMutation {
return muo.mutation
}
// ClearStats clears all "stats" edges to the MatchPlayer entity.
func (muo *MatchUpdateOne) ClearStats() *MatchUpdateOne {
muo.mutation.ClearStats()
return muo
}
// RemoveStatIDs removes the "stats" edge to MatchPlayer entities by IDs.
func (muo *MatchUpdateOne) RemoveStatIDs(ids ...int) *MatchUpdateOne {
muo.mutation.RemoveStatIDs(ids...)
return muo
}
// RemoveStats removes "stats" edges to MatchPlayer entities.
func (muo *MatchUpdateOne) RemoveStats(m ...*MatchPlayer) *MatchUpdateOne {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return muo.RemoveStatIDs(ids...)
}
// ClearPlayers clears all "players" edges to the Player entity.
func (muo *MatchUpdateOne) ClearPlayers() *MatchUpdateOne {
muo.mutation.ClearPlayers()
return muo
}
// RemovePlayerIDs removes the "players" edge to Player entities by IDs.
func (muo *MatchUpdateOne) RemovePlayerIDs(ids ...uint64) *MatchUpdateOne {
muo.mutation.RemovePlayerIDs(ids...)
return muo
}
// RemovePlayers removes "players" edges to Player entities.
func (muo *MatchUpdateOne) RemovePlayers(p ...*Player) *MatchUpdateOne {
ids := make([]uint64, len(p))
for i := range p {
ids[i] = p[i].ID
}
return muo.RemovePlayerIDs(ids...)
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (muo *MatchUpdateOne) Select(field string, fields ...string) *MatchUpdateOne {
muo.fields = append([]string{field}, fields...)
return muo
}
// Save executes the query and returns the updated Match entity.
func (muo *MatchUpdateOne) Save(ctx context.Context) (*Match, error) {
var (
err error
node *Match
)
if len(muo.hooks) == 0 {
node, err = muo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*MatchMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
muo.mutation = mutation
node, err = muo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(muo.hooks) - 1; i >= 0; i-- {
if muo.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = muo.hooks[i](mut)
}
v, err := mut.Mutate(ctx, muo.mutation)
if err != nil {
return nil, err
}
nv, ok := v.(*Match)
if !ok {
return nil, fmt.Errorf("unexpected node type %T returned from MatchMutation", v)
}
node = nv
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (muo *MatchUpdateOne) SaveX(ctx context.Context) *Match {
node, err := muo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (muo *MatchUpdateOne) Exec(ctx context.Context) error {
_, err := muo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (muo *MatchUpdateOne) ExecX(ctx context.Context) {
if err := muo.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (muo *MatchUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MatchUpdateOne {
muo.modifiers = append(muo.modifiers, modifiers...)
return muo
}
func (muo *MatchUpdateOne) sqlSave(ctx context.Context) (_node *Match, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: match.Table,
Columns: match.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Column: match.FieldID,
},
},
}
id, ok := muo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Match.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := muo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, match.FieldID)
for _, f := range fields {
if !match.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != match.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := muo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := muo.mutation.ShareCode(); ok {
_spec.SetField(match.FieldShareCode, field.TypeString, value)
}
if value, ok := muo.mutation.Map(); ok {
_spec.SetField(match.FieldMap, field.TypeString, value)
}
if muo.mutation.MapCleared() {
_spec.ClearField(match.FieldMap, field.TypeString)
}
if value, ok := muo.mutation.Date(); ok {
_spec.SetField(match.FieldDate, field.TypeTime, value)
}
if value, ok := muo.mutation.ScoreTeamA(); ok {
_spec.SetField(match.FieldScoreTeamA, field.TypeInt, value)
}
if value, ok := muo.mutation.AddedScoreTeamA(); ok {
_spec.AddField(match.FieldScoreTeamA, field.TypeInt, value)
}
if value, ok := muo.mutation.ScoreTeamB(); ok {
_spec.SetField(match.FieldScoreTeamB, field.TypeInt, value)
}
if value, ok := muo.mutation.AddedScoreTeamB(); ok {
_spec.AddField(match.FieldScoreTeamB, field.TypeInt, value)
}
if value, ok := muo.mutation.ReplayURL(); ok {
_spec.SetField(match.FieldReplayURL, field.TypeString, value)
}
if muo.mutation.ReplayURLCleared() {
_spec.ClearField(match.FieldReplayURL, field.TypeString)
}
if value, ok := muo.mutation.Duration(); ok {
_spec.SetField(match.FieldDuration, field.TypeInt, value)
}
if value, ok := muo.mutation.AddedDuration(); ok {
_spec.AddField(match.FieldDuration, field.TypeInt, value)
}
if value, ok := muo.mutation.MatchResult(); ok {
_spec.SetField(match.FieldMatchResult, field.TypeInt, value)
}
if value, ok := muo.mutation.AddedMatchResult(); ok {
_spec.AddField(match.FieldMatchResult, field.TypeInt, value)
}
if value, ok := muo.mutation.MaxRounds(); ok {
_spec.SetField(match.FieldMaxRounds, field.TypeInt, value)
}
if value, ok := muo.mutation.AddedMaxRounds(); ok {
_spec.AddField(match.FieldMaxRounds, field.TypeInt, value)
}
if value, ok := muo.mutation.DemoParsed(); ok {
_spec.SetField(match.FieldDemoParsed, field.TypeBool, value)
}
if value, ok := muo.mutation.VacPresent(); ok {
_spec.SetField(match.FieldVacPresent, field.TypeBool, value)
}
if value, ok := muo.mutation.GamebanPresent(); ok {
_spec.SetField(match.FieldGamebanPresent, field.TypeBool, value)
}
if value, ok := muo.mutation.DecryptionKey(); ok {
_spec.SetField(match.FieldDecryptionKey, field.TypeBytes, value)
}
if muo.mutation.DecryptionKeyCleared() {
_spec.ClearField(match.FieldDecryptionKey, field.TypeBytes)
}
if value, ok := muo.mutation.TickRate(); ok {
_spec.SetField(match.FieldTickRate, field.TypeFloat64, value)
}
if value, ok := muo.mutation.AddedTickRate(); ok {
_spec.AddField(match.FieldTickRate, field.TypeFloat64, value)
}
if muo.mutation.TickRateCleared() {
_spec.ClearField(match.FieldTickRate, field.TypeFloat64)
}
if muo.mutation.StatsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: match.StatsTable,
Columns: []string{match.StatsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := muo.mutation.RemovedStatsIDs(); len(nodes) > 0 && !muo.mutation.StatsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: match.StatsTable,
Columns: []string{match.StatsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := muo.mutation.StatsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: match.StatsTable,
Columns: []string{match.StatsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if muo.mutation.PlayersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: match.PlayersTable,
Columns: match.PlayersPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Column: player.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := muo.mutation.RemovedPlayersIDs(); len(nodes) > 0 && !muo.mutation.PlayersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: match.PlayersTable,
Columns: match.PlayersPrimaryKey,
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)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := muo.mutation.PlayersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: match.PlayersTable,
Columns: match.PlayersPrimaryKey,
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)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(muo.modifiers...)
_node = &Match{config: muo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{match.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
return _node, nil
}