Files
csgowtfd/ent/roundstats_update.go
2025-10-26 05:09:47 +01:00

517 lines
15 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"somegit.dev/csgowtf/csgowtfd/ent/matchplayer"
"somegit.dev/csgowtf/csgowtfd/ent/predicate"
"somegit.dev/csgowtf/csgowtfd/ent/roundstats"
)
// RoundStatsUpdate is the builder for updating RoundStats entities.
type RoundStatsUpdate struct {
config
hooks []Hook
mutation *RoundStatsMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the RoundStatsUpdate builder.
func (_u *RoundStatsUpdate) Where(ps ...predicate.RoundStats) *RoundStatsUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetRound sets the "round" field.
func (_u *RoundStatsUpdate) SetRound(v uint) *RoundStatsUpdate {
_u.mutation.ResetRound()
_u.mutation.SetRound(v)
return _u
}
// SetNillableRound sets the "round" field if the given value is not nil.
func (_u *RoundStatsUpdate) SetNillableRound(v *uint) *RoundStatsUpdate {
if v != nil {
_u.SetRound(*v)
}
return _u
}
// AddRound adds value to the "round" field.
func (_u *RoundStatsUpdate) AddRound(v int) *RoundStatsUpdate {
_u.mutation.AddRound(v)
return _u
}
// SetBank sets the "bank" field.
func (_u *RoundStatsUpdate) SetBank(v uint) *RoundStatsUpdate {
_u.mutation.ResetBank()
_u.mutation.SetBank(v)
return _u
}
// SetNillableBank sets the "bank" field if the given value is not nil.
func (_u *RoundStatsUpdate) SetNillableBank(v *uint) *RoundStatsUpdate {
if v != nil {
_u.SetBank(*v)
}
return _u
}
// AddBank adds value to the "bank" field.
func (_u *RoundStatsUpdate) AddBank(v int) *RoundStatsUpdate {
_u.mutation.AddBank(v)
return _u
}
// SetEquipment sets the "equipment" field.
func (_u *RoundStatsUpdate) SetEquipment(v uint) *RoundStatsUpdate {
_u.mutation.ResetEquipment()
_u.mutation.SetEquipment(v)
return _u
}
// SetNillableEquipment sets the "equipment" field if the given value is not nil.
func (_u *RoundStatsUpdate) SetNillableEquipment(v *uint) *RoundStatsUpdate {
if v != nil {
_u.SetEquipment(*v)
}
return _u
}
// AddEquipment adds value to the "equipment" field.
func (_u *RoundStatsUpdate) AddEquipment(v int) *RoundStatsUpdate {
_u.mutation.AddEquipment(v)
return _u
}
// SetSpent sets the "spent" field.
func (_u *RoundStatsUpdate) SetSpent(v uint) *RoundStatsUpdate {
_u.mutation.ResetSpent()
_u.mutation.SetSpent(v)
return _u
}
// SetNillableSpent sets the "spent" field if the given value is not nil.
func (_u *RoundStatsUpdate) SetNillableSpent(v *uint) *RoundStatsUpdate {
if v != nil {
_u.SetSpent(*v)
}
return _u
}
// AddSpent adds value to the "spent" field.
func (_u *RoundStatsUpdate) AddSpent(v int) *RoundStatsUpdate {
_u.mutation.AddSpent(v)
return _u
}
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
func (_u *RoundStatsUpdate) SetMatchPlayerID(id int) *RoundStatsUpdate {
_u.mutation.SetMatchPlayerID(id)
return _u
}
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
func (_u *RoundStatsUpdate) SetNillableMatchPlayerID(id *int) *RoundStatsUpdate {
if id != nil {
_u = _u.SetMatchPlayerID(*id)
}
return _u
}
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
func (_u *RoundStatsUpdate) SetMatchPlayer(v *MatchPlayer) *RoundStatsUpdate {
return _u.SetMatchPlayerID(v.ID)
}
// Mutation returns the RoundStatsMutation object of the builder.
func (_u *RoundStatsUpdate) Mutation() *RoundStatsMutation {
return _u.mutation
}
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
func (_u *RoundStatsUpdate) ClearMatchPlayer() *RoundStatsUpdate {
_u.mutation.ClearMatchPlayer()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *RoundStatsUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *RoundStatsUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *RoundStatsUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *RoundStatsUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *RoundStatsUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *RoundStatsUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *RoundStatsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(roundstats.Table, roundstats.Columns, sqlgraph.NewFieldSpec(roundstats.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Round(); ok {
_spec.SetField(roundstats.FieldRound, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedRound(); ok {
_spec.AddField(roundstats.FieldRound, field.TypeUint, value)
}
if value, ok := _u.mutation.Bank(); ok {
_spec.SetField(roundstats.FieldBank, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedBank(); ok {
_spec.AddField(roundstats.FieldBank, field.TypeUint, value)
}
if value, ok := _u.mutation.Equipment(); ok {
_spec.SetField(roundstats.FieldEquipment, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedEquipment(); ok {
_spec.AddField(roundstats.FieldEquipment, field.TypeUint, value)
}
if value, ok := _u.mutation.Spent(); ok {
_spec.SetField(roundstats.FieldSpent, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedSpent(); ok {
_spec.AddField(roundstats.FieldSpent, field.TypeUint, value)
}
if _u.mutation.MatchPlayerCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.MatchPlayerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{roundstats.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// RoundStatsUpdateOne is the builder for updating a single RoundStats entity.
type RoundStatsUpdateOne struct {
config
fields []string
hooks []Hook
mutation *RoundStatsMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetRound sets the "round" field.
func (_u *RoundStatsUpdateOne) SetRound(v uint) *RoundStatsUpdateOne {
_u.mutation.ResetRound()
_u.mutation.SetRound(v)
return _u
}
// SetNillableRound sets the "round" field if the given value is not nil.
func (_u *RoundStatsUpdateOne) SetNillableRound(v *uint) *RoundStatsUpdateOne {
if v != nil {
_u.SetRound(*v)
}
return _u
}
// AddRound adds value to the "round" field.
func (_u *RoundStatsUpdateOne) AddRound(v int) *RoundStatsUpdateOne {
_u.mutation.AddRound(v)
return _u
}
// SetBank sets the "bank" field.
func (_u *RoundStatsUpdateOne) SetBank(v uint) *RoundStatsUpdateOne {
_u.mutation.ResetBank()
_u.mutation.SetBank(v)
return _u
}
// SetNillableBank sets the "bank" field if the given value is not nil.
func (_u *RoundStatsUpdateOne) SetNillableBank(v *uint) *RoundStatsUpdateOne {
if v != nil {
_u.SetBank(*v)
}
return _u
}
// AddBank adds value to the "bank" field.
func (_u *RoundStatsUpdateOne) AddBank(v int) *RoundStatsUpdateOne {
_u.mutation.AddBank(v)
return _u
}
// SetEquipment sets the "equipment" field.
func (_u *RoundStatsUpdateOne) SetEquipment(v uint) *RoundStatsUpdateOne {
_u.mutation.ResetEquipment()
_u.mutation.SetEquipment(v)
return _u
}
// SetNillableEquipment sets the "equipment" field if the given value is not nil.
func (_u *RoundStatsUpdateOne) SetNillableEquipment(v *uint) *RoundStatsUpdateOne {
if v != nil {
_u.SetEquipment(*v)
}
return _u
}
// AddEquipment adds value to the "equipment" field.
func (_u *RoundStatsUpdateOne) AddEquipment(v int) *RoundStatsUpdateOne {
_u.mutation.AddEquipment(v)
return _u
}
// SetSpent sets the "spent" field.
func (_u *RoundStatsUpdateOne) SetSpent(v uint) *RoundStatsUpdateOne {
_u.mutation.ResetSpent()
_u.mutation.SetSpent(v)
return _u
}
// SetNillableSpent sets the "spent" field if the given value is not nil.
func (_u *RoundStatsUpdateOne) SetNillableSpent(v *uint) *RoundStatsUpdateOne {
if v != nil {
_u.SetSpent(*v)
}
return _u
}
// AddSpent adds value to the "spent" field.
func (_u *RoundStatsUpdateOne) AddSpent(v int) *RoundStatsUpdateOne {
_u.mutation.AddSpent(v)
return _u
}
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
func (_u *RoundStatsUpdateOne) SetMatchPlayerID(id int) *RoundStatsUpdateOne {
_u.mutation.SetMatchPlayerID(id)
return _u
}
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
func (_u *RoundStatsUpdateOne) SetNillableMatchPlayerID(id *int) *RoundStatsUpdateOne {
if id != nil {
_u = _u.SetMatchPlayerID(*id)
}
return _u
}
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
func (_u *RoundStatsUpdateOne) SetMatchPlayer(v *MatchPlayer) *RoundStatsUpdateOne {
return _u.SetMatchPlayerID(v.ID)
}
// Mutation returns the RoundStatsMutation object of the builder.
func (_u *RoundStatsUpdateOne) Mutation() *RoundStatsMutation {
return _u.mutation
}
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
func (_u *RoundStatsUpdateOne) ClearMatchPlayer() *RoundStatsUpdateOne {
_u.mutation.ClearMatchPlayer()
return _u
}
// Where appends a list predicates to the RoundStatsUpdate builder.
func (_u *RoundStatsUpdateOne) Where(ps ...predicate.RoundStats) *RoundStatsUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *RoundStatsUpdateOne) Select(field string, fields ...string) *RoundStatsUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated RoundStats entity.
func (_u *RoundStatsUpdateOne) Save(ctx context.Context) (*RoundStats, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *RoundStatsUpdateOne) SaveX(ctx context.Context) *RoundStats {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *RoundStatsUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *RoundStatsUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *RoundStatsUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *RoundStatsUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *RoundStatsUpdateOne) sqlSave(ctx context.Context) (_node *RoundStats, err error) {
_spec := sqlgraph.NewUpdateSpec(roundstats.Table, roundstats.Columns, sqlgraph.NewFieldSpec(roundstats.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "RoundStats.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, roundstats.FieldID)
for _, f := range fields {
if !roundstats.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != roundstats.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Round(); ok {
_spec.SetField(roundstats.FieldRound, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedRound(); ok {
_spec.AddField(roundstats.FieldRound, field.TypeUint, value)
}
if value, ok := _u.mutation.Bank(); ok {
_spec.SetField(roundstats.FieldBank, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedBank(); ok {
_spec.AddField(roundstats.FieldBank, field.TypeUint, value)
}
if value, ok := _u.mutation.Equipment(); ok {
_spec.SetField(roundstats.FieldEquipment, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedEquipment(); ok {
_spec.AddField(roundstats.FieldEquipment, field.TypeUint, value)
}
if value, ok := _u.mutation.Spent(); ok {
_spec.SetField(roundstats.FieldSpent, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedSpent(); ok {
_spec.AddField(roundstats.FieldSpent, field.TypeUint, value)
}
if _u.mutation.MatchPlayerCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.MatchPlayerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
_node = &RoundStats{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{roundstats.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}