Files
csgowtfd/ent/weapon_update.go

577 lines
15 KiB
Go

// Code generated by entc, 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"
"git.harting.dev/csgowtf/csgowtfd/ent/matchplayer"
"git.harting.dev/csgowtf/csgowtfd/ent/predicate"
"git.harting.dev/csgowtf/csgowtfd/ent/weapon"
)
// WeaponUpdate is the builder for updating Weapon entities.
type WeaponUpdate struct {
config
hooks []Hook
mutation *WeaponMutation
}
// 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) {
var (
err error
affected int
)
if len(wu.hooks) == 0 {
affected, err = wu.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*WeaponMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
wu.mutation = mutation
affected, err = wu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(wu.hooks) - 1; i >= 0; i-- {
if wu.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// 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)
}
}
func (wu *WeaponUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: weapon.Table,
Columns: weapon.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weapon.FieldID,
},
},
}
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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
}
if value, ok := wu.mutation.AddedVictim(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
}
if value, ok := wu.mutation.Dmg(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
}
if value, ok := wu.mutation.AddedDmg(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
}
if value, ok := wu.mutation.EqType(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
}
if value, ok := wu.mutation.AddedEqType(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
}
if value, ok := wu.mutation.HitGroup(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
}
if value, ok := wu.mutation.AddedHitGroup(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
}
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)
}
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{err.Error(), err}
}
return 0, err
}
return n, nil
}
// WeaponUpdateOne is the builder for updating a single Weapon entity.
type WeaponUpdateOne struct {
config
fields []string
hooks []Hook
mutation *WeaponMutation
}
// 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
}
// 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) {
var (
err error
node *Weapon
)
if len(wuo.hooks) == 0 {
node, err = wuo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*WeaponMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
wuo.mutation = mutation
node, err = wuo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(wuo.hooks) - 1; i >= 0; i-- {
if wuo.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wuo.mutation); err != nil {
return nil, err
}
}
return node, err
}
// 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)
}
}
func (wuo *WeaponUpdateOne) sqlSave(ctx context.Context) (_node *Weapon, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: weapon.Table,
Columns: weapon.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weapon.FieldID,
},
},
}
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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
}
if value, ok := wuo.mutation.AddedVictim(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
}
if value, ok := wuo.mutation.Dmg(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
}
if value, ok := wuo.mutation.AddedDmg(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
}
if value, ok := wuo.mutation.EqType(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
}
if value, ok := wuo.mutation.AddedEqType(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
}
if value, ok := wuo.mutation.HitGroup(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
}
if value, ok := wuo.mutation.AddedHitGroup(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
}
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)
}
_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{err.Error(), err}
}
return nil, err
}
return _node, nil
}