// 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/gitbot" "github.com/chaitin/MonkeyCode/backend/db/predicate" "github.com/chaitin/MonkeyCode/backend/db/project" "github.com/chaitin/MonkeyCode/backend/db/projectgitbot" "github.com/google/uuid" ) // ProjectGitBotUpdate is the builder for updating ProjectGitBot entities. type ProjectGitBotUpdate struct { config hooks []Hook mutation *ProjectGitBotMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the ProjectGitBotUpdate builder. func (_u *ProjectGitBotUpdate) Where(ps ...predicate.ProjectGitBot) *ProjectGitBotUpdate { _u.mutation.Where(ps...) return _u } // SetProjectID sets the "project_id" field. func (_u *ProjectGitBotUpdate) SetProjectID(v uuid.UUID) *ProjectGitBotUpdate { _u.mutation.SetProjectID(v) return _u } // SetNillableProjectID sets the "project_id" field if the given value is not nil. func (_u *ProjectGitBotUpdate) SetNillableProjectID(v *uuid.UUID) *ProjectGitBotUpdate { if v != nil { _u.SetProjectID(*v) } return _u } // SetGitBotID sets the "git_bot_id" field. func (_u *ProjectGitBotUpdate) SetGitBotID(v uuid.UUID) *ProjectGitBotUpdate { _u.mutation.SetGitBotID(v) return _u } // SetNillableGitBotID sets the "git_bot_id" field if the given value is not nil. func (_u *ProjectGitBotUpdate) SetNillableGitBotID(v *uuid.UUID) *ProjectGitBotUpdate { if v != nil { _u.SetGitBotID(*v) } return _u } // SetCreatedAt sets the "created_at" field. func (_u *ProjectGitBotUpdate) SetCreatedAt(v time.Time) *ProjectGitBotUpdate { _u.mutation.SetCreatedAt(v) return _u } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_u *ProjectGitBotUpdate) SetNillableCreatedAt(v *time.Time) *ProjectGitBotUpdate { if v != nil { _u.SetCreatedAt(*v) } return _u } // SetProject sets the "project" edge to the Project entity. func (_u *ProjectGitBotUpdate) SetProject(v *Project) *ProjectGitBotUpdate { return _u.SetProjectID(v.ID) } // SetGitBot sets the "git_bot" edge to the GitBot entity. func (_u *ProjectGitBotUpdate) SetGitBot(v *GitBot) *ProjectGitBotUpdate { return _u.SetGitBotID(v.ID) } // Mutation returns the ProjectGitBotMutation object of the builder. func (_u *ProjectGitBotUpdate) Mutation() *ProjectGitBotMutation { return _u.mutation } // ClearProject clears the "project" edge to the Project entity. func (_u *ProjectGitBotUpdate) ClearProject() *ProjectGitBotUpdate { _u.mutation.ClearProject() return _u } // ClearGitBot clears the "git_bot" edge to the GitBot entity. func (_u *ProjectGitBotUpdate) ClearGitBot() *ProjectGitBotUpdate { _u.mutation.ClearGitBot() return _u } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *ProjectGitBotUpdate) 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 *ProjectGitBotUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *ProjectGitBotUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *ProjectGitBotUpdate) 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 *ProjectGitBotUpdate) check() error { if _u.mutation.ProjectCleared() && len(_u.mutation.ProjectIDs()) > 0 { return errors.New(`db: clearing a required unique edge "ProjectGitBot.project"`) } if _u.mutation.GitBotCleared() && len(_u.mutation.GitBotIDs()) > 0 { return errors.New(`db: clearing a required unique edge "ProjectGitBot.git_bot"`) } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *ProjectGitBotUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ProjectGitBotUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *ProjectGitBotUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(projectgitbot.Table, projectgitbot.Columns, sqlgraph.NewFieldSpec(projectgitbot.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.CreatedAt(); ok { _spec.SetField(projectgitbot.FieldCreatedAt, field.TypeTime, value) } if _u.mutation.ProjectCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: projectgitbot.ProjectTable, Columns: []string{projectgitbot.ProjectColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.ProjectIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: projectgitbot.ProjectTable, Columns: []string{projectgitbot.ProjectColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(project.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.GitBotCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: projectgitbot.GitBotTable, Columns: []string{projectgitbot.GitBotColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(gitbot.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.GitBotIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: projectgitbot.GitBotTable, Columns: []string{projectgitbot.GitBotColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(gitbot.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{projectgitbot.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // ProjectGitBotUpdateOne is the builder for updating a single ProjectGitBot entity. type ProjectGitBotUpdateOne struct { config fields []string hooks []Hook mutation *ProjectGitBotMutation modifiers []func(*sql.UpdateBuilder) } // SetProjectID sets the "project_id" field. func (_u *ProjectGitBotUpdateOne) SetProjectID(v uuid.UUID) *ProjectGitBotUpdateOne { _u.mutation.SetProjectID(v) return _u } // SetNillableProjectID sets the "project_id" field if the given value is not nil. func (_u *ProjectGitBotUpdateOne) SetNillableProjectID(v *uuid.UUID) *ProjectGitBotUpdateOne { if v != nil { _u.SetProjectID(*v) } return _u } // SetGitBotID sets the "git_bot_id" field. func (_u *ProjectGitBotUpdateOne) SetGitBotID(v uuid.UUID) *ProjectGitBotUpdateOne { _u.mutation.SetGitBotID(v) return _u } // SetNillableGitBotID sets the "git_bot_id" field if the given value is not nil. func (_u *ProjectGitBotUpdateOne) SetNillableGitBotID(v *uuid.UUID) *ProjectGitBotUpdateOne { if v != nil { _u.SetGitBotID(*v) } return _u } // SetCreatedAt sets the "created_at" field. func (_u *ProjectGitBotUpdateOne) SetCreatedAt(v time.Time) *ProjectGitBotUpdateOne { _u.mutation.SetCreatedAt(v) return _u } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_u *ProjectGitBotUpdateOne) SetNillableCreatedAt(v *time.Time) *ProjectGitBotUpdateOne { if v != nil { _u.SetCreatedAt(*v) } return _u } // SetProject sets the "project" edge to the Project entity. func (_u *ProjectGitBotUpdateOne) SetProject(v *Project) *ProjectGitBotUpdateOne { return _u.SetProjectID(v.ID) } // SetGitBot sets the "git_bot" edge to the GitBot entity. func (_u *ProjectGitBotUpdateOne) SetGitBot(v *GitBot) *ProjectGitBotUpdateOne { return _u.SetGitBotID(v.ID) } // Mutation returns the ProjectGitBotMutation object of the builder. func (_u *ProjectGitBotUpdateOne) Mutation() *ProjectGitBotMutation { return _u.mutation } // ClearProject clears the "project" edge to the Project entity. func (_u *ProjectGitBotUpdateOne) ClearProject() *ProjectGitBotUpdateOne { _u.mutation.ClearProject() return _u } // ClearGitBot clears the "git_bot" edge to the GitBot entity. func (_u *ProjectGitBotUpdateOne) ClearGitBot() *ProjectGitBotUpdateOne { _u.mutation.ClearGitBot() return _u } // Where appends a list predicates to the ProjectGitBotUpdate builder. func (_u *ProjectGitBotUpdateOne) Where(ps ...predicate.ProjectGitBot) *ProjectGitBotUpdateOne { _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 *ProjectGitBotUpdateOne) Select(field string, fields ...string) *ProjectGitBotUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated ProjectGitBot entity. func (_u *ProjectGitBotUpdateOne) Save(ctx context.Context) (*ProjectGitBot, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *ProjectGitBotUpdateOne) SaveX(ctx context.Context) *ProjectGitBot { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *ProjectGitBotUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *ProjectGitBotUpdateOne) 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 *ProjectGitBotUpdateOne) check() error { if _u.mutation.ProjectCleared() && len(_u.mutation.ProjectIDs()) > 0 { return errors.New(`db: clearing a required unique edge "ProjectGitBot.project"`) } if _u.mutation.GitBotCleared() && len(_u.mutation.GitBotIDs()) > 0 { return errors.New(`db: clearing a required unique edge "ProjectGitBot.git_bot"`) } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *ProjectGitBotUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ProjectGitBotUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *ProjectGitBotUpdateOne) sqlSave(ctx context.Context) (_node *ProjectGitBot, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(projectgitbot.Table, projectgitbot.Columns, sqlgraph.NewFieldSpec(projectgitbot.FieldID, field.TypeUUID)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "ProjectGitBot.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, projectgitbot.FieldID) for _, f := range fields { if !projectgitbot.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } if f != projectgitbot.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.CreatedAt(); ok { _spec.SetField(projectgitbot.FieldCreatedAt, field.TypeTime, value) } if _u.mutation.ProjectCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: projectgitbot.ProjectTable, Columns: []string{projectgitbot.ProjectColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.ProjectIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: projectgitbot.ProjectTable, Columns: []string{projectgitbot.ProjectColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(project.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.GitBotCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: projectgitbot.GitBotTable, Columns: []string{projectgitbot.GitBotColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(gitbot.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.GitBotIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: projectgitbot.GitBotTable, Columns: []string{projectgitbot.GitBotColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(gitbot.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 = &ProjectGitBot{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{projectgitbot.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }