// Code generated by entc, DO NOT EDIT. package ent import ( "context" "csgowtfd/ent/match" "csgowtfd/ent/player" "csgowtfd/ent/predicate" "csgowtfd/ent/stats" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // MatchUpdate is the builder for updating Match entities. type MatchUpdate struct { config hooks []Hook mutation *MatchMutation } // 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 } // SetDemoExpired sets the "demo_expired" field. func (mu *MatchUpdate) SetDemoExpired(b bool) *MatchUpdate { mu.mutation.SetDemoExpired(b) return mu } // SetNillableDemoExpired sets the "demo_expired" field if the given value is not nil. func (mu *MatchUpdate) SetNillableDemoExpired(b *bool) *MatchUpdate { if b != nil { mu.SetDemoExpired(*b) } 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 } // SetEco sets the "eco" field. func (mu *MatchUpdate) SetEco(s struct { Rounds []*struct { Team int "json:\"team\"" Bank int "json:\"bank\"" Equipment int "json:\"equipment\"" } "json:\"rounds\"" }) *MatchUpdate { mu.mutation.SetEco(s) return mu } // SetNillableEco sets the "eco" field if the given value is not nil. func (mu *MatchUpdate) SetNillableEco(s *struct { Rounds []*struct { Team int "json:\"team\"" Bank int "json:\"bank\"" Equipment int "json:\"equipment\"" } "json:\"rounds\"" }) *MatchUpdate { if s != nil { mu.SetEco(*s) } return mu } // ClearEco clears the value of the "eco" field. func (mu *MatchUpdate) ClearEco() *MatchUpdate { mu.mutation.ClearEco() return mu } // AddStatIDs adds the "stats" edge to the Stats entity by IDs. func (mu *MatchUpdate) AddStatIDs(ids ...int) *MatchUpdate { mu.mutation.AddStatIDs(ids...) return mu } // AddStats adds the "stats" edges to the Stats entity. func (mu *MatchUpdate) AddStats(s ...*Stats) *MatchUpdate { ids := make([]int, len(s)) for i := range s { ids[i] = s[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 Stats entity. func (mu *MatchUpdate) ClearStats() *MatchUpdate { mu.mutation.ClearStats() return mu } // RemoveStatIDs removes the "stats" edge to Stats entities by IDs. func (mu *MatchUpdate) RemoveStatIDs(ids ...int) *MatchUpdate { mu.mutation.RemoveStatIDs(ids...) return mu } // RemoveStats removes "stats" edges to Stats entities. func (mu *MatchUpdate) RemoveStats(s ...*Stats) *MatchUpdate { ids := make([]int, len(s)) for i := range s { ids[i] = s[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) } } 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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: match.FieldShareCode, }) } if value, ok := mu.mutation.Map(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: match.FieldMap, }) } if mu.mutation.MapCleared() { _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ Type: field.TypeString, Column: match.FieldMap, }) } if value, ok := mu.mutation.Date(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, Column: match.FieldDate, }) } if value, ok := mu.mutation.ScoreTeamA(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldScoreTeamA, }) } if value, ok := mu.mutation.AddedScoreTeamA(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldScoreTeamA, }) } if value, ok := mu.mutation.ScoreTeamB(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldScoreTeamB, }) } if value, ok := mu.mutation.AddedScoreTeamB(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldScoreTeamB, }) } if value, ok := mu.mutation.ReplayURL(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: match.FieldReplayURL, }) } if mu.mutation.ReplayURLCleared() { _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ Type: field.TypeString, Column: match.FieldReplayURL, }) } if value, ok := mu.mutation.Duration(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldDuration, }) } if value, ok := mu.mutation.AddedDuration(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldDuration, }) } if value, ok := mu.mutation.MatchResult(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldMatchResult, }) } if value, ok := mu.mutation.AddedMatchResult(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldMatchResult, }) } if value, ok := mu.mutation.MaxRounds(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldMaxRounds, }) } if value, ok := mu.mutation.AddedMaxRounds(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldMaxRounds, }) } if value, ok := mu.mutation.DemoExpired(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: match.FieldDemoExpired, }) } if value, ok := mu.mutation.DemoParsed(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: match.FieldDemoParsed, }) } if value, ok := mu.mutation.Eco(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeJSON, Value: value, Column: match.FieldEco, }) } if mu.mutation.EcoCleared() { _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ Type: field.TypeJSON, Column: match.FieldEco, }) } 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: stats.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: stats.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: stats.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) } 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{err.Error(), 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 } // 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 } // SetDemoExpired sets the "demo_expired" field. func (muo *MatchUpdateOne) SetDemoExpired(b bool) *MatchUpdateOne { muo.mutation.SetDemoExpired(b) return muo } // SetNillableDemoExpired sets the "demo_expired" field if the given value is not nil. func (muo *MatchUpdateOne) SetNillableDemoExpired(b *bool) *MatchUpdateOne { if b != nil { muo.SetDemoExpired(*b) } 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 } // SetEco sets the "eco" field. func (muo *MatchUpdateOne) SetEco(s struct { Rounds []*struct { Team int "json:\"team\"" Bank int "json:\"bank\"" Equipment int "json:\"equipment\"" } "json:\"rounds\"" }) *MatchUpdateOne { muo.mutation.SetEco(s) return muo } // SetNillableEco sets the "eco" field if the given value is not nil. func (muo *MatchUpdateOne) SetNillableEco(s *struct { Rounds []*struct { Team int "json:\"team\"" Bank int "json:\"bank\"" Equipment int "json:\"equipment\"" } "json:\"rounds\"" }) *MatchUpdateOne { if s != nil { muo.SetEco(*s) } return muo } // ClearEco clears the value of the "eco" field. func (muo *MatchUpdateOne) ClearEco() *MatchUpdateOne { muo.mutation.ClearEco() return muo } // AddStatIDs adds the "stats" edge to the Stats entity by IDs. func (muo *MatchUpdateOne) AddStatIDs(ids ...int) *MatchUpdateOne { muo.mutation.AddStatIDs(ids...) return muo } // AddStats adds the "stats" edges to the Stats entity. func (muo *MatchUpdateOne) AddStats(s ...*Stats) *MatchUpdateOne { ids := make([]int, len(s)) for i := range s { ids[i] = s[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 Stats entity. func (muo *MatchUpdateOne) ClearStats() *MatchUpdateOne { muo.mutation.ClearStats() return muo } // RemoveStatIDs removes the "stats" edge to Stats entities by IDs. func (muo *MatchUpdateOne) RemoveStatIDs(ids ...int) *MatchUpdateOne { muo.mutation.RemoveStatIDs(ids...) return muo } // RemoveStats removes "stats" edges to Stats entities. func (muo *MatchUpdateOne) RemoveStats(s ...*Stats) *MatchUpdateOne { ids := make([]int, len(s)) for i := range s { ids[i] = s[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) } if _, err := mut.Mutate(ctx, muo.mutation); err != nil { return nil, err } } 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) } } 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: fmt.Errorf("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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: match.FieldShareCode, }) } if value, ok := muo.mutation.Map(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: match.FieldMap, }) } if muo.mutation.MapCleared() { _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ Type: field.TypeString, Column: match.FieldMap, }) } if value, ok := muo.mutation.Date(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, Column: match.FieldDate, }) } if value, ok := muo.mutation.ScoreTeamA(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldScoreTeamA, }) } if value, ok := muo.mutation.AddedScoreTeamA(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldScoreTeamA, }) } if value, ok := muo.mutation.ScoreTeamB(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldScoreTeamB, }) } if value, ok := muo.mutation.AddedScoreTeamB(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldScoreTeamB, }) } if value, ok := muo.mutation.ReplayURL(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: match.FieldReplayURL, }) } if muo.mutation.ReplayURLCleared() { _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ Type: field.TypeString, Column: match.FieldReplayURL, }) } if value, ok := muo.mutation.Duration(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldDuration, }) } if value, ok := muo.mutation.AddedDuration(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldDuration, }) } if value, ok := muo.mutation.MatchResult(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldMatchResult, }) } if value, ok := muo.mutation.AddedMatchResult(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldMatchResult, }) } if value, ok := muo.mutation.MaxRounds(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldMaxRounds, }) } if value, ok := muo.mutation.AddedMaxRounds(); ok { _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ Type: field.TypeInt, Value: value, Column: match.FieldMaxRounds, }) } if value, ok := muo.mutation.DemoExpired(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: match.FieldDemoExpired, }) } if value, ok := muo.mutation.DemoParsed(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: match.FieldDemoParsed, }) } if value, ok := muo.mutation.Eco(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeJSON, Value: value, Column: match.FieldEco, }) } if muo.mutation.EcoCleared() { _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ Type: field.TypeJSON, Column: match.FieldEco, }) } 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: stats.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: stats.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: stats.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) } _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{err.Error(), err} } return nil, err } return _node, nil }