mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-29 16:18:40 +08:00
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
437 lines
13 KiB
Go
437 lines
13 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"
|
|
)
|
|
|
|
// AgentRuleVersionUpdate is the builder for updating AgentRuleVersion entities.
|
|
type AgentRuleVersionUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AgentRuleVersionMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the AgentRuleVersionUpdate builder.
|
|
func (_u *AgentRuleVersionUpdate) Where(ps ...predicate.AgentRuleVersion) *AgentRuleVersionUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetRuleID sets the "rule_id" field.
|
|
func (_u *AgentRuleVersionUpdate) SetRuleID(v uuid.UUID) *AgentRuleVersionUpdate {
|
|
_u.mutation.SetRuleID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRuleID sets the "rule_id" field if the given value is not nil.
|
|
func (_u *AgentRuleVersionUpdate) SetNillableRuleID(v *uuid.UUID) *AgentRuleVersionUpdate {
|
|
if v != nil {
|
|
_u.SetRuleID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (_u *AgentRuleVersionUpdate) SetVersion(v string) *AgentRuleVersionUpdate {
|
|
_u.mutation.SetVersion(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableVersion sets the "version" field if the given value is not nil.
|
|
func (_u *AgentRuleVersionUpdate) SetNillableVersion(v *string) *AgentRuleVersionUpdate {
|
|
if v != nil {
|
|
_u.SetVersion(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (_u *AgentRuleVersionUpdate) SetContent(v string) *AgentRuleVersionUpdate {
|
|
_u.mutation.SetContent(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
|
func (_u *AgentRuleVersionUpdate) SetNillableContent(v *string) *AgentRuleVersionUpdate {
|
|
if v != nil {
|
|
_u.SetContent(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AgentRuleVersionUpdate) SetCreatedAt(v time.Time) *AgentRuleVersionUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AgentRuleVersionUpdate) SetNillableCreatedAt(v *time.Time) *AgentRuleVersionUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetRule sets the "rule" edge to the AgentRule entity.
|
|
func (_u *AgentRuleVersionUpdate) SetRule(v *AgentRule) *AgentRuleVersionUpdate {
|
|
return _u.SetRuleID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the AgentRuleVersionMutation object of the builder.
|
|
func (_u *AgentRuleVersionUpdate) Mutation() *AgentRuleVersionMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearRule clears the "rule" edge to the AgentRule entity.
|
|
func (_u *AgentRuleVersionUpdate) ClearRule() *AgentRuleVersionUpdate {
|
|
_u.mutation.ClearRule()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *AgentRuleVersionUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AgentRuleVersionUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *AgentRuleVersionUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AgentRuleVersionUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AgentRuleVersionUpdate) check() error {
|
|
if v, ok := _u.mutation.Version(); ok {
|
|
if err := agentruleversion.VersionValidator(v); err != nil {
|
|
return &ValidationError{Name: "version", err: fmt.Errorf(`db: validator failed for field "AgentRuleVersion.version": %w`, err)}
|
|
}
|
|
}
|
|
if _u.mutation.RuleCleared() && len(_u.mutation.RuleIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "AgentRuleVersion.rule"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *AgentRuleVersionUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgentRuleVersionUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *AgentRuleVersionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(agentruleversion.Table, agentruleversion.Columns, sqlgraph.NewFieldSpec(agentruleversion.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.Version(); ok {
|
|
_spec.SetField(agentruleversion.FieldVersion, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Content(); ok {
|
|
_spec.SetField(agentruleversion.FieldContent, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(agentruleversion.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.RuleCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: agentruleversion.RuleTable,
|
|
Columns: []string{agentruleversion.RuleColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentrule.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RuleIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: agentruleversion.RuleTable,
|
|
Columns: []string{agentruleversion.RuleColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentrule.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{agentruleversion.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// AgentRuleVersionUpdateOne is the builder for updating a single AgentRuleVersion entity.
|
|
type AgentRuleVersionUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AgentRuleVersionMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetRuleID sets the "rule_id" field.
|
|
func (_u *AgentRuleVersionUpdateOne) SetRuleID(v uuid.UUID) *AgentRuleVersionUpdateOne {
|
|
_u.mutation.SetRuleID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRuleID sets the "rule_id" field if the given value is not nil.
|
|
func (_u *AgentRuleVersionUpdateOne) SetNillableRuleID(v *uuid.UUID) *AgentRuleVersionUpdateOne {
|
|
if v != nil {
|
|
_u.SetRuleID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (_u *AgentRuleVersionUpdateOne) SetVersion(v string) *AgentRuleVersionUpdateOne {
|
|
_u.mutation.SetVersion(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableVersion sets the "version" field if the given value is not nil.
|
|
func (_u *AgentRuleVersionUpdateOne) SetNillableVersion(v *string) *AgentRuleVersionUpdateOne {
|
|
if v != nil {
|
|
_u.SetVersion(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (_u *AgentRuleVersionUpdateOne) SetContent(v string) *AgentRuleVersionUpdateOne {
|
|
_u.mutation.SetContent(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
|
func (_u *AgentRuleVersionUpdateOne) SetNillableContent(v *string) *AgentRuleVersionUpdateOne {
|
|
if v != nil {
|
|
_u.SetContent(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AgentRuleVersionUpdateOne) SetCreatedAt(v time.Time) *AgentRuleVersionUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AgentRuleVersionUpdateOne) SetNillableCreatedAt(v *time.Time) *AgentRuleVersionUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetRule sets the "rule" edge to the AgentRule entity.
|
|
func (_u *AgentRuleVersionUpdateOne) SetRule(v *AgentRule) *AgentRuleVersionUpdateOne {
|
|
return _u.SetRuleID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the AgentRuleVersionMutation object of the builder.
|
|
func (_u *AgentRuleVersionUpdateOne) Mutation() *AgentRuleVersionMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearRule clears the "rule" edge to the AgentRule entity.
|
|
func (_u *AgentRuleVersionUpdateOne) ClearRule() *AgentRuleVersionUpdateOne {
|
|
_u.mutation.ClearRule()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the AgentRuleVersionUpdate builder.
|
|
func (_u *AgentRuleVersionUpdateOne) Where(ps ...predicate.AgentRuleVersion) *AgentRuleVersionUpdateOne {
|
|
_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 *AgentRuleVersionUpdateOne) Select(field string, fields ...string) *AgentRuleVersionUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated AgentRuleVersion entity.
|
|
func (_u *AgentRuleVersionUpdateOne) Save(ctx context.Context) (*AgentRuleVersion, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AgentRuleVersionUpdateOne) SaveX(ctx context.Context) *AgentRuleVersion {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *AgentRuleVersionUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AgentRuleVersionUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AgentRuleVersionUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Version(); ok {
|
|
if err := agentruleversion.VersionValidator(v); err != nil {
|
|
return &ValidationError{Name: "version", err: fmt.Errorf(`db: validator failed for field "AgentRuleVersion.version": %w`, err)}
|
|
}
|
|
}
|
|
if _u.mutation.RuleCleared() && len(_u.mutation.RuleIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "AgentRuleVersion.rule"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *AgentRuleVersionUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgentRuleVersionUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *AgentRuleVersionUpdateOne) sqlSave(ctx context.Context) (_node *AgentRuleVersion, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(agentruleversion.Table, agentruleversion.Columns, sqlgraph.NewFieldSpec(agentruleversion.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AgentRuleVersion.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, agentruleversion.FieldID)
|
|
for _, f := range fields {
|
|
if !agentruleversion.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != agentruleversion.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.Version(); ok {
|
|
_spec.SetField(agentruleversion.FieldVersion, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Content(); ok {
|
|
_spec.SetField(agentruleversion.FieldContent, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(agentruleversion.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.RuleCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: agentruleversion.RuleTable,
|
|
Columns: []string{agentruleversion.RuleColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentrule.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RuleIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: agentruleversion.RuleTable,
|
|
Columns: []string{agentruleversion.RuleColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentrule.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 = &AgentRuleVersion{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{agentruleversion.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|