357 lines
10 KiB
Go
357 lines
10 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/spray"
|
|
)
|
|
|
|
// SprayUpdate is the builder for updating Spray entities.
|
|
type SprayUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *SprayMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the SprayUpdate builder.
|
|
func (su *SprayUpdate) Where(ps ...predicate.Spray) *SprayUpdate {
|
|
su.mutation.Where(ps...)
|
|
return su
|
|
}
|
|
|
|
// SetWeapon sets the "weapon" field.
|
|
func (su *SprayUpdate) SetWeapon(i int) *SprayUpdate {
|
|
su.mutation.ResetWeapon()
|
|
su.mutation.SetWeapon(i)
|
|
return su
|
|
}
|
|
|
|
// AddWeapon adds i to the "weapon" field.
|
|
func (su *SprayUpdate) AddWeapon(i int) *SprayUpdate {
|
|
su.mutation.AddWeapon(i)
|
|
return su
|
|
}
|
|
|
|
// SetSpray sets the "spray" field.
|
|
func (su *SprayUpdate) SetSpray(b []byte) *SprayUpdate {
|
|
su.mutation.SetSpray(b)
|
|
return su
|
|
}
|
|
|
|
// SetMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID.
|
|
func (su *SprayUpdate) SetMatchPlayersID(id int) *SprayUpdate {
|
|
su.mutation.SetMatchPlayersID(id)
|
|
return su
|
|
}
|
|
|
|
// SetNillableMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID if the given value is not nil.
|
|
func (su *SprayUpdate) SetNillableMatchPlayersID(id *int) *SprayUpdate {
|
|
if id != nil {
|
|
su = su.SetMatchPlayersID(*id)
|
|
}
|
|
return su
|
|
}
|
|
|
|
// SetMatchPlayers sets the "match_players" edge to the MatchPlayer entity.
|
|
func (su *SprayUpdate) SetMatchPlayers(m *MatchPlayer) *SprayUpdate {
|
|
return su.SetMatchPlayersID(m.ID)
|
|
}
|
|
|
|
// Mutation returns the SprayMutation object of the builder.
|
|
func (su *SprayUpdate) Mutation() *SprayMutation {
|
|
return su.mutation
|
|
}
|
|
|
|
// ClearMatchPlayers clears the "match_players" edge to the MatchPlayer entity.
|
|
func (su *SprayUpdate) ClearMatchPlayers() *SprayUpdate {
|
|
su.mutation.ClearMatchPlayers()
|
|
return su
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (su *SprayUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (su *SprayUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := su.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (su *SprayUpdate) Exec(ctx context.Context) error {
|
|
_, err := su.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (su *SprayUpdate) ExecX(ctx context.Context) {
|
|
if err := su.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (su *SprayUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SprayUpdate {
|
|
su.modifiers = append(su.modifiers, modifiers...)
|
|
return su
|
|
}
|
|
|
|
func (su *SprayUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(spray.Table, spray.Columns, sqlgraph.NewFieldSpec(spray.FieldID, field.TypeInt))
|
|
if ps := su.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := su.mutation.Weapon(); ok {
|
|
_spec.SetField(spray.FieldWeapon, field.TypeInt, value)
|
|
}
|
|
if value, ok := su.mutation.AddedWeapon(); ok {
|
|
_spec.AddField(spray.FieldWeapon, field.TypeInt, value)
|
|
}
|
|
if value, ok := su.mutation.Spray(); ok {
|
|
_spec.SetField(spray.FieldSpray, field.TypeBytes, value)
|
|
}
|
|
if su.mutation.MatchPlayersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: spray.MatchPlayersTable,
|
|
Columns: []string{spray.MatchPlayersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := su.mutation.MatchPlayersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: spray.MatchPlayersTable,
|
|
Columns: []string{spray.MatchPlayersColumn},
|
|
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(su.modifiers...)
|
|
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{spray.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
su.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// SprayUpdateOne is the builder for updating a single Spray entity.
|
|
type SprayUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *SprayMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetWeapon sets the "weapon" field.
|
|
func (suo *SprayUpdateOne) SetWeapon(i int) *SprayUpdateOne {
|
|
suo.mutation.ResetWeapon()
|
|
suo.mutation.SetWeapon(i)
|
|
return suo
|
|
}
|
|
|
|
// AddWeapon adds i to the "weapon" field.
|
|
func (suo *SprayUpdateOne) AddWeapon(i int) *SprayUpdateOne {
|
|
suo.mutation.AddWeapon(i)
|
|
return suo
|
|
}
|
|
|
|
// SetSpray sets the "spray" field.
|
|
func (suo *SprayUpdateOne) SetSpray(b []byte) *SprayUpdateOne {
|
|
suo.mutation.SetSpray(b)
|
|
return suo
|
|
}
|
|
|
|
// SetMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID.
|
|
func (suo *SprayUpdateOne) SetMatchPlayersID(id int) *SprayUpdateOne {
|
|
suo.mutation.SetMatchPlayersID(id)
|
|
return suo
|
|
}
|
|
|
|
// SetNillableMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID if the given value is not nil.
|
|
func (suo *SprayUpdateOne) SetNillableMatchPlayersID(id *int) *SprayUpdateOne {
|
|
if id != nil {
|
|
suo = suo.SetMatchPlayersID(*id)
|
|
}
|
|
return suo
|
|
}
|
|
|
|
// SetMatchPlayers sets the "match_players" edge to the MatchPlayer entity.
|
|
func (suo *SprayUpdateOne) SetMatchPlayers(m *MatchPlayer) *SprayUpdateOne {
|
|
return suo.SetMatchPlayersID(m.ID)
|
|
}
|
|
|
|
// Mutation returns the SprayMutation object of the builder.
|
|
func (suo *SprayUpdateOne) Mutation() *SprayMutation {
|
|
return suo.mutation
|
|
}
|
|
|
|
// ClearMatchPlayers clears the "match_players" edge to the MatchPlayer entity.
|
|
func (suo *SprayUpdateOne) ClearMatchPlayers() *SprayUpdateOne {
|
|
suo.mutation.ClearMatchPlayers()
|
|
return suo
|
|
}
|
|
|
|
// Where appends a list predicates to the SprayUpdate builder.
|
|
func (suo *SprayUpdateOne) Where(ps ...predicate.Spray) *SprayUpdateOne {
|
|
suo.mutation.Where(ps...)
|
|
return suo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (suo *SprayUpdateOne) Select(field string, fields ...string) *SprayUpdateOne {
|
|
suo.fields = append([]string{field}, fields...)
|
|
return suo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Spray entity.
|
|
func (suo *SprayUpdateOne) Save(ctx context.Context) (*Spray, error) {
|
|
return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (suo *SprayUpdateOne) SaveX(ctx context.Context) *Spray {
|
|
node, err := suo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (suo *SprayUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := suo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (suo *SprayUpdateOne) ExecX(ctx context.Context) {
|
|
if err := suo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (suo *SprayUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SprayUpdateOne {
|
|
suo.modifiers = append(suo.modifiers, modifiers...)
|
|
return suo
|
|
}
|
|
|
|
func (suo *SprayUpdateOne) sqlSave(ctx context.Context) (_node *Spray, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(spray.Table, spray.Columns, sqlgraph.NewFieldSpec(spray.FieldID, field.TypeInt))
|
|
id, ok := suo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Spray.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := suo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, spray.FieldID)
|
|
for _, f := range fields {
|
|
if !spray.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != spray.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := suo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := suo.mutation.Weapon(); ok {
|
|
_spec.SetField(spray.FieldWeapon, field.TypeInt, value)
|
|
}
|
|
if value, ok := suo.mutation.AddedWeapon(); ok {
|
|
_spec.AddField(spray.FieldWeapon, field.TypeInt, value)
|
|
}
|
|
if value, ok := suo.mutation.Spray(); ok {
|
|
_spec.SetField(spray.FieldSpray, field.TypeBytes, value)
|
|
}
|
|
if suo.mutation.MatchPlayersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: spray.MatchPlayersTable,
|
|
Columns: []string{spray.MatchPlayersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := suo.mutation.MatchPlayersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: spray.MatchPlayersTable,
|
|
Columns: []string{spray.MatchPlayersColumn},
|
|
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(suo.modifiers...)
|
|
_node = &Spray{config: suo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{spray.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
suo.mutation.done = true
|
|
return _node, nil
|
|
}
|