mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-29 16:18:40 +08:00
893 lines
27 KiB
Go
893 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/agentrule"
|
|
"github.com/chaitin/MonkeyCode/backend/db/agentruleversion"
|
|
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// AgentRuleUpdate is the builder for updating AgentRule entities.
|
|
type AgentRuleUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AgentRuleMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the AgentRuleUpdate builder.
|
|
func (_u *AgentRuleUpdate) Where(ps ...predicate.AgentRule) *AgentRuleUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *AgentRuleUpdate) SetName(v string) *AgentRuleUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableName(v *string) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *AgentRuleUpdate) SetDescription(v string) *AgentRuleUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableDescription(v *string) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *AgentRuleUpdate) ClearDescription() *AgentRuleUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetScopeType sets the "scope_type" field.
|
|
func (_u *AgentRuleUpdate) SetScopeType(v agentrule.ScopeType) *AgentRuleUpdate {
|
|
_u.mutation.SetScopeType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableScopeType sets the "scope_type" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableScopeType(v *agentrule.ScopeType) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetScopeType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetScopeID sets the "scope_id" field.
|
|
func (_u *AgentRuleUpdate) SetScopeID(v string) *AgentRuleUpdate {
|
|
_u.mutation.SetScopeID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableScopeID sets the "scope_id" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableScopeID(v *string) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetScopeID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedBy sets the "created_by" field.
|
|
func (_u *AgentRuleUpdate) SetCreatedBy(v uuid.UUID) *AgentRuleUpdate {
|
|
_u.mutation.SetCreatedBy(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableCreatedBy(v *uuid.UUID) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedBy(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetActiveVersionID sets the "active_version_id" field.
|
|
func (_u *AgentRuleUpdate) SetActiveVersionID(v uuid.UUID) *AgentRuleUpdate {
|
|
_u.mutation.SetActiveVersionID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActiveVersionID sets the "active_version_id" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableActiveVersionID(v *uuid.UUID) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetActiveVersionID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearActiveVersionID clears the value of the "active_version_id" field.
|
|
func (_u *AgentRuleUpdate) ClearActiveVersionID() *AgentRuleUpdate {
|
|
_u.mutation.ClearActiveVersionID()
|
|
return _u
|
|
}
|
|
|
|
// SetExtensionPackageID sets the "extension_package_id" field.
|
|
func (_u *AgentRuleUpdate) SetExtensionPackageID(v string) *AgentRuleUpdate {
|
|
_u.mutation.SetExtensionPackageID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableExtensionPackageID sets the "extension_package_id" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableExtensionPackageID(v *string) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetExtensionPackageID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearExtensionPackageID clears the value of the "extension_package_id" field.
|
|
func (_u *AgentRuleUpdate) ClearExtensionPackageID() *AgentRuleUpdate {
|
|
_u.mutation.ClearExtensionPackageID()
|
|
return _u
|
|
}
|
|
|
|
// SetExtensionRuleID sets the "extension_rule_id" field.
|
|
func (_u *AgentRuleUpdate) SetExtensionRuleID(v string) *AgentRuleUpdate {
|
|
_u.mutation.SetExtensionRuleID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableExtensionRuleID sets the "extension_rule_id" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableExtensionRuleID(v *string) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetExtensionRuleID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearExtensionRuleID clears the value of the "extension_rule_id" field.
|
|
func (_u *AgentRuleUpdate) ClearExtensionRuleID() *AgentRuleUpdate {
|
|
_u.mutation.ClearExtensionRuleID()
|
|
return _u
|
|
}
|
|
|
|
// SetExtensionVersion sets the "extension_version" field.
|
|
func (_u *AgentRuleUpdate) SetExtensionVersion(v string) *AgentRuleUpdate {
|
|
_u.mutation.SetExtensionVersion(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableExtensionVersion sets the "extension_version" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableExtensionVersion(v *string) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetExtensionVersion(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearExtensionVersion clears the value of the "extension_version" field.
|
|
func (_u *AgentRuleUpdate) ClearExtensionVersion() *AgentRuleUpdate {
|
|
_u.mutation.ClearExtensionVersion()
|
|
return _u
|
|
}
|
|
|
|
// SetIsDeleted sets the "is_deleted" field.
|
|
func (_u *AgentRuleUpdate) SetIsDeleted(v bool) *AgentRuleUpdate {
|
|
_u.mutation.SetIsDeleted(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsDeleted sets the "is_deleted" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableIsDeleted(v *bool) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetIsDeleted(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AgentRuleUpdate) SetCreatedAt(v time.Time) *AgentRuleUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdate) SetNillableCreatedAt(v *time.Time) *AgentRuleUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AgentRuleUpdate) SetUpdatedAt(v time.Time) *AgentRuleUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// AddVersionIDs adds the "versions" edge to the AgentRuleVersion entity by IDs.
|
|
func (_u *AgentRuleUpdate) AddVersionIDs(ids ...uuid.UUID) *AgentRuleUpdate {
|
|
_u.mutation.AddVersionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddVersions adds the "versions" edges to the AgentRuleVersion entity.
|
|
func (_u *AgentRuleUpdate) AddVersions(v ...*AgentRuleVersion) *AgentRuleUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddVersionIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the AgentRuleMutation object of the builder.
|
|
func (_u *AgentRuleUpdate) Mutation() *AgentRuleMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearVersions clears all "versions" edges to the AgentRuleVersion entity.
|
|
func (_u *AgentRuleUpdate) ClearVersions() *AgentRuleUpdate {
|
|
_u.mutation.ClearVersions()
|
|
return _u
|
|
}
|
|
|
|
// RemoveVersionIDs removes the "versions" edge to AgentRuleVersion entities by IDs.
|
|
func (_u *AgentRuleUpdate) RemoveVersionIDs(ids ...uuid.UUID) *AgentRuleUpdate {
|
|
_u.mutation.RemoveVersionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveVersions removes "versions" edges to AgentRuleVersion entities.
|
|
func (_u *AgentRuleUpdate) RemoveVersions(v ...*AgentRuleVersion) *AgentRuleUpdate {
|
|
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 *AgentRuleUpdate) 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 *AgentRuleUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *AgentRuleUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AgentRuleUpdate) 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 *AgentRuleUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := agentrule.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AgentRuleUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := agentrule.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "AgentRule.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ScopeType(); ok {
|
|
if err := agentrule.ScopeTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "scope_type", err: fmt.Errorf(`db: validator failed for field "AgentRule.scope_type": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *AgentRuleUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgentRuleUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *AgentRuleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(agentrule.Table, agentrule.Columns, sqlgraph.NewFieldSpec(agentrule.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(agentrule.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(agentrule.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(agentrule.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.ScopeType(); ok {
|
|
_spec.SetField(agentrule.FieldScopeType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.ScopeID(); ok {
|
|
_spec.SetField(agentrule.FieldScopeID, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedBy(); ok {
|
|
_spec.SetField(agentrule.FieldCreatedBy, field.TypeUUID, value)
|
|
}
|
|
if value, ok := _u.mutation.ActiveVersionID(); ok {
|
|
_spec.SetField(agentrule.FieldActiveVersionID, field.TypeUUID, value)
|
|
}
|
|
if _u.mutation.ActiveVersionIDCleared() {
|
|
_spec.ClearField(agentrule.FieldActiveVersionID, field.TypeUUID)
|
|
}
|
|
if value, ok := _u.mutation.ExtensionPackageID(); ok {
|
|
_spec.SetField(agentrule.FieldExtensionPackageID, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ExtensionPackageIDCleared() {
|
|
_spec.ClearField(agentrule.FieldExtensionPackageID, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.ExtensionRuleID(); ok {
|
|
_spec.SetField(agentrule.FieldExtensionRuleID, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ExtensionRuleIDCleared() {
|
|
_spec.ClearField(agentrule.FieldExtensionRuleID, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.ExtensionVersion(); ok {
|
|
_spec.SetField(agentrule.FieldExtensionVersion, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ExtensionVersionCleared() {
|
|
_spec.ClearField(agentrule.FieldExtensionVersion, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.IsDeleted(); ok {
|
|
_spec.SetField(agentrule.FieldIsDeleted, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(agentrule.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(agentrule.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.VersionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: agentrule.VersionsTable,
|
|
Columns: []string{agentrule.VersionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentruleversion.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: agentrule.VersionsTable,
|
|
Columns: []string{agentrule.VersionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentruleversion.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: agentrule.VersionsTable,
|
|
Columns: []string{agentrule.VersionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentruleversion.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{agentrule.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// AgentRuleUpdateOne is the builder for updating a single AgentRule entity.
|
|
type AgentRuleUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AgentRuleMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *AgentRuleUpdateOne) SetName(v string) *AgentRuleUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableName(v *string) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *AgentRuleUpdateOne) SetDescription(v string) *AgentRuleUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableDescription(v *string) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *AgentRuleUpdateOne) ClearDescription() *AgentRuleUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetScopeType sets the "scope_type" field.
|
|
func (_u *AgentRuleUpdateOne) SetScopeType(v agentrule.ScopeType) *AgentRuleUpdateOne {
|
|
_u.mutation.SetScopeType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableScopeType sets the "scope_type" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableScopeType(v *agentrule.ScopeType) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetScopeType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetScopeID sets the "scope_id" field.
|
|
func (_u *AgentRuleUpdateOne) SetScopeID(v string) *AgentRuleUpdateOne {
|
|
_u.mutation.SetScopeID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableScopeID sets the "scope_id" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableScopeID(v *string) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetScopeID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedBy sets the "created_by" field.
|
|
func (_u *AgentRuleUpdateOne) SetCreatedBy(v uuid.UUID) *AgentRuleUpdateOne {
|
|
_u.mutation.SetCreatedBy(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableCreatedBy(v *uuid.UUID) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedBy(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetActiveVersionID sets the "active_version_id" field.
|
|
func (_u *AgentRuleUpdateOne) SetActiveVersionID(v uuid.UUID) *AgentRuleUpdateOne {
|
|
_u.mutation.SetActiveVersionID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActiveVersionID sets the "active_version_id" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableActiveVersionID(v *uuid.UUID) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetActiveVersionID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearActiveVersionID clears the value of the "active_version_id" field.
|
|
func (_u *AgentRuleUpdateOne) ClearActiveVersionID() *AgentRuleUpdateOne {
|
|
_u.mutation.ClearActiveVersionID()
|
|
return _u
|
|
}
|
|
|
|
// SetExtensionPackageID sets the "extension_package_id" field.
|
|
func (_u *AgentRuleUpdateOne) SetExtensionPackageID(v string) *AgentRuleUpdateOne {
|
|
_u.mutation.SetExtensionPackageID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableExtensionPackageID sets the "extension_package_id" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableExtensionPackageID(v *string) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetExtensionPackageID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearExtensionPackageID clears the value of the "extension_package_id" field.
|
|
func (_u *AgentRuleUpdateOne) ClearExtensionPackageID() *AgentRuleUpdateOne {
|
|
_u.mutation.ClearExtensionPackageID()
|
|
return _u
|
|
}
|
|
|
|
// SetExtensionRuleID sets the "extension_rule_id" field.
|
|
func (_u *AgentRuleUpdateOne) SetExtensionRuleID(v string) *AgentRuleUpdateOne {
|
|
_u.mutation.SetExtensionRuleID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableExtensionRuleID sets the "extension_rule_id" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableExtensionRuleID(v *string) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetExtensionRuleID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearExtensionRuleID clears the value of the "extension_rule_id" field.
|
|
func (_u *AgentRuleUpdateOne) ClearExtensionRuleID() *AgentRuleUpdateOne {
|
|
_u.mutation.ClearExtensionRuleID()
|
|
return _u
|
|
}
|
|
|
|
// SetExtensionVersion sets the "extension_version" field.
|
|
func (_u *AgentRuleUpdateOne) SetExtensionVersion(v string) *AgentRuleUpdateOne {
|
|
_u.mutation.SetExtensionVersion(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableExtensionVersion sets the "extension_version" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableExtensionVersion(v *string) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetExtensionVersion(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearExtensionVersion clears the value of the "extension_version" field.
|
|
func (_u *AgentRuleUpdateOne) ClearExtensionVersion() *AgentRuleUpdateOne {
|
|
_u.mutation.ClearExtensionVersion()
|
|
return _u
|
|
}
|
|
|
|
// SetIsDeleted sets the "is_deleted" field.
|
|
func (_u *AgentRuleUpdateOne) SetIsDeleted(v bool) *AgentRuleUpdateOne {
|
|
_u.mutation.SetIsDeleted(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsDeleted sets the "is_deleted" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableIsDeleted(v *bool) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetIsDeleted(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AgentRuleUpdateOne) SetCreatedAt(v time.Time) *AgentRuleUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AgentRuleUpdateOne) SetNillableCreatedAt(v *time.Time) *AgentRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AgentRuleUpdateOne) SetUpdatedAt(v time.Time) *AgentRuleUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// AddVersionIDs adds the "versions" edge to the AgentRuleVersion entity by IDs.
|
|
func (_u *AgentRuleUpdateOne) AddVersionIDs(ids ...uuid.UUID) *AgentRuleUpdateOne {
|
|
_u.mutation.AddVersionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddVersions adds the "versions" edges to the AgentRuleVersion entity.
|
|
func (_u *AgentRuleUpdateOne) AddVersions(v ...*AgentRuleVersion) *AgentRuleUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddVersionIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the AgentRuleMutation object of the builder.
|
|
func (_u *AgentRuleUpdateOne) Mutation() *AgentRuleMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearVersions clears all "versions" edges to the AgentRuleVersion entity.
|
|
func (_u *AgentRuleUpdateOne) ClearVersions() *AgentRuleUpdateOne {
|
|
_u.mutation.ClearVersions()
|
|
return _u
|
|
}
|
|
|
|
// RemoveVersionIDs removes the "versions" edge to AgentRuleVersion entities by IDs.
|
|
func (_u *AgentRuleUpdateOne) RemoveVersionIDs(ids ...uuid.UUID) *AgentRuleUpdateOne {
|
|
_u.mutation.RemoveVersionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveVersions removes "versions" edges to AgentRuleVersion entities.
|
|
func (_u *AgentRuleUpdateOne) RemoveVersions(v ...*AgentRuleVersion) *AgentRuleUpdateOne {
|
|
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 AgentRuleUpdate builder.
|
|
func (_u *AgentRuleUpdateOne) Where(ps ...predicate.AgentRule) *AgentRuleUpdateOne {
|
|
_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 *AgentRuleUpdateOne) Select(field string, fields ...string) *AgentRuleUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated AgentRule entity.
|
|
func (_u *AgentRuleUpdateOne) Save(ctx context.Context) (*AgentRule, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AgentRuleUpdateOne) SaveX(ctx context.Context) *AgentRule {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *AgentRuleUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AgentRuleUpdateOne) 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 *AgentRuleUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := agentrule.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AgentRuleUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := agentrule.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "AgentRule.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ScopeType(); ok {
|
|
if err := agentrule.ScopeTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "scope_type", err: fmt.Errorf(`db: validator failed for field "AgentRule.scope_type": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *AgentRuleUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgentRuleUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *AgentRuleUpdateOne) sqlSave(ctx context.Context) (_node *AgentRule, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(agentrule.Table, agentrule.Columns, sqlgraph.NewFieldSpec(agentrule.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AgentRule.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, agentrule.FieldID)
|
|
for _, f := range fields {
|
|
if !agentrule.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != agentrule.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(agentrule.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(agentrule.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(agentrule.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.ScopeType(); ok {
|
|
_spec.SetField(agentrule.FieldScopeType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.ScopeID(); ok {
|
|
_spec.SetField(agentrule.FieldScopeID, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedBy(); ok {
|
|
_spec.SetField(agentrule.FieldCreatedBy, field.TypeUUID, value)
|
|
}
|
|
if value, ok := _u.mutation.ActiveVersionID(); ok {
|
|
_spec.SetField(agentrule.FieldActiveVersionID, field.TypeUUID, value)
|
|
}
|
|
if _u.mutation.ActiveVersionIDCleared() {
|
|
_spec.ClearField(agentrule.FieldActiveVersionID, field.TypeUUID)
|
|
}
|
|
if value, ok := _u.mutation.ExtensionPackageID(); ok {
|
|
_spec.SetField(agentrule.FieldExtensionPackageID, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ExtensionPackageIDCleared() {
|
|
_spec.ClearField(agentrule.FieldExtensionPackageID, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.ExtensionRuleID(); ok {
|
|
_spec.SetField(agentrule.FieldExtensionRuleID, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ExtensionRuleIDCleared() {
|
|
_spec.ClearField(agentrule.FieldExtensionRuleID, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.ExtensionVersion(); ok {
|
|
_spec.SetField(agentrule.FieldExtensionVersion, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ExtensionVersionCleared() {
|
|
_spec.ClearField(agentrule.FieldExtensionVersion, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.IsDeleted(); ok {
|
|
_spec.SetField(agentrule.FieldIsDeleted, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(agentrule.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(agentrule.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.VersionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: agentrule.VersionsTable,
|
|
Columns: []string{agentrule.VersionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentruleversion.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: agentrule.VersionsTable,
|
|
Columns: []string{agentrule.VersionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentruleversion.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: agentrule.VersionsTable,
|
|
Columns: []string{agentrule.VersionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentruleversion.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 = &AgentRule{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{agentrule.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|