465 lines
14 KiB
Go
465 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/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 (rsu *RoundStatsUpdate) Where(ps ...predicate.RoundStats) *RoundStatsUpdate {
|
|
rsu.mutation.Where(ps...)
|
|
return rsu
|
|
}
|
|
|
|
// SetRound sets the "round" field.
|
|
func (rsu *RoundStatsUpdate) SetRound(u uint) *RoundStatsUpdate {
|
|
rsu.mutation.ResetRound()
|
|
rsu.mutation.SetRound(u)
|
|
return rsu
|
|
}
|
|
|
|
// AddRound adds u to the "round" field.
|
|
func (rsu *RoundStatsUpdate) AddRound(u int) *RoundStatsUpdate {
|
|
rsu.mutation.AddRound(u)
|
|
return rsu
|
|
}
|
|
|
|
// SetBank sets the "bank" field.
|
|
func (rsu *RoundStatsUpdate) SetBank(u uint) *RoundStatsUpdate {
|
|
rsu.mutation.ResetBank()
|
|
rsu.mutation.SetBank(u)
|
|
return rsu
|
|
}
|
|
|
|
// AddBank adds u to the "bank" field.
|
|
func (rsu *RoundStatsUpdate) AddBank(u int) *RoundStatsUpdate {
|
|
rsu.mutation.AddBank(u)
|
|
return rsu
|
|
}
|
|
|
|
// SetEquipment sets the "equipment" field.
|
|
func (rsu *RoundStatsUpdate) SetEquipment(u uint) *RoundStatsUpdate {
|
|
rsu.mutation.ResetEquipment()
|
|
rsu.mutation.SetEquipment(u)
|
|
return rsu
|
|
}
|
|
|
|
// AddEquipment adds u to the "equipment" field.
|
|
func (rsu *RoundStatsUpdate) AddEquipment(u int) *RoundStatsUpdate {
|
|
rsu.mutation.AddEquipment(u)
|
|
return rsu
|
|
}
|
|
|
|
// SetSpent sets the "spent" field.
|
|
func (rsu *RoundStatsUpdate) SetSpent(u uint) *RoundStatsUpdate {
|
|
rsu.mutation.ResetSpent()
|
|
rsu.mutation.SetSpent(u)
|
|
return rsu
|
|
}
|
|
|
|
// AddSpent adds u to the "spent" field.
|
|
func (rsu *RoundStatsUpdate) AddSpent(u int) *RoundStatsUpdate {
|
|
rsu.mutation.AddSpent(u)
|
|
return rsu
|
|
}
|
|
|
|
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
|
|
func (rsu *RoundStatsUpdate) SetMatchPlayerID(id int) *RoundStatsUpdate {
|
|
rsu.mutation.SetMatchPlayerID(id)
|
|
return rsu
|
|
}
|
|
|
|
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
|
|
func (rsu *RoundStatsUpdate) SetNillableMatchPlayerID(id *int) *RoundStatsUpdate {
|
|
if id != nil {
|
|
rsu = rsu.SetMatchPlayerID(*id)
|
|
}
|
|
return rsu
|
|
}
|
|
|
|
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
|
|
func (rsu *RoundStatsUpdate) SetMatchPlayer(m *MatchPlayer) *RoundStatsUpdate {
|
|
return rsu.SetMatchPlayerID(m.ID)
|
|
}
|
|
|
|
// Mutation returns the RoundStatsMutation object of the builder.
|
|
func (rsu *RoundStatsUpdate) Mutation() *RoundStatsMutation {
|
|
return rsu.mutation
|
|
}
|
|
|
|
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
|
|
func (rsu *RoundStatsUpdate) ClearMatchPlayer() *RoundStatsUpdate {
|
|
rsu.mutation.ClearMatchPlayer()
|
|
return rsu
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (rsu *RoundStatsUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks[int, RoundStatsMutation](ctx, rsu.sqlSave, rsu.mutation, rsu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (rsu *RoundStatsUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := rsu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (rsu *RoundStatsUpdate) Exec(ctx context.Context) error {
|
|
_, err := rsu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (rsu *RoundStatsUpdate) ExecX(ctx context.Context) {
|
|
if err := rsu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (rsu *RoundStatsUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *RoundStatsUpdate {
|
|
rsu.modifiers = append(rsu.modifiers, modifiers...)
|
|
return rsu
|
|
}
|
|
|
|
func (rsu *RoundStatsUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(roundstats.Table, roundstats.Columns, sqlgraph.NewFieldSpec(roundstats.FieldID, field.TypeInt))
|
|
if ps := rsu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := rsu.mutation.Round(); ok {
|
|
_spec.SetField(roundstats.FieldRound, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsu.mutation.AddedRound(); ok {
|
|
_spec.AddField(roundstats.FieldRound, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsu.mutation.Bank(); ok {
|
|
_spec.SetField(roundstats.FieldBank, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsu.mutation.AddedBank(); ok {
|
|
_spec.AddField(roundstats.FieldBank, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsu.mutation.Equipment(); ok {
|
|
_spec.SetField(roundstats.FieldEquipment, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsu.mutation.AddedEquipment(); ok {
|
|
_spec.AddField(roundstats.FieldEquipment, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsu.mutation.Spent(); ok {
|
|
_spec.SetField(roundstats.FieldSpent, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsu.mutation.AddedSpent(); ok {
|
|
_spec.AddField(roundstats.FieldSpent, field.TypeUint, value)
|
|
}
|
|
if rsu.mutation.MatchPlayerCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: roundstats.MatchPlayerTable,
|
|
Columns: []string{roundstats.MatchPlayerColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: matchplayer.FieldID,
|
|
},
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := rsu.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.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(rsu.modifiers...)
|
|
if n, err = sqlgraph.UpdateNodes(ctx, rsu.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
|
|
}
|
|
rsu.mutation.done = true
|
|
return n, 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 (rsuo *RoundStatsUpdateOne) SetRound(u uint) *RoundStatsUpdateOne {
|
|
rsuo.mutation.ResetRound()
|
|
rsuo.mutation.SetRound(u)
|
|
return rsuo
|
|
}
|
|
|
|
// AddRound adds u to the "round" field.
|
|
func (rsuo *RoundStatsUpdateOne) AddRound(u int) *RoundStatsUpdateOne {
|
|
rsuo.mutation.AddRound(u)
|
|
return rsuo
|
|
}
|
|
|
|
// SetBank sets the "bank" field.
|
|
func (rsuo *RoundStatsUpdateOne) SetBank(u uint) *RoundStatsUpdateOne {
|
|
rsuo.mutation.ResetBank()
|
|
rsuo.mutation.SetBank(u)
|
|
return rsuo
|
|
}
|
|
|
|
// AddBank adds u to the "bank" field.
|
|
func (rsuo *RoundStatsUpdateOne) AddBank(u int) *RoundStatsUpdateOne {
|
|
rsuo.mutation.AddBank(u)
|
|
return rsuo
|
|
}
|
|
|
|
// SetEquipment sets the "equipment" field.
|
|
func (rsuo *RoundStatsUpdateOne) SetEquipment(u uint) *RoundStatsUpdateOne {
|
|
rsuo.mutation.ResetEquipment()
|
|
rsuo.mutation.SetEquipment(u)
|
|
return rsuo
|
|
}
|
|
|
|
// AddEquipment adds u to the "equipment" field.
|
|
func (rsuo *RoundStatsUpdateOne) AddEquipment(u int) *RoundStatsUpdateOne {
|
|
rsuo.mutation.AddEquipment(u)
|
|
return rsuo
|
|
}
|
|
|
|
// SetSpent sets the "spent" field.
|
|
func (rsuo *RoundStatsUpdateOne) SetSpent(u uint) *RoundStatsUpdateOne {
|
|
rsuo.mutation.ResetSpent()
|
|
rsuo.mutation.SetSpent(u)
|
|
return rsuo
|
|
}
|
|
|
|
// AddSpent adds u to the "spent" field.
|
|
func (rsuo *RoundStatsUpdateOne) AddSpent(u int) *RoundStatsUpdateOne {
|
|
rsuo.mutation.AddSpent(u)
|
|
return rsuo
|
|
}
|
|
|
|
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
|
|
func (rsuo *RoundStatsUpdateOne) SetMatchPlayerID(id int) *RoundStatsUpdateOne {
|
|
rsuo.mutation.SetMatchPlayerID(id)
|
|
return rsuo
|
|
}
|
|
|
|
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
|
|
func (rsuo *RoundStatsUpdateOne) SetNillableMatchPlayerID(id *int) *RoundStatsUpdateOne {
|
|
if id != nil {
|
|
rsuo = rsuo.SetMatchPlayerID(*id)
|
|
}
|
|
return rsuo
|
|
}
|
|
|
|
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
|
|
func (rsuo *RoundStatsUpdateOne) SetMatchPlayer(m *MatchPlayer) *RoundStatsUpdateOne {
|
|
return rsuo.SetMatchPlayerID(m.ID)
|
|
}
|
|
|
|
// Mutation returns the RoundStatsMutation object of the builder.
|
|
func (rsuo *RoundStatsUpdateOne) Mutation() *RoundStatsMutation {
|
|
return rsuo.mutation
|
|
}
|
|
|
|
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
|
|
func (rsuo *RoundStatsUpdateOne) ClearMatchPlayer() *RoundStatsUpdateOne {
|
|
rsuo.mutation.ClearMatchPlayer()
|
|
return rsuo
|
|
}
|
|
|
|
// Where appends a list predicates to the RoundStatsUpdate builder.
|
|
func (rsuo *RoundStatsUpdateOne) Where(ps ...predicate.RoundStats) *RoundStatsUpdateOne {
|
|
rsuo.mutation.Where(ps...)
|
|
return rsuo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (rsuo *RoundStatsUpdateOne) Select(field string, fields ...string) *RoundStatsUpdateOne {
|
|
rsuo.fields = append([]string{field}, fields...)
|
|
return rsuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated RoundStats entity.
|
|
func (rsuo *RoundStatsUpdateOne) Save(ctx context.Context) (*RoundStats, error) {
|
|
return withHooks[*RoundStats, RoundStatsMutation](ctx, rsuo.sqlSave, rsuo.mutation, rsuo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (rsuo *RoundStatsUpdateOne) SaveX(ctx context.Context) *RoundStats {
|
|
node, err := rsuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (rsuo *RoundStatsUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := rsuo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (rsuo *RoundStatsUpdateOne) ExecX(ctx context.Context) {
|
|
if err := rsuo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (rsuo *RoundStatsUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *RoundStatsUpdateOne {
|
|
rsuo.modifiers = append(rsuo.modifiers, modifiers...)
|
|
return rsuo
|
|
}
|
|
|
|
func (rsuo *RoundStatsUpdateOne) sqlSave(ctx context.Context) (_node *RoundStats, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(roundstats.Table, roundstats.Columns, sqlgraph.NewFieldSpec(roundstats.FieldID, field.TypeInt))
|
|
id, ok := rsuo.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 := rsuo.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 := rsuo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := rsuo.mutation.Round(); ok {
|
|
_spec.SetField(roundstats.FieldRound, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsuo.mutation.AddedRound(); ok {
|
|
_spec.AddField(roundstats.FieldRound, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsuo.mutation.Bank(); ok {
|
|
_spec.SetField(roundstats.FieldBank, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsuo.mutation.AddedBank(); ok {
|
|
_spec.AddField(roundstats.FieldBank, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsuo.mutation.Equipment(); ok {
|
|
_spec.SetField(roundstats.FieldEquipment, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsuo.mutation.AddedEquipment(); ok {
|
|
_spec.AddField(roundstats.FieldEquipment, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsuo.mutation.Spent(); ok {
|
|
_spec.SetField(roundstats.FieldSpent, field.TypeUint, value)
|
|
}
|
|
if value, ok := rsuo.mutation.AddedSpent(); ok {
|
|
_spec.AddField(roundstats.FieldSpent, field.TypeUint, value)
|
|
}
|
|
if rsuo.mutation.MatchPlayerCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: roundstats.MatchPlayerTable,
|
|
Columns: []string{roundstats.MatchPlayerColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: matchplayer.FieldID,
|
|
},
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := rsuo.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.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(rsuo.modifiers...)
|
|
_node = &RoundStats{config: rsuo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, rsuo.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
|
|
}
|
|
rsuo.mutation.done = true
|
|
return _node, nil
|
|
}
|