Files
csgowtfd/ent/weapon_update.go

465 lines
13 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 (wu *WeaponUpdate) Where(ps ...predicate.Weapon) *WeaponUpdate {
wu.mutation.Where(ps...)
return wu
}
// SetVictim sets the "victim" field.
func (wu *WeaponUpdate) SetVictim(u uint64) *WeaponUpdate {
wu.mutation.ResetVictim()
wu.mutation.SetVictim(u)
return wu
}
// AddVictim adds u to the "victim" field.
func (wu *WeaponUpdate) AddVictim(u int64) *WeaponUpdate {
wu.mutation.AddVictim(u)
return wu
}
// SetDmg sets the "dmg" field.
func (wu *WeaponUpdate) SetDmg(u uint) *WeaponUpdate {
wu.mutation.ResetDmg()
wu.mutation.SetDmg(u)
return wu
}
// AddDmg adds u to the "dmg" field.
func (wu *WeaponUpdate) AddDmg(u int) *WeaponUpdate {
wu.mutation.AddDmg(u)
return wu
}
// SetEqType sets the "eq_type" field.
func (wu *WeaponUpdate) SetEqType(i int) *WeaponUpdate {
wu.mutation.ResetEqType()
wu.mutation.SetEqType(i)
return wu
}
// AddEqType adds i to the "eq_type" field.
func (wu *WeaponUpdate) AddEqType(i int) *WeaponUpdate {
wu.mutation.AddEqType(i)
return wu
}
// SetHitGroup sets the "hit_group" field.
func (wu *WeaponUpdate) SetHitGroup(i int) *WeaponUpdate {
wu.mutation.ResetHitGroup()
wu.mutation.SetHitGroup(i)
return wu
}
// AddHitGroup adds i to the "hit_group" field.
func (wu *WeaponUpdate) AddHitGroup(i int) *WeaponUpdate {
wu.mutation.AddHitGroup(i)
return wu
}
// SetStatID sets the "stat" edge to the MatchPlayer entity by ID.
func (wu *WeaponUpdate) SetStatID(id int) *WeaponUpdate {
wu.mutation.SetStatID(id)
return wu
}
// SetNillableStatID sets the "stat" edge to the MatchPlayer entity by ID if the given value is not nil.
func (wu *WeaponUpdate) SetNillableStatID(id *int) *WeaponUpdate {
if id != nil {
wu = wu.SetStatID(*id)
}
return wu
}
// SetStat sets the "stat" edge to the MatchPlayer entity.
func (wu *WeaponUpdate) SetStat(m *MatchPlayer) *WeaponUpdate {
return wu.SetStatID(m.ID)
}
// Mutation returns the WeaponMutation object of the builder.
func (wu *WeaponUpdate) Mutation() *WeaponMutation {
return wu.mutation
}
// ClearStat clears the "stat" edge to the MatchPlayer entity.
func (wu *WeaponUpdate) ClearStat() *WeaponUpdate {
wu.mutation.ClearStat()
return wu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (wu *WeaponUpdate) Save(ctx context.Context) (int, error) {
return withHooks[int, WeaponMutation](ctx, wu.sqlSave, wu.mutation, wu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (wu *WeaponUpdate) SaveX(ctx context.Context) int {
affected, err := wu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (wu *WeaponUpdate) Exec(ctx context.Context) error {
_, err := wu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (wu *WeaponUpdate) ExecX(ctx context.Context) {
if err := wu.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (wu *WeaponUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WeaponUpdate {
wu.modifiers = append(wu.modifiers, modifiers...)
return wu
}
func (wu *WeaponUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(weapon.Table, weapon.Columns, sqlgraph.NewFieldSpec(weapon.FieldID, field.TypeInt))
if ps := wu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := wu.mutation.Victim(); ok {
_spec.SetField(weapon.FieldVictim, field.TypeUint64, value)
}
if value, ok := wu.mutation.AddedVictim(); ok {
_spec.AddField(weapon.FieldVictim, field.TypeUint64, value)
}
if value, ok := wu.mutation.Dmg(); ok {
_spec.SetField(weapon.FieldDmg, field.TypeUint, value)
}
if value, ok := wu.mutation.AddedDmg(); ok {
_spec.AddField(weapon.FieldDmg, field.TypeUint, value)
}
if value, ok := wu.mutation.EqType(); ok {
_spec.SetField(weapon.FieldEqType, field.TypeInt, value)
}
if value, ok := wu.mutation.AddedEqType(); ok {
_spec.AddField(weapon.FieldEqType, field.TypeInt, value)
}
if value, ok := wu.mutation.HitGroup(); ok {
_spec.SetField(weapon.FieldHitGroup, field.TypeInt, value)
}
if value, ok := wu.mutation.AddedHitGroup(); ok {
_spec.AddField(weapon.FieldHitGroup, field.TypeInt, value)
}
if wu.mutation.StatCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weapon.StatTable,
Columns: []string{weapon.StatColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := wu.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.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)
}
_spec.AddModifiers(wu.modifiers...)
if n, err = sqlgraph.UpdateNodes(ctx, wu.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
}
wu.mutation.done = true
return n, 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 (wuo *WeaponUpdateOne) SetVictim(u uint64) *WeaponUpdateOne {
wuo.mutation.ResetVictim()
wuo.mutation.SetVictim(u)
return wuo
}
// AddVictim adds u to the "victim" field.
func (wuo *WeaponUpdateOne) AddVictim(u int64) *WeaponUpdateOne {
wuo.mutation.AddVictim(u)
return wuo
}
// SetDmg sets the "dmg" field.
func (wuo *WeaponUpdateOne) SetDmg(u uint) *WeaponUpdateOne {
wuo.mutation.ResetDmg()
wuo.mutation.SetDmg(u)
return wuo
}
// AddDmg adds u to the "dmg" field.
func (wuo *WeaponUpdateOne) AddDmg(u int) *WeaponUpdateOne {
wuo.mutation.AddDmg(u)
return wuo
}
// SetEqType sets the "eq_type" field.
func (wuo *WeaponUpdateOne) SetEqType(i int) *WeaponUpdateOne {
wuo.mutation.ResetEqType()
wuo.mutation.SetEqType(i)
return wuo
}
// AddEqType adds i to the "eq_type" field.
func (wuo *WeaponUpdateOne) AddEqType(i int) *WeaponUpdateOne {
wuo.mutation.AddEqType(i)
return wuo
}
// SetHitGroup sets the "hit_group" field.
func (wuo *WeaponUpdateOne) SetHitGroup(i int) *WeaponUpdateOne {
wuo.mutation.ResetHitGroup()
wuo.mutation.SetHitGroup(i)
return wuo
}
// AddHitGroup adds i to the "hit_group" field.
func (wuo *WeaponUpdateOne) AddHitGroup(i int) *WeaponUpdateOne {
wuo.mutation.AddHitGroup(i)
return wuo
}
// SetStatID sets the "stat" edge to the MatchPlayer entity by ID.
func (wuo *WeaponUpdateOne) SetStatID(id int) *WeaponUpdateOne {
wuo.mutation.SetStatID(id)
return wuo
}
// SetNillableStatID sets the "stat" edge to the MatchPlayer entity by ID if the given value is not nil.
func (wuo *WeaponUpdateOne) SetNillableStatID(id *int) *WeaponUpdateOne {
if id != nil {
wuo = wuo.SetStatID(*id)
}
return wuo
}
// SetStat sets the "stat" edge to the MatchPlayer entity.
func (wuo *WeaponUpdateOne) SetStat(m *MatchPlayer) *WeaponUpdateOne {
return wuo.SetStatID(m.ID)
}
// Mutation returns the WeaponMutation object of the builder.
func (wuo *WeaponUpdateOne) Mutation() *WeaponMutation {
return wuo.mutation
}
// ClearStat clears the "stat" edge to the MatchPlayer entity.
func (wuo *WeaponUpdateOne) ClearStat() *WeaponUpdateOne {
wuo.mutation.ClearStat()
return wuo
}
// Where appends a list predicates to the WeaponUpdate builder.
func (wuo *WeaponUpdateOne) Where(ps ...predicate.Weapon) *WeaponUpdateOne {
wuo.mutation.Where(ps...)
return wuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (wuo *WeaponUpdateOne) Select(field string, fields ...string) *WeaponUpdateOne {
wuo.fields = append([]string{field}, fields...)
return wuo
}
// Save executes the query and returns the updated Weapon entity.
func (wuo *WeaponUpdateOne) Save(ctx context.Context) (*Weapon, error) {
return withHooks[*Weapon, WeaponMutation](ctx, wuo.sqlSave, wuo.mutation, wuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (wuo *WeaponUpdateOne) SaveX(ctx context.Context) *Weapon {
node, err := wuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (wuo *WeaponUpdateOne) Exec(ctx context.Context) error {
_, err := wuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (wuo *WeaponUpdateOne) ExecX(ctx context.Context) {
if err := wuo.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (wuo *WeaponUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WeaponUpdateOne {
wuo.modifiers = append(wuo.modifiers, modifiers...)
return wuo
}
func (wuo *WeaponUpdateOne) sqlSave(ctx context.Context) (_node *Weapon, err error) {
_spec := sqlgraph.NewUpdateSpec(weapon.Table, weapon.Columns, sqlgraph.NewFieldSpec(weapon.FieldID, field.TypeInt))
id, ok := wuo.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 := wuo.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 := wuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := wuo.mutation.Victim(); ok {
_spec.SetField(weapon.FieldVictim, field.TypeUint64, value)
}
if value, ok := wuo.mutation.AddedVictim(); ok {
_spec.AddField(weapon.FieldVictim, field.TypeUint64, value)
}
if value, ok := wuo.mutation.Dmg(); ok {
_spec.SetField(weapon.FieldDmg, field.TypeUint, value)
}
if value, ok := wuo.mutation.AddedDmg(); ok {
_spec.AddField(weapon.FieldDmg, field.TypeUint, value)
}
if value, ok := wuo.mutation.EqType(); ok {
_spec.SetField(weapon.FieldEqType, field.TypeInt, value)
}
if value, ok := wuo.mutation.AddedEqType(); ok {
_spec.AddField(weapon.FieldEqType, field.TypeInt, value)
}
if value, ok := wuo.mutation.HitGroup(); ok {
_spec.SetField(weapon.FieldHitGroup, field.TypeInt, value)
}
if value, ok := wuo.mutation.AddedHitGroup(); ok {
_spec.AddField(weapon.FieldHitGroup, field.TypeInt, value)
}
if wuo.mutation.StatCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weapon.StatTable,
Columns: []string{weapon.StatColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := wuo.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.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)
}
_spec.AddModifiers(wuo.modifiers...)
_node = &Weapon{config: wuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, wuo.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
}
wuo.mutation.done = true
return _node, nil
}