423 lines
12 KiB
Go
423 lines
12 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/messages"
|
|
"somegit.dev/csgowtf/csgowtfd/ent/predicate"
|
|
)
|
|
|
|
// MessagesUpdate is the builder for updating Messages entities.
|
|
type MessagesUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *MessagesMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the MessagesUpdate builder.
|
|
func (_u *MessagesUpdate) Where(ps ...predicate.Messages) *MessagesUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetMessage sets the "message" field.
|
|
func (_u *MessagesUpdate) SetMessage(v string) *MessagesUpdate {
|
|
_u.mutation.SetMessage(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMessage sets the "message" field if the given value is not nil.
|
|
func (_u *MessagesUpdate) SetNillableMessage(v *string) *MessagesUpdate {
|
|
if v != nil {
|
|
_u.SetMessage(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAllChat sets the "all_chat" field.
|
|
func (_u *MessagesUpdate) SetAllChat(v bool) *MessagesUpdate {
|
|
_u.mutation.SetAllChat(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAllChat sets the "all_chat" field if the given value is not nil.
|
|
func (_u *MessagesUpdate) SetNillableAllChat(v *bool) *MessagesUpdate {
|
|
if v != nil {
|
|
_u.SetAllChat(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTick sets the "tick" field.
|
|
func (_u *MessagesUpdate) SetTick(v int) *MessagesUpdate {
|
|
_u.mutation.ResetTick()
|
|
_u.mutation.SetTick(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTick sets the "tick" field if the given value is not nil.
|
|
func (_u *MessagesUpdate) SetNillableTick(v *int) *MessagesUpdate {
|
|
if v != nil {
|
|
_u.SetTick(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddTick adds value to the "tick" field.
|
|
func (_u *MessagesUpdate) AddTick(v int) *MessagesUpdate {
|
|
_u.mutation.AddTick(v)
|
|
return _u
|
|
}
|
|
|
|
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
|
|
func (_u *MessagesUpdate) SetMatchPlayerID(id int) *MessagesUpdate {
|
|
_u.mutation.SetMatchPlayerID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
|
|
func (_u *MessagesUpdate) SetNillableMatchPlayerID(id *int) *MessagesUpdate {
|
|
if id != nil {
|
|
_u = _u.SetMatchPlayerID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
|
|
func (_u *MessagesUpdate) SetMatchPlayer(v *MatchPlayer) *MessagesUpdate {
|
|
return _u.SetMatchPlayerID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the MessagesMutation object of the builder.
|
|
func (_u *MessagesUpdate) Mutation() *MessagesMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
|
|
func (_u *MessagesUpdate) ClearMatchPlayer() *MessagesUpdate {
|
|
_u.mutation.ClearMatchPlayer()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *MessagesUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *MessagesUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *MessagesUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *MessagesUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *MessagesUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MessagesUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *MessagesUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(messages.Table, messages.Columns, sqlgraph.NewFieldSpec(messages.FieldID, field.TypeInt))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.Message(); ok {
|
|
_spec.SetField(messages.FieldMessage, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.AllChat(); ok {
|
|
_spec.SetField(messages.FieldAllChat, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Tick(); ok {
|
|
_spec.SetField(messages.FieldTick, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedTick(); ok {
|
|
_spec.AddField(messages.FieldTick, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.MatchPlayerCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: messages.MatchPlayerTable,
|
|
Columns: []string{messages.MatchPlayerColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.MatchPlayerIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: messages.MatchPlayerTable,
|
|
Columns: []string{messages.MatchPlayerColumn},
|
|
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(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{messages.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// MessagesUpdateOne is the builder for updating a single Messages entity.
|
|
type MessagesUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *MessagesMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetMessage sets the "message" field.
|
|
func (_u *MessagesUpdateOne) SetMessage(v string) *MessagesUpdateOne {
|
|
_u.mutation.SetMessage(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMessage sets the "message" field if the given value is not nil.
|
|
func (_u *MessagesUpdateOne) SetNillableMessage(v *string) *MessagesUpdateOne {
|
|
if v != nil {
|
|
_u.SetMessage(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAllChat sets the "all_chat" field.
|
|
func (_u *MessagesUpdateOne) SetAllChat(v bool) *MessagesUpdateOne {
|
|
_u.mutation.SetAllChat(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAllChat sets the "all_chat" field if the given value is not nil.
|
|
func (_u *MessagesUpdateOne) SetNillableAllChat(v *bool) *MessagesUpdateOne {
|
|
if v != nil {
|
|
_u.SetAllChat(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTick sets the "tick" field.
|
|
func (_u *MessagesUpdateOne) SetTick(v int) *MessagesUpdateOne {
|
|
_u.mutation.ResetTick()
|
|
_u.mutation.SetTick(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTick sets the "tick" field if the given value is not nil.
|
|
func (_u *MessagesUpdateOne) SetNillableTick(v *int) *MessagesUpdateOne {
|
|
if v != nil {
|
|
_u.SetTick(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddTick adds value to the "tick" field.
|
|
func (_u *MessagesUpdateOne) AddTick(v int) *MessagesUpdateOne {
|
|
_u.mutation.AddTick(v)
|
|
return _u
|
|
}
|
|
|
|
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
|
|
func (_u *MessagesUpdateOne) SetMatchPlayerID(id int) *MessagesUpdateOne {
|
|
_u.mutation.SetMatchPlayerID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
|
|
func (_u *MessagesUpdateOne) SetNillableMatchPlayerID(id *int) *MessagesUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetMatchPlayerID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
|
|
func (_u *MessagesUpdateOne) SetMatchPlayer(v *MatchPlayer) *MessagesUpdateOne {
|
|
return _u.SetMatchPlayerID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the MessagesMutation object of the builder.
|
|
func (_u *MessagesUpdateOne) Mutation() *MessagesMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
|
|
func (_u *MessagesUpdateOne) ClearMatchPlayer() *MessagesUpdateOne {
|
|
_u.mutation.ClearMatchPlayer()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the MessagesUpdate builder.
|
|
func (_u *MessagesUpdateOne) Where(ps ...predicate.Messages) *MessagesUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *MessagesUpdateOne) Select(field string, fields ...string) *MessagesUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Messages entity.
|
|
func (_u *MessagesUpdateOne) Save(ctx context.Context) (*Messages, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *MessagesUpdateOne) SaveX(ctx context.Context) *Messages {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *MessagesUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *MessagesUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *MessagesUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MessagesUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *MessagesUpdateOne) sqlSave(ctx context.Context) (_node *Messages, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(messages.Table, messages.Columns, sqlgraph.NewFieldSpec(messages.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Messages.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := _u.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, messages.FieldID)
|
|
for _, f := range fields {
|
|
if !messages.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != messages.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.Message(); ok {
|
|
_spec.SetField(messages.FieldMessage, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.AllChat(); ok {
|
|
_spec.SetField(messages.FieldAllChat, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Tick(); ok {
|
|
_spec.SetField(messages.FieldTick, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedTick(); ok {
|
|
_spec.AddField(messages.FieldTick, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.MatchPlayerCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: messages.MatchPlayerTable,
|
|
Columns: []string{messages.MatchPlayerColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(matchplayer.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.MatchPlayerIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: messages.MatchPlayerTable,
|
|
Columns: []string{messages.MatchPlayerColumn},
|
|
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(_u.modifiers...)
|
|
_node = &Messages{config: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{messages.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|