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

517 lines
14 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/weapon"
)
// WeaponUpdate is the builder for updating Weapon entities.
type WeaponUpdate struct {
config
hooks []Hook
mutation *WeaponMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the WeaponUpdate builder.
func (_u *WeaponUpdate) Where(ps ...predicate.Weapon) *WeaponUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetVictim sets the "victim" field.
func (_u *WeaponUpdate) SetVictim(v uint64) *WeaponUpdate {
_u.mutation.ResetVictim()
_u.mutation.SetVictim(v)
return _u
}
// SetNillableVictim sets the "victim" field if the given value is not nil.
func (_u *WeaponUpdate) SetNillableVictim(v *uint64) *WeaponUpdate {
if v != nil {
_u.SetVictim(*v)
}
return _u
}
// AddVictim adds value to the "victim" field.
func (_u *WeaponUpdate) AddVictim(v int64) *WeaponUpdate {
_u.mutation.AddVictim(v)
return _u
}
// SetDmg sets the "dmg" field.
func (_u *WeaponUpdate) SetDmg(v uint) *WeaponUpdate {
_u.mutation.ResetDmg()
_u.mutation.SetDmg(v)
return _u
}
// SetNillableDmg sets the "dmg" field if the given value is not nil.
func (_u *WeaponUpdate) SetNillableDmg(v *uint) *WeaponUpdate {
if v != nil {
_u.SetDmg(*v)
}
return _u
}
// AddDmg adds value to the "dmg" field.
func (_u *WeaponUpdate) AddDmg(v int) *WeaponUpdate {
_u.mutation.AddDmg(v)
return _u
}
// SetEqType sets the "eq_type" field.
func (_u *WeaponUpdate) SetEqType(v int) *WeaponUpdate {
_u.mutation.ResetEqType()
_u.mutation.SetEqType(v)
return _u
}
// SetNillableEqType sets the "eq_type" field if the given value is not nil.
func (_u *WeaponUpdate) SetNillableEqType(v *int) *WeaponUpdate {
if v != nil {
_u.SetEqType(*v)
}
return _u
}
// AddEqType adds value to the "eq_type" field.
func (_u *WeaponUpdate) AddEqType(v int) *WeaponUpdate {
_u.mutation.AddEqType(v)
return _u
}
// SetHitGroup sets the "hit_group" field.
func (_u *WeaponUpdate) SetHitGroup(v int) *WeaponUpdate {
_u.mutation.ResetHitGroup()
_u.mutation.SetHitGroup(v)
return _u
}
// SetNillableHitGroup sets the "hit_group" field if the given value is not nil.
func (_u *WeaponUpdate) SetNillableHitGroup(v *int) *WeaponUpdate {
if v != nil {
_u.SetHitGroup(*v)
}
return _u
}
// AddHitGroup adds value to the "hit_group" field.
func (_u *WeaponUpdate) AddHitGroup(v int) *WeaponUpdate {
_u.mutation.AddHitGroup(v)
return _u
}
// SetStatID sets the "stat" edge to the MatchPlayer entity by ID.
func (_u *WeaponUpdate) SetStatID(id int) *WeaponUpdate {
_u.mutation.SetStatID(id)
return _u
}
// SetNillableStatID sets the "stat" edge to the MatchPlayer entity by ID if the given value is not nil.
func (_u *WeaponUpdate) SetNillableStatID(id *int) *WeaponUpdate {
if id != nil {
_u = _u.SetStatID(*id)
}
return _u
}
// SetStat sets the "stat" edge to the MatchPlayer entity.
func (_u *WeaponUpdate) SetStat(v *MatchPlayer) *WeaponUpdate {
return _u.SetStatID(v.ID)
}
// Mutation returns the WeaponMutation object of the builder.
func (_u *WeaponUpdate) Mutation() *WeaponMutation {
return _u.mutation
}
// ClearStat clears the "stat" edge to the MatchPlayer entity.
func (_u *WeaponUpdate) ClearStat() *WeaponUpdate {
_u.mutation.ClearStat()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *WeaponUpdate) 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 *WeaponUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *WeaponUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *WeaponUpdate) 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 *WeaponUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WeaponUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *WeaponUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(weapon.Table, weapon.Columns, sqlgraph.NewFieldSpec(weapon.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.Victim(); ok {
_spec.SetField(weapon.FieldVictim, field.TypeUint64, value)
}
if value, ok := _u.mutation.AddedVictim(); ok {
_spec.AddField(weapon.FieldVictim, field.TypeUint64, value)
}
if value, ok := _u.mutation.Dmg(); ok {
_spec.SetField(weapon.FieldDmg, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedDmg(); ok {
_spec.AddField(weapon.FieldDmg, field.TypeUint, value)
}
if value, ok := _u.mutation.EqType(); ok {
_spec.SetField(weapon.FieldEqType, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedEqType(); ok {
_spec.AddField(weapon.FieldEqType, field.TypeInt, value)
}
if value, ok := _u.mutation.HitGroup(); ok {
_spec.SetField(weapon.FieldHitGroup, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedHitGroup(); ok {
_spec.AddField(weapon.FieldHitGroup, field.TypeInt, value)
}
if _u.mutation.StatCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weapon.StatTable,
Columns: []string{weapon.StatColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.StatIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weapon.StatTable,
Columns: []string{weapon.StatColumn},
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{weapon.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// WeaponUpdateOne is the builder for updating a single Weapon entity.
type WeaponUpdateOne struct {
config
fields []string
hooks []Hook
mutation *WeaponMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetVictim sets the "victim" field.
func (_u *WeaponUpdateOne) SetVictim(v uint64) *WeaponUpdateOne {
_u.mutation.ResetVictim()
_u.mutation.SetVictim(v)
return _u
}
// SetNillableVictim sets the "victim" field if the given value is not nil.
func (_u *WeaponUpdateOne) SetNillableVictim(v *uint64) *WeaponUpdateOne {
if v != nil {
_u.SetVictim(*v)
}
return _u
}
// AddVictim adds value to the "victim" field.
func (_u *WeaponUpdateOne) AddVictim(v int64) *WeaponUpdateOne {
_u.mutation.AddVictim(v)
return _u
}
// SetDmg sets the "dmg" field.
func (_u *WeaponUpdateOne) SetDmg(v uint) *WeaponUpdateOne {
_u.mutation.ResetDmg()
_u.mutation.SetDmg(v)
return _u
}
// SetNillableDmg sets the "dmg" field if the given value is not nil.
func (_u *WeaponUpdateOne) SetNillableDmg(v *uint) *WeaponUpdateOne {
if v != nil {
_u.SetDmg(*v)
}
return _u
}
// AddDmg adds value to the "dmg" field.
func (_u *WeaponUpdateOne) AddDmg(v int) *WeaponUpdateOne {
_u.mutation.AddDmg(v)
return _u
}
// SetEqType sets the "eq_type" field.
func (_u *WeaponUpdateOne) SetEqType(v int) *WeaponUpdateOne {
_u.mutation.ResetEqType()
_u.mutation.SetEqType(v)
return _u
}
// SetNillableEqType sets the "eq_type" field if the given value is not nil.
func (_u *WeaponUpdateOne) SetNillableEqType(v *int) *WeaponUpdateOne {
if v != nil {
_u.SetEqType(*v)
}
return _u
}
// AddEqType adds value to the "eq_type" field.
func (_u *WeaponUpdateOne) AddEqType(v int) *WeaponUpdateOne {
_u.mutation.AddEqType(v)
return _u
}
// SetHitGroup sets the "hit_group" field.
func (_u *WeaponUpdateOne) SetHitGroup(v int) *WeaponUpdateOne {
_u.mutation.ResetHitGroup()
_u.mutation.SetHitGroup(v)
return _u
}
// SetNillableHitGroup sets the "hit_group" field if the given value is not nil.
func (_u *WeaponUpdateOne) SetNillableHitGroup(v *int) *WeaponUpdateOne {
if v != nil {
_u.SetHitGroup(*v)
}
return _u
}
// AddHitGroup adds value to the "hit_group" field.
func (_u *WeaponUpdateOne) AddHitGroup(v int) *WeaponUpdateOne {
_u.mutation.AddHitGroup(v)
return _u
}
// SetStatID sets the "stat" edge to the MatchPlayer entity by ID.
func (_u *WeaponUpdateOne) SetStatID(id int) *WeaponUpdateOne {
_u.mutation.SetStatID(id)
return _u
}
// SetNillableStatID sets the "stat" edge to the MatchPlayer entity by ID if the given value is not nil.
func (_u *WeaponUpdateOne) SetNillableStatID(id *int) *WeaponUpdateOne {
if id != nil {
_u = _u.SetStatID(*id)
}
return _u
}
// SetStat sets the "stat" edge to the MatchPlayer entity.
func (_u *WeaponUpdateOne) SetStat(v *MatchPlayer) *WeaponUpdateOne {
return _u.SetStatID(v.ID)
}
// Mutation returns the WeaponMutation object of the builder.
func (_u *WeaponUpdateOne) Mutation() *WeaponMutation {
return _u.mutation
}
// ClearStat clears the "stat" edge to the MatchPlayer entity.
func (_u *WeaponUpdateOne) ClearStat() *WeaponUpdateOne {
_u.mutation.ClearStat()
return _u
}
// Where appends a list predicates to the WeaponUpdate builder.
func (_u *WeaponUpdateOne) Where(ps ...predicate.Weapon) *WeaponUpdateOne {
_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 *WeaponUpdateOne) Select(field string, fields ...string) *WeaponUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Weapon entity.
func (_u *WeaponUpdateOne) Save(ctx context.Context) (*Weapon, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *WeaponUpdateOne) SaveX(ctx context.Context) *Weapon {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *WeaponUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *WeaponUpdateOne) 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 *WeaponUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WeaponUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *WeaponUpdateOne) sqlSave(ctx context.Context) (_node *Weapon, err error) {
_spec := sqlgraph.NewUpdateSpec(weapon.Table, weapon.Columns, sqlgraph.NewFieldSpec(weapon.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Weapon.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, weapon.FieldID)
for _, f := range fields {
if !weapon.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != weapon.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.Victim(); ok {
_spec.SetField(weapon.FieldVictim, field.TypeUint64, value)
}
if value, ok := _u.mutation.AddedVictim(); ok {
_spec.AddField(weapon.FieldVictim, field.TypeUint64, value)
}
if value, ok := _u.mutation.Dmg(); ok {
_spec.SetField(weapon.FieldDmg, field.TypeUint, value)
}
if value, ok := _u.mutation.AddedDmg(); ok {
_spec.AddField(weapon.FieldDmg, field.TypeUint, value)
}
if value, ok := _u.mutation.EqType(); ok {
_spec.SetField(weapon.FieldEqType, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedEqType(); ok {
_spec.AddField(weapon.FieldEqType, field.TypeInt, value)
}
if value, ok := _u.mutation.HitGroup(); ok {
_spec.SetField(weapon.FieldHitGroup, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedHitGroup(); ok {
_spec.AddField(weapon.FieldHitGroup, field.TypeInt, value)
}
if _u.mutation.StatCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weapon.StatTable,
Columns: []string{weapon.StatColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.StatIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weapon.StatTable,
Columns: []string{weapon.StatColumn},
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 = &Weapon{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{weapon.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}