added chat messages
This commit is contained in:
412
ent/messages_update.go
Normal file
412
ent/messages_update.go
Normal file
@@ -0,0 +1,412 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"csgowtfd/ent/matchplayer"
|
||||
"csgowtfd/ent/messages"
|
||||
"csgowtfd/ent/predicate"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MessagesUpdate is the builder for updating Messages entities.
|
||||
type MessagesUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *MessagesMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MessagesUpdate builder.
|
||||
func (mu *MessagesUpdate) Where(ps ...predicate.Messages) *MessagesUpdate {
|
||||
mu.mutation.Where(ps...)
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetMessage sets the "message" field.
|
||||
func (mu *MessagesUpdate) SetMessage(s string) *MessagesUpdate {
|
||||
mu.mutation.SetMessage(s)
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetAllChat sets the "all_chat" field.
|
||||
func (mu *MessagesUpdate) SetAllChat(b bool) *MessagesUpdate {
|
||||
mu.mutation.SetAllChat(b)
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
|
||||
func (mu *MessagesUpdate) SetMatchPlayerID(id int) *MessagesUpdate {
|
||||
mu.mutation.SetMatchPlayerID(id)
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
|
||||
func (mu *MessagesUpdate) SetNillableMatchPlayerID(id *int) *MessagesUpdate {
|
||||
if id != nil {
|
||||
mu = mu.SetMatchPlayerID(*id)
|
||||
}
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
|
||||
func (mu *MessagesUpdate) SetMatchPlayer(m *MatchPlayer) *MessagesUpdate {
|
||||
return mu.SetMatchPlayerID(m.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the MessagesMutation object of the builder.
|
||||
func (mu *MessagesUpdate) Mutation() *MessagesMutation {
|
||||
return mu.mutation
|
||||
}
|
||||
|
||||
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
|
||||
func (mu *MessagesUpdate) ClearMatchPlayer() *MessagesUpdate {
|
||||
mu.mutation.ClearMatchPlayer()
|
||||
return mu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (mu *MessagesUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(mu.hooks) == 0 {
|
||||
affected, err = mu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*MessagesMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
mu.mutation = mutation
|
||||
affected, err = mu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(mu.hooks) - 1; i >= 0; i-- {
|
||||
if mu.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = mu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, mu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (mu *MessagesUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := mu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (mu *MessagesUpdate) Exec(ctx context.Context) error {
|
||||
_, err := mu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (mu *MessagesUpdate) ExecX(ctx context.Context) {
|
||||
if err := mu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (mu *MessagesUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: messages.Table,
|
||||
Columns: messages.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: messages.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := mu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := mu.mutation.Message(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: messages.FieldMessage,
|
||||
})
|
||||
}
|
||||
if value, ok := mu.mutation.AllChat(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: messages.FieldAllChat,
|
||||
})
|
||||
}
|
||||
if mu.mutation.MatchPlayerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: messages.MatchPlayerTable,
|
||||
Columns: []string{messages.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 := mu.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.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, mu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{messages.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// MessagesUpdateOne is the builder for updating a single Messages entity.
|
||||
type MessagesUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *MessagesMutation
|
||||
}
|
||||
|
||||
// SetMessage sets the "message" field.
|
||||
func (muo *MessagesUpdateOne) SetMessage(s string) *MessagesUpdateOne {
|
||||
muo.mutation.SetMessage(s)
|
||||
return muo
|
||||
}
|
||||
|
||||
// SetAllChat sets the "all_chat" field.
|
||||
func (muo *MessagesUpdateOne) SetAllChat(b bool) *MessagesUpdateOne {
|
||||
muo.mutation.SetAllChat(b)
|
||||
return muo
|
||||
}
|
||||
|
||||
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
|
||||
func (muo *MessagesUpdateOne) SetMatchPlayerID(id int) *MessagesUpdateOne {
|
||||
muo.mutation.SetMatchPlayerID(id)
|
||||
return muo
|
||||
}
|
||||
|
||||
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
|
||||
func (muo *MessagesUpdateOne) SetNillableMatchPlayerID(id *int) *MessagesUpdateOne {
|
||||
if id != nil {
|
||||
muo = muo.SetMatchPlayerID(*id)
|
||||
}
|
||||
return muo
|
||||
}
|
||||
|
||||
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
|
||||
func (muo *MessagesUpdateOne) SetMatchPlayer(m *MatchPlayer) *MessagesUpdateOne {
|
||||
return muo.SetMatchPlayerID(m.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the MessagesMutation object of the builder.
|
||||
func (muo *MessagesUpdateOne) Mutation() *MessagesMutation {
|
||||
return muo.mutation
|
||||
}
|
||||
|
||||
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
|
||||
func (muo *MessagesUpdateOne) ClearMatchPlayer() *MessagesUpdateOne {
|
||||
muo.mutation.ClearMatchPlayer()
|
||||
return muo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (muo *MessagesUpdateOne) Select(field string, fields ...string) *MessagesUpdateOne {
|
||||
muo.fields = append([]string{field}, fields...)
|
||||
return muo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Messages entity.
|
||||
func (muo *MessagesUpdateOne) Save(ctx context.Context) (*Messages, error) {
|
||||
var (
|
||||
err error
|
||||
node *Messages
|
||||
)
|
||||
if len(muo.hooks) == 0 {
|
||||
node, err = muo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*MessagesMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
muo.mutation = mutation
|
||||
node, err = muo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(muo.hooks) - 1; i >= 0; i-- {
|
||||
if muo.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = muo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, muo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (muo *MessagesUpdateOne) SaveX(ctx context.Context) *Messages {
|
||||
node, err := muo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (muo *MessagesUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := muo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (muo *MessagesUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := muo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (muo *MessagesUpdateOne) sqlSave(ctx context.Context) (_node *Messages, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: messages.Table,
|
||||
Columns: messages.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: messages.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := muo.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 := muo.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 := muo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := muo.mutation.Message(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: messages.FieldMessage,
|
||||
})
|
||||
}
|
||||
if value, ok := muo.mutation.AllChat(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: messages.FieldAllChat,
|
||||
})
|
||||
}
|
||||
if muo.mutation.MatchPlayerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: messages.MatchPlayerTable,
|
||||
Columns: []string{messages.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 := muo.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.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 = &Messages{config: muo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{messages.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user