// 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" "within.website/x/cmd/tourian/ent/chatmessage" "within.website/x/cmd/tourian/ent/predicate" ) // ChatMessageUpdate is the builder for updating ChatMessage entities. type ChatMessageUpdate struct { config hooks []Hook mutation *ChatMessageMutation } // Where appends a list predicates to the ChatMessageUpdate builder. func (cmu *ChatMessageUpdate) Where(ps ...predicate.ChatMessage) *ChatMessageUpdate { cmu.mutation.Where(ps...) return cmu } // SetConversationID sets the "conversation_id" field. func (cmu *ChatMessageUpdate) SetConversationID(s string) *ChatMessageUpdate { cmu.mutation.SetConversationID(s) return cmu } // SetNillableConversationID sets the "conversation_id" field if the given value is not nil. func (cmu *ChatMessageUpdate) SetNillableConversationID(s *string) *ChatMessageUpdate { if s != nil { cmu.SetConversationID(*s) } return cmu } // SetRole sets the "role" field. func (cmu *ChatMessageUpdate) SetRole(s string) *ChatMessageUpdate { cmu.mutation.SetRole(s) return cmu } // SetNillableRole sets the "role" field if the given value is not nil. func (cmu *ChatMessageUpdate) SetNillableRole(s *string) *ChatMessageUpdate { if s != nil { cmu.SetRole(*s) } return cmu } // SetContent sets the "content" field. func (cmu *ChatMessageUpdate) SetContent(s string) *ChatMessageUpdate { cmu.mutation.SetContent(s) return cmu } // SetNillableContent sets the "content" field if the given value is not nil. func (cmu *ChatMessageUpdate) SetNillableContent(s *string) *ChatMessageUpdate { if s != nil { cmu.SetContent(*s) } return cmu } // Mutation returns the ChatMessageMutation object of the builder. func (cmu *ChatMessageUpdate) Mutation() *ChatMessageMutation { return cmu.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (cmu *ChatMessageUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, cmu.sqlSave, cmu.mutation, cmu.hooks) } // SaveX is like Save, but panics if an error occurs. func (cmu *ChatMessageUpdate) SaveX(ctx context.Context) int { affected, err := cmu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (cmu *ChatMessageUpdate) Exec(ctx context.Context) error { _, err := cmu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (cmu *ChatMessageUpdate) ExecX(ctx context.Context) { if err := cmu.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (cmu *ChatMessageUpdate) check() error { if v, ok := cmu.mutation.ConversationID(); ok { if err := chatmessage.ConversationIDValidator(v); err != nil { return &ValidationError{Name: "conversation_id", err: fmt.Errorf(`ent: validator failed for field "ChatMessage.conversation_id": %w`, err)} } } if v, ok := cmu.mutation.Role(); ok { if err := chatmessage.RoleValidator(v); err != nil { return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "ChatMessage.role": %w`, err)} } } if v, ok := cmu.mutation.Content(); ok { if err := chatmessage.ContentValidator(v); err != nil { return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "ChatMessage.content": %w`, err)} } } return nil } func (cmu *ChatMessageUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := cmu.check(); err != nil { return n, err } _spec := sqlgraph.NewUpdateSpec(chatmessage.Table, chatmessage.Columns, sqlgraph.NewFieldSpec(chatmessage.FieldID, field.TypeString)) if ps := cmu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := cmu.mutation.ConversationID(); ok { _spec.SetField(chatmessage.FieldConversationID, field.TypeString, value) } if value, ok := cmu.mutation.Role(); ok { _spec.SetField(chatmessage.FieldRole, field.TypeString, value) } if value, ok := cmu.mutation.Content(); ok { _spec.SetField(chatmessage.FieldContent, field.TypeString, value) } if n, err = sqlgraph.UpdateNodes(ctx, cmu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{chatmessage.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } cmu.mutation.done = true return n, nil } // ChatMessageUpdateOne is the builder for updating a single ChatMessage entity. type ChatMessageUpdateOne struct { config fields []string hooks []Hook mutation *ChatMessageMutation } // SetConversationID sets the "conversation_id" field. func (cmuo *ChatMessageUpdateOne) SetConversationID(s string) *ChatMessageUpdateOne { cmuo.mutation.SetConversationID(s) return cmuo } // SetNillableConversationID sets the "conversation_id" field if the given value is not nil. func (cmuo *ChatMessageUpdateOne) SetNillableConversationID(s *string) *ChatMessageUpdateOne { if s != nil { cmuo.SetConversationID(*s) } return cmuo } // SetRole sets the "role" field. func (cmuo *ChatMessageUpdateOne) SetRole(s string) *ChatMessageUpdateOne { cmuo.mutation.SetRole(s) return cmuo } // SetNillableRole sets the "role" field if the given value is not nil. func (cmuo *ChatMessageUpdateOne) SetNillableRole(s *string) *ChatMessageUpdateOne { if s != nil { cmuo.SetRole(*s) } return cmuo } // SetContent sets the "content" field. func (cmuo *ChatMessageUpdateOne) SetContent(s string) *ChatMessageUpdateOne { cmuo.mutation.SetContent(s) return cmuo } // SetNillableContent sets the "content" field if the given value is not nil. func (cmuo *ChatMessageUpdateOne) SetNillableContent(s *string) *ChatMessageUpdateOne { if s != nil { cmuo.SetContent(*s) } return cmuo } // Mutation returns the ChatMessageMutation object of the builder. func (cmuo *ChatMessageUpdateOne) Mutation() *ChatMessageMutation { return cmuo.mutation } // Where appends a list predicates to the ChatMessageUpdate builder. func (cmuo *ChatMessageUpdateOne) Where(ps ...predicate.ChatMessage) *ChatMessageUpdateOne { cmuo.mutation.Where(ps...) return cmuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (cmuo *ChatMessageUpdateOne) Select(field string, fields ...string) *ChatMessageUpdateOne { cmuo.fields = append([]string{field}, fields...) return cmuo } // Save executes the query and returns the updated ChatMessage entity. func (cmuo *ChatMessageUpdateOne) Save(ctx context.Context) (*ChatMessage, error) { return withHooks(ctx, cmuo.sqlSave, cmuo.mutation, cmuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (cmuo *ChatMessageUpdateOne) SaveX(ctx context.Context) *ChatMessage { node, err := cmuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (cmuo *ChatMessageUpdateOne) Exec(ctx context.Context) error { _, err := cmuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (cmuo *ChatMessageUpdateOne) ExecX(ctx context.Context) { if err := cmuo.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (cmuo *ChatMessageUpdateOne) check() error { if v, ok := cmuo.mutation.ConversationID(); ok { if err := chatmessage.ConversationIDValidator(v); err != nil { return &ValidationError{Name: "conversation_id", err: fmt.Errorf(`ent: validator failed for field "ChatMessage.conversation_id": %w`, err)} } } if v, ok := cmuo.mutation.Role(); ok { if err := chatmessage.RoleValidator(v); err != nil { return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "ChatMessage.role": %w`, err)} } } if v, ok := cmuo.mutation.Content(); ok { if err := chatmessage.ContentValidator(v); err != nil { return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "ChatMessage.content": %w`, err)} } } return nil } func (cmuo *ChatMessageUpdateOne) sqlSave(ctx context.Context) (_node *ChatMessage, err error) { if err := cmuo.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(chatmessage.Table, chatmessage.Columns, sqlgraph.NewFieldSpec(chatmessage.FieldID, field.TypeString)) id, ok := cmuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChatMessage.id" for update`)} } _spec.Node.ID.Value = id if fields := cmuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, chatmessage.FieldID) for _, f := range fields { if !chatmessage.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != chatmessage.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := cmuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := cmuo.mutation.ConversationID(); ok { _spec.SetField(chatmessage.FieldConversationID, field.TypeString, value) } if value, ok := cmuo.mutation.Role(); ok { _spec.SetField(chatmessage.FieldRole, field.TypeString, value) } if value, ok := cmuo.mutation.Content(); ok { _spec.SetField(chatmessage.FieldContent, field.TypeString, value) } _node = &ChatMessage{config: cmuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, cmuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{chatmessage.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } cmuo.mutation.done = true return _node, nil }