// 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/agentplugin" "github.com/chaitin/MonkeyCode/backend/db/agentpluginrepo" "github.com/chaitin/MonkeyCode/backend/db/agentpluginversion" "github.com/chaitin/MonkeyCode/backend/db/predicate" "github.com/google/uuid" ) // AgentPluginUpdate is the builder for updating AgentPlugin entities. type AgentPluginUpdate struct { config hooks []Hook mutation *AgentPluginMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the AgentPluginUpdate builder. func (_u *AgentPluginUpdate) Where(ps ...predicate.AgentPlugin) *AgentPluginUpdate { _u.mutation.Where(ps...) return _u } // SetRepoID sets the "repo_id" field. func (_u *AgentPluginUpdate) SetRepoID(v uuid.UUID) *AgentPluginUpdate { _u.mutation.SetRepoID(v) return _u } // SetNillableRepoID sets the "repo_id" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableRepoID(v *uuid.UUID) *AgentPluginUpdate { if v != nil { _u.SetRepoID(*v) } return _u } // SetName sets the "name" field. func (_u *AgentPluginUpdate) SetName(v string) *AgentPluginUpdate { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableName(v *string) *AgentPluginUpdate { if v != nil { _u.SetName(*v) } return _u } // SetDescription sets the "description" field. func (_u *AgentPluginUpdate) SetDescription(v string) *AgentPluginUpdate { _u.mutation.SetDescription(v) return _u } // SetNillableDescription sets the "description" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableDescription(v *string) *AgentPluginUpdate { if v != nil { _u.SetDescription(*v) } return _u } // ClearDescription clears the value of the "description" field. func (_u *AgentPluginUpdate) ClearDescription() *AgentPluginUpdate { _u.mutation.ClearDescription() return _u } // SetScopeType sets the "scope_type" field. func (_u *AgentPluginUpdate) SetScopeType(v agentplugin.ScopeType) *AgentPluginUpdate { _u.mutation.SetScopeType(v) return _u } // SetNillableScopeType sets the "scope_type" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableScopeType(v *agentplugin.ScopeType) *AgentPluginUpdate { if v != nil { _u.SetScopeType(*v) } return _u } // SetScopeID sets the "scope_id" field. func (_u *AgentPluginUpdate) SetScopeID(v string) *AgentPluginUpdate { _u.mutation.SetScopeID(v) return _u } // SetNillableScopeID sets the "scope_id" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableScopeID(v *string) *AgentPluginUpdate { if v != nil { _u.SetScopeID(*v) } return _u } // SetCreatedBy sets the "created_by" field. func (_u *AgentPluginUpdate) SetCreatedBy(v uuid.UUID) *AgentPluginUpdate { _u.mutation.SetCreatedBy(v) return _u } // SetNillableCreatedBy sets the "created_by" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableCreatedBy(v *uuid.UUID) *AgentPluginUpdate { if v != nil { _u.SetCreatedBy(*v) } return _u } // SetActiveVersionID sets the "active_version_id" field. func (_u *AgentPluginUpdate) SetActiveVersionID(v uuid.UUID) *AgentPluginUpdate { _u.mutation.SetActiveVersionID(v) return _u } // SetNillableActiveVersionID sets the "active_version_id" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableActiveVersionID(v *uuid.UUID) *AgentPluginUpdate { if v != nil { _u.SetActiveVersionID(*v) } return _u } // ClearActiveVersionID clears the value of the "active_version_id" field. func (_u *AgentPluginUpdate) ClearActiveVersionID() *AgentPluginUpdate { _u.mutation.ClearActiveVersionID() return _u } // SetIsForceDelivery sets the "is_force_delivery" field. func (_u *AgentPluginUpdate) SetIsForceDelivery(v bool) *AgentPluginUpdate { _u.mutation.SetIsForceDelivery(v) return _u } // SetNillableIsForceDelivery sets the "is_force_delivery" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableIsForceDelivery(v *bool) *AgentPluginUpdate { if v != nil { _u.SetIsForceDelivery(*v) } return _u } // SetIsOrphan sets the "is_orphan" field. func (_u *AgentPluginUpdate) SetIsOrphan(v bool) *AgentPluginUpdate { _u.mutation.SetIsOrphan(v) return _u } // SetNillableIsOrphan sets the "is_orphan" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableIsOrphan(v *bool) *AgentPluginUpdate { if v != nil { _u.SetIsOrphan(*v) } return _u } // SetIsDeleted sets the "is_deleted" field. func (_u *AgentPluginUpdate) SetIsDeleted(v bool) *AgentPluginUpdate { _u.mutation.SetIsDeleted(v) return _u } // SetNillableIsDeleted sets the "is_deleted" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableIsDeleted(v *bool) *AgentPluginUpdate { if v != nil { _u.SetIsDeleted(*v) } return _u } // SetEnabled sets the "enabled" field. func (_u *AgentPluginUpdate) SetEnabled(v bool) *AgentPluginUpdate { _u.mutation.SetEnabled(v) return _u } // SetNillableEnabled sets the "enabled" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableEnabled(v *bool) *AgentPluginUpdate { if v != nil { _u.SetEnabled(*v) } return _u } // SetCreatedAt sets the "created_at" field. func (_u *AgentPluginUpdate) SetCreatedAt(v time.Time) *AgentPluginUpdate { _u.mutation.SetCreatedAt(v) return _u } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_u *AgentPluginUpdate) SetNillableCreatedAt(v *time.Time) *AgentPluginUpdate { if v != nil { _u.SetCreatedAt(*v) } return _u } // SetUpdatedAt sets the "updated_at" field. func (_u *AgentPluginUpdate) SetUpdatedAt(v time.Time) *AgentPluginUpdate { _u.mutation.SetUpdatedAt(v) return _u } // SetRepo sets the "repo" edge to the AgentPluginRepo entity. func (_u *AgentPluginUpdate) SetRepo(v *AgentPluginRepo) *AgentPluginUpdate { return _u.SetRepoID(v.ID) } // AddVersionIDs adds the "versions" edge to the AgentPluginVersion entity by IDs. func (_u *AgentPluginUpdate) AddVersionIDs(ids ...uuid.UUID) *AgentPluginUpdate { _u.mutation.AddVersionIDs(ids...) return _u } // AddVersions adds the "versions" edges to the AgentPluginVersion entity. func (_u *AgentPluginUpdate) AddVersions(v ...*AgentPluginVersion) *AgentPluginUpdate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddVersionIDs(ids...) } // Mutation returns the AgentPluginMutation object of the builder. func (_u *AgentPluginUpdate) Mutation() *AgentPluginMutation { return _u.mutation } // ClearRepo clears the "repo" edge to the AgentPluginRepo entity. func (_u *AgentPluginUpdate) ClearRepo() *AgentPluginUpdate { _u.mutation.ClearRepo() return _u } // ClearVersions clears all "versions" edges to the AgentPluginVersion entity. func (_u *AgentPluginUpdate) ClearVersions() *AgentPluginUpdate { _u.mutation.ClearVersions() return _u } // RemoveVersionIDs removes the "versions" edge to AgentPluginVersion entities by IDs. func (_u *AgentPluginUpdate) RemoveVersionIDs(ids ...uuid.UUID) *AgentPluginUpdate { _u.mutation.RemoveVersionIDs(ids...) return _u } // RemoveVersions removes "versions" edges to AgentPluginVersion entities. func (_u *AgentPluginUpdate) RemoveVersions(v ...*AgentPluginVersion) *AgentPluginUpdate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveVersionIDs(ids...) } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *AgentPluginUpdate) 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 *AgentPluginUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *AgentPluginUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *AgentPluginUpdate) 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 *AgentPluginUpdate) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { v := agentplugin.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_u *AgentPluginUpdate) check() error { if v, ok := _u.mutation.Name(); ok { if err := agentplugin.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "AgentPlugin.name": %w`, err)} } } if v, ok := _u.mutation.ScopeType(); ok { if err := agentplugin.ScopeTypeValidator(v); err != nil { return &ValidationError{Name: "scope_type", err: fmt.Errorf(`db: validator failed for field "AgentPlugin.scope_type": %w`, err)} } } if _u.mutation.RepoCleared() && len(_u.mutation.RepoIDs()) > 0 { return errors.New(`db: clearing a required unique edge "AgentPlugin.repo"`) } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *AgentPluginUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgentPluginUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *AgentPluginUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(agentplugin.Table, agentplugin.Columns, sqlgraph.NewFieldSpec(agentplugin.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.Name(); ok { _spec.SetField(agentplugin.FieldName, field.TypeString, value) } if value, ok := _u.mutation.Description(); ok { _spec.SetField(agentplugin.FieldDescription, field.TypeString, value) } if _u.mutation.DescriptionCleared() { _spec.ClearField(agentplugin.FieldDescription, field.TypeString) } if value, ok := _u.mutation.ScopeType(); ok { _spec.SetField(agentplugin.FieldScopeType, field.TypeEnum, value) } if value, ok := _u.mutation.ScopeID(); ok { _spec.SetField(agentplugin.FieldScopeID, field.TypeString, value) } if value, ok := _u.mutation.CreatedBy(); ok { _spec.SetField(agentplugin.FieldCreatedBy, field.TypeUUID, value) } if value, ok := _u.mutation.ActiveVersionID(); ok { _spec.SetField(agentplugin.FieldActiveVersionID, field.TypeUUID, value) } if _u.mutation.ActiveVersionIDCleared() { _spec.ClearField(agentplugin.FieldActiveVersionID, field.TypeUUID) } if value, ok := _u.mutation.IsForceDelivery(); ok { _spec.SetField(agentplugin.FieldIsForceDelivery, field.TypeBool, value) } if value, ok := _u.mutation.IsOrphan(); ok { _spec.SetField(agentplugin.FieldIsOrphan, field.TypeBool, value) } if value, ok := _u.mutation.IsDeleted(); ok { _spec.SetField(agentplugin.FieldIsDeleted, field.TypeBool, value) } if value, ok := _u.mutation.Enabled(); ok { _spec.SetField(agentplugin.FieldEnabled, field.TypeBool, value) } if value, ok := _u.mutation.CreatedAt(); ok { _spec.SetField(agentplugin.FieldCreatedAt, field.TypeTime, value) } if value, ok := _u.mutation.UpdatedAt(); ok { _spec.SetField(agentplugin.FieldUpdatedAt, field.TypeTime, value) } if _u.mutation.RepoCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: agentplugin.RepoTable, Columns: []string{agentplugin.RepoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginrepo.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RepoIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: agentplugin.RepoTable, Columns: []string{agentplugin.RepoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginrepo.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.VersionsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: agentplugin.VersionsTable, Columns: []string{agentplugin.VersionsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginversion.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedVersionsIDs(); len(nodes) > 0 && !_u.mutation.VersionsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: agentplugin.VersionsTable, Columns: []string{agentplugin.VersionsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginversion.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.VersionsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: agentplugin.VersionsTable, Columns: []string{agentplugin.VersionsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginversion.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{agentplugin.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // AgentPluginUpdateOne is the builder for updating a single AgentPlugin entity. type AgentPluginUpdateOne struct { config fields []string hooks []Hook mutation *AgentPluginMutation modifiers []func(*sql.UpdateBuilder) } // SetRepoID sets the "repo_id" field. func (_u *AgentPluginUpdateOne) SetRepoID(v uuid.UUID) *AgentPluginUpdateOne { _u.mutation.SetRepoID(v) return _u } // SetNillableRepoID sets the "repo_id" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableRepoID(v *uuid.UUID) *AgentPluginUpdateOne { if v != nil { _u.SetRepoID(*v) } return _u } // SetName sets the "name" field. func (_u *AgentPluginUpdateOne) SetName(v string) *AgentPluginUpdateOne { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableName(v *string) *AgentPluginUpdateOne { if v != nil { _u.SetName(*v) } return _u } // SetDescription sets the "description" field. func (_u *AgentPluginUpdateOne) SetDescription(v string) *AgentPluginUpdateOne { _u.mutation.SetDescription(v) return _u } // SetNillableDescription sets the "description" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableDescription(v *string) *AgentPluginUpdateOne { if v != nil { _u.SetDescription(*v) } return _u } // ClearDescription clears the value of the "description" field. func (_u *AgentPluginUpdateOne) ClearDescription() *AgentPluginUpdateOne { _u.mutation.ClearDescription() return _u } // SetScopeType sets the "scope_type" field. func (_u *AgentPluginUpdateOne) SetScopeType(v agentplugin.ScopeType) *AgentPluginUpdateOne { _u.mutation.SetScopeType(v) return _u } // SetNillableScopeType sets the "scope_type" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableScopeType(v *agentplugin.ScopeType) *AgentPluginUpdateOne { if v != nil { _u.SetScopeType(*v) } return _u } // SetScopeID sets the "scope_id" field. func (_u *AgentPluginUpdateOne) SetScopeID(v string) *AgentPluginUpdateOne { _u.mutation.SetScopeID(v) return _u } // SetNillableScopeID sets the "scope_id" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableScopeID(v *string) *AgentPluginUpdateOne { if v != nil { _u.SetScopeID(*v) } return _u } // SetCreatedBy sets the "created_by" field. func (_u *AgentPluginUpdateOne) SetCreatedBy(v uuid.UUID) *AgentPluginUpdateOne { _u.mutation.SetCreatedBy(v) return _u } // SetNillableCreatedBy sets the "created_by" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableCreatedBy(v *uuid.UUID) *AgentPluginUpdateOne { if v != nil { _u.SetCreatedBy(*v) } return _u } // SetActiveVersionID sets the "active_version_id" field. func (_u *AgentPluginUpdateOne) SetActiveVersionID(v uuid.UUID) *AgentPluginUpdateOne { _u.mutation.SetActiveVersionID(v) return _u } // SetNillableActiveVersionID sets the "active_version_id" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableActiveVersionID(v *uuid.UUID) *AgentPluginUpdateOne { if v != nil { _u.SetActiveVersionID(*v) } return _u } // ClearActiveVersionID clears the value of the "active_version_id" field. func (_u *AgentPluginUpdateOne) ClearActiveVersionID() *AgentPluginUpdateOne { _u.mutation.ClearActiveVersionID() return _u } // SetIsForceDelivery sets the "is_force_delivery" field. func (_u *AgentPluginUpdateOne) SetIsForceDelivery(v bool) *AgentPluginUpdateOne { _u.mutation.SetIsForceDelivery(v) return _u } // SetNillableIsForceDelivery sets the "is_force_delivery" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableIsForceDelivery(v *bool) *AgentPluginUpdateOne { if v != nil { _u.SetIsForceDelivery(*v) } return _u } // SetIsOrphan sets the "is_orphan" field. func (_u *AgentPluginUpdateOne) SetIsOrphan(v bool) *AgentPluginUpdateOne { _u.mutation.SetIsOrphan(v) return _u } // SetNillableIsOrphan sets the "is_orphan" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableIsOrphan(v *bool) *AgentPluginUpdateOne { if v != nil { _u.SetIsOrphan(*v) } return _u } // SetIsDeleted sets the "is_deleted" field. func (_u *AgentPluginUpdateOne) SetIsDeleted(v bool) *AgentPluginUpdateOne { _u.mutation.SetIsDeleted(v) return _u } // SetNillableIsDeleted sets the "is_deleted" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableIsDeleted(v *bool) *AgentPluginUpdateOne { if v != nil { _u.SetIsDeleted(*v) } return _u } // SetEnabled sets the "enabled" field. func (_u *AgentPluginUpdateOne) SetEnabled(v bool) *AgentPluginUpdateOne { _u.mutation.SetEnabled(v) return _u } // SetNillableEnabled sets the "enabled" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableEnabled(v *bool) *AgentPluginUpdateOne { if v != nil { _u.SetEnabled(*v) } return _u } // SetCreatedAt sets the "created_at" field. func (_u *AgentPluginUpdateOne) SetCreatedAt(v time.Time) *AgentPluginUpdateOne { _u.mutation.SetCreatedAt(v) return _u } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_u *AgentPluginUpdateOne) SetNillableCreatedAt(v *time.Time) *AgentPluginUpdateOne { if v != nil { _u.SetCreatedAt(*v) } return _u } // SetUpdatedAt sets the "updated_at" field. func (_u *AgentPluginUpdateOne) SetUpdatedAt(v time.Time) *AgentPluginUpdateOne { _u.mutation.SetUpdatedAt(v) return _u } // SetRepo sets the "repo" edge to the AgentPluginRepo entity. func (_u *AgentPluginUpdateOne) SetRepo(v *AgentPluginRepo) *AgentPluginUpdateOne { return _u.SetRepoID(v.ID) } // AddVersionIDs adds the "versions" edge to the AgentPluginVersion entity by IDs. func (_u *AgentPluginUpdateOne) AddVersionIDs(ids ...uuid.UUID) *AgentPluginUpdateOne { _u.mutation.AddVersionIDs(ids...) return _u } // AddVersions adds the "versions" edges to the AgentPluginVersion entity. func (_u *AgentPluginUpdateOne) AddVersions(v ...*AgentPluginVersion) *AgentPluginUpdateOne { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddVersionIDs(ids...) } // Mutation returns the AgentPluginMutation object of the builder. func (_u *AgentPluginUpdateOne) Mutation() *AgentPluginMutation { return _u.mutation } // ClearRepo clears the "repo" edge to the AgentPluginRepo entity. func (_u *AgentPluginUpdateOne) ClearRepo() *AgentPluginUpdateOne { _u.mutation.ClearRepo() return _u } // ClearVersions clears all "versions" edges to the AgentPluginVersion entity. func (_u *AgentPluginUpdateOne) ClearVersions() *AgentPluginUpdateOne { _u.mutation.ClearVersions() return _u } // RemoveVersionIDs removes the "versions" edge to AgentPluginVersion entities by IDs. func (_u *AgentPluginUpdateOne) RemoveVersionIDs(ids ...uuid.UUID) *AgentPluginUpdateOne { _u.mutation.RemoveVersionIDs(ids...) return _u } // RemoveVersions removes "versions" edges to AgentPluginVersion entities. func (_u *AgentPluginUpdateOne) RemoveVersions(v ...*AgentPluginVersion) *AgentPluginUpdateOne { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveVersionIDs(ids...) } // Where appends a list predicates to the AgentPluginUpdate builder. func (_u *AgentPluginUpdateOne) Where(ps ...predicate.AgentPlugin) *AgentPluginUpdateOne { _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 *AgentPluginUpdateOne) Select(field string, fields ...string) *AgentPluginUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated AgentPlugin entity. func (_u *AgentPluginUpdateOne) Save(ctx context.Context) (*AgentPlugin, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *AgentPluginUpdateOne) SaveX(ctx context.Context) *AgentPlugin { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *AgentPluginUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *AgentPluginUpdateOne) 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 *AgentPluginUpdateOne) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { v := agentplugin.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_u *AgentPluginUpdateOne) check() error { if v, ok := _u.mutation.Name(); ok { if err := agentplugin.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "AgentPlugin.name": %w`, err)} } } if v, ok := _u.mutation.ScopeType(); ok { if err := agentplugin.ScopeTypeValidator(v); err != nil { return &ValidationError{Name: "scope_type", err: fmt.Errorf(`db: validator failed for field "AgentPlugin.scope_type": %w`, err)} } } if _u.mutation.RepoCleared() && len(_u.mutation.RepoIDs()) > 0 { return errors.New(`db: clearing a required unique edge "AgentPlugin.repo"`) } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *AgentPluginUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgentPluginUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *AgentPluginUpdateOne) sqlSave(ctx context.Context) (_node *AgentPlugin, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(agentplugin.Table, agentplugin.Columns, sqlgraph.NewFieldSpec(agentplugin.FieldID, field.TypeUUID)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AgentPlugin.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, agentplugin.FieldID) for _, f := range fields { if !agentplugin.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } if f != agentplugin.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.Name(); ok { _spec.SetField(agentplugin.FieldName, field.TypeString, value) } if value, ok := _u.mutation.Description(); ok { _spec.SetField(agentplugin.FieldDescription, field.TypeString, value) } if _u.mutation.DescriptionCleared() { _spec.ClearField(agentplugin.FieldDescription, field.TypeString) } if value, ok := _u.mutation.ScopeType(); ok { _spec.SetField(agentplugin.FieldScopeType, field.TypeEnum, value) } if value, ok := _u.mutation.ScopeID(); ok { _spec.SetField(agentplugin.FieldScopeID, field.TypeString, value) } if value, ok := _u.mutation.CreatedBy(); ok { _spec.SetField(agentplugin.FieldCreatedBy, field.TypeUUID, value) } if value, ok := _u.mutation.ActiveVersionID(); ok { _spec.SetField(agentplugin.FieldActiveVersionID, field.TypeUUID, value) } if _u.mutation.ActiveVersionIDCleared() { _spec.ClearField(agentplugin.FieldActiveVersionID, field.TypeUUID) } if value, ok := _u.mutation.IsForceDelivery(); ok { _spec.SetField(agentplugin.FieldIsForceDelivery, field.TypeBool, value) } if value, ok := _u.mutation.IsOrphan(); ok { _spec.SetField(agentplugin.FieldIsOrphan, field.TypeBool, value) } if value, ok := _u.mutation.IsDeleted(); ok { _spec.SetField(agentplugin.FieldIsDeleted, field.TypeBool, value) } if value, ok := _u.mutation.Enabled(); ok { _spec.SetField(agentplugin.FieldEnabled, field.TypeBool, value) } if value, ok := _u.mutation.CreatedAt(); ok { _spec.SetField(agentplugin.FieldCreatedAt, field.TypeTime, value) } if value, ok := _u.mutation.UpdatedAt(); ok { _spec.SetField(agentplugin.FieldUpdatedAt, field.TypeTime, value) } if _u.mutation.RepoCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: agentplugin.RepoTable, Columns: []string{agentplugin.RepoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginrepo.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RepoIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: agentplugin.RepoTable, Columns: []string{agentplugin.RepoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginrepo.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.VersionsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: agentplugin.VersionsTable, Columns: []string{agentplugin.VersionsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginversion.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedVersionsIDs(); len(nodes) > 0 && !_u.mutation.VersionsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: agentplugin.VersionsTable, Columns: []string{agentplugin.VersionsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginversion.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.VersionsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: agentplugin.VersionsTable, Columns: []string{agentplugin.VersionsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agentpluginversion.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 = &AgentPlugin{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{agentplugin.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }