Files
MonkeyCode/backend/db/mcptool_update.go

933 lines
27 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/mcptool"
"github.com/chaitin/MonkeyCode/backend/db/mcpupstream"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/google/uuid"
)
// MCPToolUpdate is the builder for updating MCPTool entities.
type MCPToolUpdate struct {
config
hooks []Hook
mutation *MCPToolMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the MCPToolUpdate builder.
func (_u *MCPToolUpdate) Where(ps ...predicate.MCPTool) *MCPToolUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *MCPToolUpdate) SetDeletedAt(v time.Time) *MCPToolUpdate {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableDeletedAt(v *time.Time) *MCPToolUpdate {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *MCPToolUpdate) ClearDeletedAt() *MCPToolUpdate {
_u.mutation.ClearDeletedAt()
return _u
}
// SetUpstreamID sets the "upstream_id" field.
func (_u *MCPToolUpdate) SetUpstreamID(v uuid.UUID) *MCPToolUpdate {
_u.mutation.SetUpstreamID(v)
return _u
}
// SetNillableUpstreamID sets the "upstream_id" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableUpstreamID(v *uuid.UUID) *MCPToolUpdate {
if v != nil {
_u.SetUpstreamID(*v)
}
return _u
}
// SetName sets the "name" field.
func (_u *MCPToolUpdate) SetName(v string) *MCPToolUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableName(v *string) *MCPToolUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetNamespacedName sets the "namespaced_name" field.
func (_u *MCPToolUpdate) SetNamespacedName(v string) *MCPToolUpdate {
_u.mutation.SetNamespacedName(v)
return _u
}
// SetNillableNamespacedName sets the "namespaced_name" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableNamespacedName(v *string) *MCPToolUpdate {
if v != nil {
_u.SetNamespacedName(*v)
}
return _u
}
// SetScope sets the "scope" field.
func (_u *MCPToolUpdate) SetScope(v mcptool.Scope) *MCPToolUpdate {
_u.mutation.SetScope(v)
return _u
}
// SetNillableScope sets the "scope" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableScope(v *mcptool.Scope) *MCPToolUpdate {
if v != nil {
_u.SetScope(*v)
}
return _u
}
// SetUserID sets the "user_id" field.
func (_u *MCPToolUpdate) SetUserID(v uuid.UUID) *MCPToolUpdate {
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableUserID(v *uuid.UUID) *MCPToolUpdate {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// ClearUserID clears the value of the "user_id" field.
func (_u *MCPToolUpdate) ClearUserID() *MCPToolUpdate {
_u.mutation.ClearUserID()
return _u
}
// SetDescription sets the "description" field.
func (_u *MCPToolUpdate) SetDescription(v string) *MCPToolUpdate {
_u.mutation.SetDescription(v)
return _u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableDescription(v *string) *MCPToolUpdate {
if v != nil {
_u.SetDescription(*v)
}
return _u
}
// ClearDescription clears the value of the "description" field.
func (_u *MCPToolUpdate) ClearDescription() *MCPToolUpdate {
_u.mutation.ClearDescription()
return _u
}
// SetInputSchema sets the "input_schema" field.
func (_u *MCPToolUpdate) SetInputSchema(v map[string]interface{}) *MCPToolUpdate {
_u.mutation.SetInputSchema(v)
return _u
}
// ClearInputSchema clears the value of the "input_schema" field.
func (_u *MCPToolUpdate) ClearInputSchema() *MCPToolUpdate {
_u.mutation.ClearInputSchema()
return _u
}
// SetPrice sets the "price" field.
func (_u *MCPToolUpdate) SetPrice(v int64) *MCPToolUpdate {
_u.mutation.ResetPrice()
_u.mutation.SetPrice(v)
return _u
}
// SetNillablePrice sets the "price" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillablePrice(v *int64) *MCPToolUpdate {
if v != nil {
_u.SetPrice(*v)
}
return _u
}
// AddPrice adds value to the "price" field.
func (_u *MCPToolUpdate) AddPrice(v int64) *MCPToolUpdate {
_u.mutation.AddPrice(v)
return _u
}
// SetEnabled sets the "enabled" field.
func (_u *MCPToolUpdate) SetEnabled(v bool) *MCPToolUpdate {
_u.mutation.SetEnabled(v)
return _u
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableEnabled(v *bool) *MCPToolUpdate {
if v != nil {
_u.SetEnabled(*v)
}
return _u
}
// SetVersionHash sets the "version_hash" field.
func (_u *MCPToolUpdate) SetVersionHash(v string) *MCPToolUpdate {
_u.mutation.SetVersionHash(v)
return _u
}
// SetNillableVersionHash sets the "version_hash" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableVersionHash(v *string) *MCPToolUpdate {
if v != nil {
_u.SetVersionHash(*v)
}
return _u
}
// ClearVersionHash clears the value of the "version_hash" field.
func (_u *MCPToolUpdate) ClearVersionHash() *MCPToolUpdate {
_u.mutation.ClearVersionHash()
return _u
}
// SetSyncedAt sets the "synced_at" field.
func (_u *MCPToolUpdate) SetSyncedAt(v time.Time) *MCPToolUpdate {
_u.mutation.SetSyncedAt(v)
return _u
}
// SetNillableSyncedAt sets the "synced_at" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableSyncedAt(v *time.Time) *MCPToolUpdate {
if v != nil {
_u.SetSyncedAt(*v)
}
return _u
}
// ClearSyncedAt clears the value of the "synced_at" field.
func (_u *MCPToolUpdate) ClearSyncedAt() *MCPToolUpdate {
_u.mutation.ClearSyncedAt()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *MCPToolUpdate) SetCreatedAt(v time.Time) *MCPToolUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *MCPToolUpdate) SetNillableCreatedAt(v *time.Time) *MCPToolUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *MCPToolUpdate) SetUpdatedAt(v time.Time) *MCPToolUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetUpstream sets the "upstream" edge to the MCPUpstream entity.
func (_u *MCPToolUpdate) SetUpstream(v *MCPUpstream) *MCPToolUpdate {
return _u.SetUpstreamID(v.ID)
}
// Mutation returns the MCPToolMutation object of the builder.
func (_u *MCPToolUpdate) Mutation() *MCPToolMutation {
return _u.mutation
}
// ClearUpstream clears the "upstream" edge to the MCPUpstream entity.
func (_u *MCPToolUpdate) ClearUpstream() *MCPToolUpdate {
_u.mutation.ClearUpstream()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *MCPToolUpdate) Save(ctx context.Context) (int, error) {
if err := _u.defaults(); err != nil {
return 0, err
}
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *MCPToolUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *MCPToolUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *MCPToolUpdate) 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 *MCPToolUpdate) defaults() error {
if _, ok := _u.mutation.UpdatedAt(); !ok {
if mcptool.UpdateDefaultUpdatedAt == nil {
return fmt.Errorf("db: uninitialized mcptool.UpdateDefaultUpdatedAt (forgotten import db/runtime?)")
}
v := mcptool.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_u *MCPToolUpdate) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := mcptool.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "MCPTool.name": %w`, err)}
}
}
if v, ok := _u.mutation.NamespacedName(); ok {
if err := mcptool.NamespacedNameValidator(v); err != nil {
return &ValidationError{Name: "namespaced_name", err: fmt.Errorf(`db: validator failed for field "MCPTool.namespaced_name": %w`, err)}
}
}
if v, ok := _u.mutation.Scope(); ok {
if err := mcptool.ScopeValidator(v); err != nil {
return &ValidationError{Name: "scope", err: fmt.Errorf(`db: validator failed for field "MCPTool.scope": %w`, err)}
}
}
if v, ok := _u.mutation.VersionHash(); ok {
if err := mcptool.VersionHashValidator(v); err != nil {
return &ValidationError{Name: "version_hash", err: fmt.Errorf(`db: validator failed for field "MCPTool.version_hash": %w`, err)}
}
}
if _u.mutation.UpstreamCleared() && len(_u.mutation.UpstreamIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "MCPTool.upstream"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *MCPToolUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MCPToolUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *MCPToolUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(mcptool.Table, mcptool.Columns, sqlgraph.NewFieldSpec(mcptool.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.DeletedAt(); ok {
_spec.SetField(mcptool.FieldDeletedAt, field.TypeTime, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(mcptool.FieldDeletedAt, field.TypeTime)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(mcptool.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.NamespacedName(); ok {
_spec.SetField(mcptool.FieldNamespacedName, field.TypeString, value)
}
if value, ok := _u.mutation.Scope(); ok {
_spec.SetField(mcptool.FieldScope, field.TypeEnum, value)
}
if value, ok := _u.mutation.UserID(); ok {
_spec.SetField(mcptool.FieldUserID, field.TypeUUID, value)
}
if _u.mutation.UserIDCleared() {
_spec.ClearField(mcptool.FieldUserID, field.TypeUUID)
}
if value, ok := _u.mutation.Description(); ok {
_spec.SetField(mcptool.FieldDescription, field.TypeString, value)
}
if _u.mutation.DescriptionCleared() {
_spec.ClearField(mcptool.FieldDescription, field.TypeString)
}
if value, ok := _u.mutation.InputSchema(); ok {
_spec.SetField(mcptool.FieldInputSchema, field.TypeJSON, value)
}
if _u.mutation.InputSchemaCleared() {
_spec.ClearField(mcptool.FieldInputSchema, field.TypeJSON)
}
if value, ok := _u.mutation.Price(); ok {
_spec.SetField(mcptool.FieldPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedPrice(); ok {
_spec.AddField(mcptool.FieldPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.Enabled(); ok {
_spec.SetField(mcptool.FieldEnabled, field.TypeBool, value)
}
if value, ok := _u.mutation.VersionHash(); ok {
_spec.SetField(mcptool.FieldVersionHash, field.TypeString, value)
}
if _u.mutation.VersionHashCleared() {
_spec.ClearField(mcptool.FieldVersionHash, field.TypeString)
}
if value, ok := _u.mutation.SyncedAt(); ok {
_spec.SetField(mcptool.FieldSyncedAt, field.TypeTime, value)
}
if _u.mutation.SyncedAtCleared() {
_spec.ClearField(mcptool.FieldSyncedAt, field.TypeTime)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(mcptool.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(mcptool.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.UpstreamCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: mcptool.UpstreamTable,
Columns: []string{mcptool.UpstreamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(mcpupstream.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.UpstreamIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: mcptool.UpstreamTable,
Columns: []string{mcptool.UpstreamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(mcpupstream.FieldID, field.TypeUUID),
},
}
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{mcptool.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// MCPToolUpdateOne is the builder for updating a single MCPTool entity.
type MCPToolUpdateOne struct {
config
fields []string
hooks []Hook
mutation *MCPToolMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *MCPToolUpdateOne) SetDeletedAt(v time.Time) *MCPToolUpdateOne {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableDeletedAt(v *time.Time) *MCPToolUpdateOne {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *MCPToolUpdateOne) ClearDeletedAt() *MCPToolUpdateOne {
_u.mutation.ClearDeletedAt()
return _u
}
// SetUpstreamID sets the "upstream_id" field.
func (_u *MCPToolUpdateOne) SetUpstreamID(v uuid.UUID) *MCPToolUpdateOne {
_u.mutation.SetUpstreamID(v)
return _u
}
// SetNillableUpstreamID sets the "upstream_id" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableUpstreamID(v *uuid.UUID) *MCPToolUpdateOne {
if v != nil {
_u.SetUpstreamID(*v)
}
return _u
}
// SetName sets the "name" field.
func (_u *MCPToolUpdateOne) SetName(v string) *MCPToolUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableName(v *string) *MCPToolUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetNamespacedName sets the "namespaced_name" field.
func (_u *MCPToolUpdateOne) SetNamespacedName(v string) *MCPToolUpdateOne {
_u.mutation.SetNamespacedName(v)
return _u
}
// SetNillableNamespacedName sets the "namespaced_name" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableNamespacedName(v *string) *MCPToolUpdateOne {
if v != nil {
_u.SetNamespacedName(*v)
}
return _u
}
// SetScope sets the "scope" field.
func (_u *MCPToolUpdateOne) SetScope(v mcptool.Scope) *MCPToolUpdateOne {
_u.mutation.SetScope(v)
return _u
}
// SetNillableScope sets the "scope" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableScope(v *mcptool.Scope) *MCPToolUpdateOne {
if v != nil {
_u.SetScope(*v)
}
return _u
}
// SetUserID sets the "user_id" field.
func (_u *MCPToolUpdateOne) SetUserID(v uuid.UUID) *MCPToolUpdateOne {
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableUserID(v *uuid.UUID) *MCPToolUpdateOne {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// ClearUserID clears the value of the "user_id" field.
func (_u *MCPToolUpdateOne) ClearUserID() *MCPToolUpdateOne {
_u.mutation.ClearUserID()
return _u
}
// SetDescription sets the "description" field.
func (_u *MCPToolUpdateOne) SetDescription(v string) *MCPToolUpdateOne {
_u.mutation.SetDescription(v)
return _u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableDescription(v *string) *MCPToolUpdateOne {
if v != nil {
_u.SetDescription(*v)
}
return _u
}
// ClearDescription clears the value of the "description" field.
func (_u *MCPToolUpdateOne) ClearDescription() *MCPToolUpdateOne {
_u.mutation.ClearDescription()
return _u
}
// SetInputSchema sets the "input_schema" field.
func (_u *MCPToolUpdateOne) SetInputSchema(v map[string]interface{}) *MCPToolUpdateOne {
_u.mutation.SetInputSchema(v)
return _u
}
// ClearInputSchema clears the value of the "input_schema" field.
func (_u *MCPToolUpdateOne) ClearInputSchema() *MCPToolUpdateOne {
_u.mutation.ClearInputSchema()
return _u
}
// SetPrice sets the "price" field.
func (_u *MCPToolUpdateOne) SetPrice(v int64) *MCPToolUpdateOne {
_u.mutation.ResetPrice()
_u.mutation.SetPrice(v)
return _u
}
// SetNillablePrice sets the "price" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillablePrice(v *int64) *MCPToolUpdateOne {
if v != nil {
_u.SetPrice(*v)
}
return _u
}
// AddPrice adds value to the "price" field.
func (_u *MCPToolUpdateOne) AddPrice(v int64) *MCPToolUpdateOne {
_u.mutation.AddPrice(v)
return _u
}
// SetEnabled sets the "enabled" field.
func (_u *MCPToolUpdateOne) SetEnabled(v bool) *MCPToolUpdateOne {
_u.mutation.SetEnabled(v)
return _u
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableEnabled(v *bool) *MCPToolUpdateOne {
if v != nil {
_u.SetEnabled(*v)
}
return _u
}
// SetVersionHash sets the "version_hash" field.
func (_u *MCPToolUpdateOne) SetVersionHash(v string) *MCPToolUpdateOne {
_u.mutation.SetVersionHash(v)
return _u
}
// SetNillableVersionHash sets the "version_hash" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableVersionHash(v *string) *MCPToolUpdateOne {
if v != nil {
_u.SetVersionHash(*v)
}
return _u
}
// ClearVersionHash clears the value of the "version_hash" field.
func (_u *MCPToolUpdateOne) ClearVersionHash() *MCPToolUpdateOne {
_u.mutation.ClearVersionHash()
return _u
}
// SetSyncedAt sets the "synced_at" field.
func (_u *MCPToolUpdateOne) SetSyncedAt(v time.Time) *MCPToolUpdateOne {
_u.mutation.SetSyncedAt(v)
return _u
}
// SetNillableSyncedAt sets the "synced_at" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableSyncedAt(v *time.Time) *MCPToolUpdateOne {
if v != nil {
_u.SetSyncedAt(*v)
}
return _u
}
// ClearSyncedAt clears the value of the "synced_at" field.
func (_u *MCPToolUpdateOne) ClearSyncedAt() *MCPToolUpdateOne {
_u.mutation.ClearSyncedAt()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *MCPToolUpdateOne) SetCreatedAt(v time.Time) *MCPToolUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *MCPToolUpdateOne) SetNillableCreatedAt(v *time.Time) *MCPToolUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *MCPToolUpdateOne) SetUpdatedAt(v time.Time) *MCPToolUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetUpstream sets the "upstream" edge to the MCPUpstream entity.
func (_u *MCPToolUpdateOne) SetUpstream(v *MCPUpstream) *MCPToolUpdateOne {
return _u.SetUpstreamID(v.ID)
}
// Mutation returns the MCPToolMutation object of the builder.
func (_u *MCPToolUpdateOne) Mutation() *MCPToolMutation {
return _u.mutation
}
// ClearUpstream clears the "upstream" edge to the MCPUpstream entity.
func (_u *MCPToolUpdateOne) ClearUpstream() *MCPToolUpdateOne {
_u.mutation.ClearUpstream()
return _u
}
// Where appends a list predicates to the MCPToolUpdate builder.
func (_u *MCPToolUpdateOne) Where(ps ...predicate.MCPTool) *MCPToolUpdateOne {
_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 *MCPToolUpdateOne) Select(field string, fields ...string) *MCPToolUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated MCPTool entity.
func (_u *MCPToolUpdateOne) Save(ctx context.Context) (*MCPTool, error) {
if err := _u.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *MCPToolUpdateOne) SaveX(ctx context.Context) *MCPTool {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *MCPToolUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *MCPToolUpdateOne) 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 *MCPToolUpdateOne) defaults() error {
if _, ok := _u.mutation.UpdatedAt(); !ok {
if mcptool.UpdateDefaultUpdatedAt == nil {
return fmt.Errorf("db: uninitialized mcptool.UpdateDefaultUpdatedAt (forgotten import db/runtime?)")
}
v := mcptool.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_u *MCPToolUpdateOne) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := mcptool.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "MCPTool.name": %w`, err)}
}
}
if v, ok := _u.mutation.NamespacedName(); ok {
if err := mcptool.NamespacedNameValidator(v); err != nil {
return &ValidationError{Name: "namespaced_name", err: fmt.Errorf(`db: validator failed for field "MCPTool.namespaced_name": %w`, err)}
}
}
if v, ok := _u.mutation.Scope(); ok {
if err := mcptool.ScopeValidator(v); err != nil {
return &ValidationError{Name: "scope", err: fmt.Errorf(`db: validator failed for field "MCPTool.scope": %w`, err)}
}
}
if v, ok := _u.mutation.VersionHash(); ok {
if err := mcptool.VersionHashValidator(v); err != nil {
return &ValidationError{Name: "version_hash", err: fmt.Errorf(`db: validator failed for field "MCPTool.version_hash": %w`, err)}
}
}
if _u.mutation.UpstreamCleared() && len(_u.mutation.UpstreamIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "MCPTool.upstream"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *MCPToolUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MCPToolUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *MCPToolUpdateOne) sqlSave(ctx context.Context) (_node *MCPTool, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(mcptool.Table, mcptool.Columns, sqlgraph.NewFieldSpec(mcptool.FieldID, field.TypeUUID))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "MCPTool.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, mcptool.FieldID)
for _, f := range fields {
if !mcptool.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != mcptool.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.DeletedAt(); ok {
_spec.SetField(mcptool.FieldDeletedAt, field.TypeTime, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(mcptool.FieldDeletedAt, field.TypeTime)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(mcptool.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.NamespacedName(); ok {
_spec.SetField(mcptool.FieldNamespacedName, field.TypeString, value)
}
if value, ok := _u.mutation.Scope(); ok {
_spec.SetField(mcptool.FieldScope, field.TypeEnum, value)
}
if value, ok := _u.mutation.UserID(); ok {
_spec.SetField(mcptool.FieldUserID, field.TypeUUID, value)
}
if _u.mutation.UserIDCleared() {
_spec.ClearField(mcptool.FieldUserID, field.TypeUUID)
}
if value, ok := _u.mutation.Description(); ok {
_spec.SetField(mcptool.FieldDescription, field.TypeString, value)
}
if _u.mutation.DescriptionCleared() {
_spec.ClearField(mcptool.FieldDescription, field.TypeString)
}
if value, ok := _u.mutation.InputSchema(); ok {
_spec.SetField(mcptool.FieldInputSchema, field.TypeJSON, value)
}
if _u.mutation.InputSchemaCleared() {
_spec.ClearField(mcptool.FieldInputSchema, field.TypeJSON)
}
if value, ok := _u.mutation.Price(); ok {
_spec.SetField(mcptool.FieldPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedPrice(); ok {
_spec.AddField(mcptool.FieldPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.Enabled(); ok {
_spec.SetField(mcptool.FieldEnabled, field.TypeBool, value)
}
if value, ok := _u.mutation.VersionHash(); ok {
_spec.SetField(mcptool.FieldVersionHash, field.TypeString, value)
}
if _u.mutation.VersionHashCleared() {
_spec.ClearField(mcptool.FieldVersionHash, field.TypeString)
}
if value, ok := _u.mutation.SyncedAt(); ok {
_spec.SetField(mcptool.FieldSyncedAt, field.TypeTime, value)
}
if _u.mutation.SyncedAtCleared() {
_spec.ClearField(mcptool.FieldSyncedAt, field.TypeTime)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(mcptool.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(mcptool.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.UpstreamCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: mcptool.UpstreamTable,
Columns: []string{mcptool.UpstreamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(mcpupstream.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.UpstreamIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: mcptool.UpstreamTable,
Columns: []string{mcptool.UpstreamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(mcpupstream.FieldID, field.TypeUUID),
},
}
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 = &MCPTool{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{mcptool.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}