mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-12-01 00:59:02 +08:00
366 lines
11 KiB
Go
366 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/chaitin/MonkeyCode/backend/db/mcpusertoolsetting"
|
|
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// MCPUserToolSettingUpdate is the builder for updating MCPUserToolSetting entities.
|
|
type MCPUserToolSettingUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *MCPUserToolSettingMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the MCPUserToolSettingUpdate builder.
|
|
func (_u *MCPUserToolSettingUpdate) Where(ps ...predicate.MCPUserToolSetting) *MCPUserToolSettingUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_u *MCPUserToolSettingUpdate) SetUserID(v uuid.UUID) *MCPUserToolSettingUpdate {
|
|
_u.mutation.SetUserID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (_u *MCPUserToolSettingUpdate) SetNillableUserID(v *uuid.UUID) *MCPUserToolSettingUpdate {
|
|
if v != nil {
|
|
_u.SetUserID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetToolID sets the "tool_id" field.
|
|
func (_u *MCPUserToolSettingUpdate) SetToolID(v uuid.UUID) *MCPUserToolSettingUpdate {
|
|
_u.mutation.SetToolID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableToolID sets the "tool_id" field if the given value is not nil.
|
|
func (_u *MCPUserToolSettingUpdate) SetNillableToolID(v *uuid.UUID) *MCPUserToolSettingUpdate {
|
|
if v != nil {
|
|
_u.SetToolID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_u *MCPUserToolSettingUpdate) SetEnabled(v bool) *MCPUserToolSettingUpdate {
|
|
_u.mutation.SetEnabled(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_u *MCPUserToolSettingUpdate) SetNillableEnabled(v *bool) *MCPUserToolSettingUpdate {
|
|
if v != nil {
|
|
_u.SetEnabled(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *MCPUserToolSettingUpdate) SetCreatedAt(v time.Time) *MCPUserToolSettingUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *MCPUserToolSettingUpdate) SetNillableCreatedAt(v *time.Time) *MCPUserToolSettingUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *MCPUserToolSettingUpdate) SetUpdatedAt(v time.Time) *MCPUserToolSettingUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the MCPUserToolSettingMutation object of the builder.
|
|
func (_u *MCPUserToolSettingUpdate) Mutation() *MCPUserToolSettingMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *MCPUserToolSettingUpdate) Save(ctx context.Context) (int, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *MCPUserToolSettingUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *MCPUserToolSettingUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *MCPUserToolSettingUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *MCPUserToolSettingUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := mcpusertoolsetting.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *MCPUserToolSettingUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MCPUserToolSettingUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *MCPUserToolSettingUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(mcpusertoolsetting.Table, mcpusertoolsetting.Columns, sqlgraph.NewFieldSpec(mcpusertoolsetting.FieldID, field.TypeUUID))
|
|
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.UserID(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldUserID, field.TypeUUID, value)
|
|
}
|
|
if value, ok := _u.mutation.ToolID(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldToolID, field.TypeUUID, value)
|
|
}
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldEnabled, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{mcpusertoolsetting.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// MCPUserToolSettingUpdateOne is the builder for updating a single MCPUserToolSetting entity.
|
|
type MCPUserToolSettingUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *MCPUserToolSettingMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetUserID(v uuid.UUID) *MCPUserToolSettingUpdateOne {
|
|
_u.mutation.SetUserID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetNillableUserID(v *uuid.UUID) *MCPUserToolSettingUpdateOne {
|
|
if v != nil {
|
|
_u.SetUserID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetToolID sets the "tool_id" field.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetToolID(v uuid.UUID) *MCPUserToolSettingUpdateOne {
|
|
_u.mutation.SetToolID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableToolID sets the "tool_id" field if the given value is not nil.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetNillableToolID(v *uuid.UUID) *MCPUserToolSettingUpdateOne {
|
|
if v != nil {
|
|
_u.SetToolID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetEnabled(v bool) *MCPUserToolSettingUpdateOne {
|
|
_u.mutation.SetEnabled(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetNillableEnabled(v *bool) *MCPUserToolSettingUpdateOne {
|
|
if v != nil {
|
|
_u.SetEnabled(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetCreatedAt(v time.Time) *MCPUserToolSettingUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetNillableCreatedAt(v *time.Time) *MCPUserToolSettingUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *MCPUserToolSettingUpdateOne) SetUpdatedAt(v time.Time) *MCPUserToolSettingUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the MCPUserToolSettingMutation object of the builder.
|
|
func (_u *MCPUserToolSettingUpdateOne) Mutation() *MCPUserToolSettingMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the MCPUserToolSettingUpdate builder.
|
|
func (_u *MCPUserToolSettingUpdateOne) Where(ps ...predicate.MCPUserToolSetting) *MCPUserToolSettingUpdateOne {
|
|
_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 *MCPUserToolSettingUpdateOne) Select(field string, fields ...string) *MCPUserToolSettingUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated MCPUserToolSetting entity.
|
|
func (_u *MCPUserToolSettingUpdateOne) Save(ctx context.Context) (*MCPUserToolSetting, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *MCPUserToolSettingUpdateOne) SaveX(ctx context.Context) *MCPUserToolSetting {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *MCPUserToolSettingUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *MCPUserToolSettingUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *MCPUserToolSettingUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := mcpusertoolsetting.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *MCPUserToolSettingUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MCPUserToolSettingUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *MCPUserToolSettingUpdateOne) sqlSave(ctx context.Context) (_node *MCPUserToolSetting, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(mcpusertoolsetting.Table, mcpusertoolsetting.Columns, sqlgraph.NewFieldSpec(mcpusertoolsetting.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "MCPUserToolSetting.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, mcpusertoolsetting.FieldID)
|
|
for _, f := range fields {
|
|
if !mcpusertoolsetting.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != mcpusertoolsetting.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.UserID(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldUserID, field.TypeUUID, value)
|
|
}
|
|
if value, ok := _u.mutation.ToolID(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldToolID, field.TypeUUID, value)
|
|
}
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldEnabled, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &MCPUserToolSetting{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{mcpusertoolsetting.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|