added spray patterns
This commit is contained in:
439
ent/spray_update.go
Normal file
439
ent/spray_update.go
Normal file
@@ -0,0 +1,439 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"csgowtfd/ent/matchplayer"
|
||||
"csgowtfd/ent/predicate"
|
||||
"csgowtfd/ent/spray"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SprayUpdate is the builder for updating Spray entities.
|
||||
type SprayUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SprayMutation
|
||||
}
|
||||
|
||||
// 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) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(su.hooks) == 0 {
|
||||
affected, err = su.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SprayMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
su.mutation = mutation
|
||||
affected, err = su.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(su.hooks) - 1; i >= 0; i-- {
|
||||
if su.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = su.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, su.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
func (su *SprayUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: spray.Table,
|
||||
Columns: spray.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: spray.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: spray.FieldWeapon,
|
||||
})
|
||||
}
|
||||
if value, ok := su.mutation.AddedWeapon(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: spray.FieldWeapon,
|
||||
})
|
||||
}
|
||||
if value, ok := su.mutation.Spray(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: spray.FieldSpray,
|
||||
})
|
||||
}
|
||||
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.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: matchplayer.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_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.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, su.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{spray.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// SprayUpdateOne is the builder for updating a single Spray entity.
|
||||
type SprayUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *SprayMutation
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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) {
|
||||
var (
|
||||
err error
|
||||
node *Spray
|
||||
)
|
||||
if len(suo.hooks) == 0 {
|
||||
node, err = suo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SprayMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
suo.mutation = mutation
|
||||
node, err = suo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(suo.hooks) - 1; i >= 0; i-- {
|
||||
if suo.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = suo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, suo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
func (suo *SprayUpdateOne) sqlSave(ctx context.Context) (_node *Spray, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: spray.Table,
|
||||
Columns: spray.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: spray.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := suo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: spray.FieldWeapon,
|
||||
})
|
||||
}
|
||||
if value, ok := suo.mutation.AddedWeapon(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: spray.FieldWeapon,
|
||||
})
|
||||
}
|
||||
if value, ok := suo.mutation.Spray(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: spray.FieldSpray,
|
||||
})
|
||||
}
|
||||
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.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: matchplayer.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_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.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 = &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{err.Error(), err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return _node, nil
|
||||
}
|
Reference in New Issue
Block a user