// Code generated by ent, DO NOT EDIT. package db import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/chaitin/MonkeyCode/backend/consts" "github.com/chaitin/MonkeyCode/backend/db/gitbot" "github.com/chaitin/MonkeyCode/backend/db/gitbottask" "github.com/chaitin/MonkeyCode/backend/db/gitbotuser" "github.com/chaitin/MonkeyCode/backend/db/host" "github.com/chaitin/MonkeyCode/backend/db/project" "github.com/chaitin/MonkeyCode/backend/db/projectgitbot" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) // GitBotCreate is the builder for creating a GitBot entity. type GitBotCreate struct { config mutation *GitBotMutation hooks []Hook conflict []sql.ConflictOption } // SetDeletedAt sets the "deleted_at" field. func (_c *GitBotCreate) SetDeletedAt(v time.Time) *GitBotCreate { _c.mutation.SetDeletedAt(v) return _c } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_c *GitBotCreate) SetNillableDeletedAt(v *time.Time) *GitBotCreate { if v != nil { _c.SetDeletedAt(*v) } return _c } // SetUserID sets the "user_id" field. func (_c *GitBotCreate) SetUserID(v uuid.UUID) *GitBotCreate { _c.mutation.SetUserID(v) return _c } // SetName sets the "name" field. func (_c *GitBotCreate) SetName(v string) *GitBotCreate { _c.mutation.SetName(v) return _c } // SetNillableName sets the "name" field if the given value is not nil. func (_c *GitBotCreate) SetNillableName(v *string) *GitBotCreate { if v != nil { _c.SetName(*v) } return _c } // SetHostID sets the "host_id" field. func (_c *GitBotCreate) SetHostID(v string) *GitBotCreate { _c.mutation.SetHostID(v) return _c } // SetToken sets the "token" field. func (_c *GitBotCreate) SetToken(v string) *GitBotCreate { _c.mutation.SetToken(v) return _c } // SetNillableToken sets the "token" field if the given value is not nil. func (_c *GitBotCreate) SetNillableToken(v *string) *GitBotCreate { if v != nil { _c.SetToken(*v) } return _c } // SetSecretToken sets the "secret_token" field. func (_c *GitBotCreate) SetSecretToken(v string) *GitBotCreate { _c.mutation.SetSecretToken(v) return _c } // SetNillableSecretToken sets the "secret_token" field if the given value is not nil. func (_c *GitBotCreate) SetNillableSecretToken(v *string) *GitBotCreate { if v != nil { _c.SetSecretToken(*v) } return _c } // SetPlatform sets the "platform" field. func (_c *GitBotCreate) SetPlatform(v consts.GitPlatform) *GitBotCreate { _c.mutation.SetPlatform(v) return _c } // SetCreatedAt sets the "created_at" field. func (_c *GitBotCreate) SetCreatedAt(v time.Time) *GitBotCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *GitBotCreate) SetNillableCreatedAt(v *time.Time) *GitBotCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetID sets the "id" field. func (_c *GitBotCreate) SetID(v uuid.UUID) *GitBotCreate { _c.mutation.SetID(v) return _c } // AddGitBotTaskIDs adds the "git_bot_tasks" edge to the GitBotTask entity by IDs. func (_c *GitBotCreate) AddGitBotTaskIDs(ids ...uuid.UUID) *GitBotCreate { _c.mutation.AddGitBotTaskIDs(ids...) return _c } // AddGitBotTasks adds the "git_bot_tasks" edges to the GitBotTask entity. func (_c *GitBotCreate) AddGitBotTasks(v ...*GitBotTask) *GitBotCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddGitBotTaskIDs(ids...) } // SetHost sets the "host" edge to the Host entity. func (_c *GitBotCreate) SetHost(v *Host) *GitBotCreate { return _c.SetHostID(v.ID) } // AddUserIDs adds the "users" edge to the User entity by IDs. func (_c *GitBotCreate) AddUserIDs(ids ...uuid.UUID) *GitBotCreate { _c.mutation.AddUserIDs(ids...) return _c } // AddUsers adds the "users" edges to the User entity. func (_c *GitBotCreate) AddUsers(v ...*User) *GitBotCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddUserIDs(ids...) } // AddProjectIDs adds the "projects" edge to the Project entity by IDs. func (_c *GitBotCreate) AddProjectIDs(ids ...uuid.UUID) *GitBotCreate { _c.mutation.AddProjectIDs(ids...) return _c } // AddProjects adds the "projects" edges to the Project entity. func (_c *GitBotCreate) AddProjects(v ...*Project) *GitBotCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddProjectIDs(ids...) } // AddGitBotUserIDs adds the "git_bot_users" edge to the GitBotUser entity by IDs. func (_c *GitBotCreate) AddGitBotUserIDs(ids ...uuid.UUID) *GitBotCreate { _c.mutation.AddGitBotUserIDs(ids...) return _c } // AddGitBotUsers adds the "git_bot_users" edges to the GitBotUser entity. func (_c *GitBotCreate) AddGitBotUsers(v ...*GitBotUser) *GitBotCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddGitBotUserIDs(ids...) } // AddProjectGitBotIDs adds the "project_git_bots" edge to the ProjectGitBot entity by IDs. func (_c *GitBotCreate) AddProjectGitBotIDs(ids ...uuid.UUID) *GitBotCreate { _c.mutation.AddProjectGitBotIDs(ids...) return _c } // AddProjectGitBots adds the "project_git_bots" edges to the ProjectGitBot entity. func (_c *GitBotCreate) AddProjectGitBots(v ...*ProjectGitBot) *GitBotCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddProjectGitBotIDs(ids...) } // Mutation returns the GitBotMutation object of the builder. func (_c *GitBotCreate) Mutation() *GitBotMutation { return _c.mutation } // Save creates the GitBot in the database. func (_c *GitBotCreate) Save(ctx context.Context) (*GitBot, error) { if err := _c.defaults(); err != nil { return nil, err } return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *GitBotCreate) SaveX(ctx context.Context) *GitBot { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *GitBotCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *GitBotCreate) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_c *GitBotCreate) defaults() error { if _, ok := _c.mutation.CreatedAt(); !ok { if gitbot.DefaultCreatedAt == nil { return fmt.Errorf("db: uninitialized gitbot.DefaultCreatedAt (forgotten import db/runtime?)") } v := gitbot.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (_c *GitBotCreate) check() error { if _, ok := _c.mutation.UserID(); !ok { return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "GitBot.user_id"`)} } if _, ok := _c.mutation.HostID(); !ok { return &ValidationError{Name: "host_id", err: errors.New(`db: missing required field "GitBot.host_id"`)} } if _, ok := _c.mutation.Platform(); !ok { return &ValidationError{Name: "platform", err: errors.New(`db: missing required field "GitBot.platform"`)} } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "GitBot.created_at"`)} } if len(_c.mutation.HostIDs()) == 0 { return &ValidationError{Name: "host", err: errors.New(`db: missing required edge "GitBot.host"`)} } return nil } func (_c *GitBotCreate) sqlSave(ctx context.Context) (*GitBot, error) { if err := _c.check(); err != nil { return nil, err } _node, _spec := _c.createSpec() if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } if _spec.ID.Value != nil { if id, ok := _spec.ID.Value.(*uuid.UUID); ok { _node.ID = *id } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { return nil, err } } _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *GitBotCreate) createSpec() (*GitBot, *sqlgraph.CreateSpec) { var ( _node = &GitBot{config: _c.config} _spec = sqlgraph.NewCreateSpec(gitbot.Table, sqlgraph.NewFieldSpec(gitbot.FieldID, field.TypeUUID)) ) _spec.OnConflict = _c.conflict if id, ok := _c.mutation.ID(); ok { _node.ID = id _spec.ID.Value = &id } if value, ok := _c.mutation.DeletedAt(); ok { _spec.SetField(gitbot.FieldDeletedAt, field.TypeTime, value) _node.DeletedAt = value } if value, ok := _c.mutation.UserID(); ok { _spec.SetField(gitbot.FieldUserID, field.TypeUUID, value) _node.UserID = value } if value, ok := _c.mutation.Name(); ok { _spec.SetField(gitbot.FieldName, field.TypeString, value) _node.Name = value } if value, ok := _c.mutation.Token(); ok { _spec.SetField(gitbot.FieldToken, field.TypeString, value) _node.Token = value } if value, ok := _c.mutation.SecretToken(); ok { _spec.SetField(gitbot.FieldSecretToken, field.TypeString, value) _node.SecretToken = value } if value, ok := _c.mutation.Platform(); ok { _spec.SetField(gitbot.FieldPlatform, field.TypeString, value) _node.Platform = value } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(gitbot.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if nodes := _c.mutation.GitBotTasksIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: gitbot.GitBotTasksTable, Columns: []string{gitbot.GitBotTasksColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(gitbottask.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.HostIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: gitbot.HostTable, Columns: []string{gitbot.HostColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(host.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.HostID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.UsersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: gitbot.UsersTable, Columns: gitbot.UsersPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } createE := &GitBotUserCreate{config: _c.config, mutation: newGitBotUserMutation(_c.config, OpCreate)} createE.defaults() _, specE := createE.createSpec() edge.Target.Fields = specE.Fields if specE.ID.Value != nil { edge.Target.Fields = append(edge.Target.Fields, specE.ID) } _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.ProjectsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: gitbot.ProjectsTable, Columns: gitbot.ProjectsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } createE := &ProjectGitBotCreate{config: _c.config, mutation: newProjectGitBotMutation(_c.config, OpCreate)} createE.defaults() _, specE := createE.createSpec() edge.Target.Fields = specE.Fields if specE.ID.Value != nil { edge.Target.Fields = append(edge.Target.Fields, specE.ID) } _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.GitBotUsersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: gitbot.GitBotUsersTable, Columns: []string{gitbot.GitBotUsersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(gitbotuser.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.ProjectGitBotsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: gitbot.ProjectGitBotsTable, Columns: []string{gitbot.ProjectGitBotsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(projectgitbot.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges = append(_spec.Edges, edge) } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.GitBot.Create(). // SetDeletedAt(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.GitBotUpsert) { // SetDeletedAt(v+v). // }). // Exec(ctx) func (_c *GitBotCreate) OnConflict(opts ...sql.ConflictOption) *GitBotUpsertOne { _c.conflict = opts return &GitBotUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.GitBot.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *GitBotCreate) OnConflictColumns(columns ...string) *GitBotUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &GitBotUpsertOne{ create: _c, } } type ( // GitBotUpsertOne is the builder for "upsert"-ing // one GitBot node. GitBotUpsertOne struct { create *GitBotCreate } // GitBotUpsert is the "OnConflict" setter. GitBotUpsert struct { *sql.UpdateSet } ) // SetDeletedAt sets the "deleted_at" field. func (u *GitBotUpsert) SetDeletedAt(v time.Time) *GitBotUpsert { u.Set(gitbot.FieldDeletedAt, v) return u } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *GitBotUpsert) UpdateDeletedAt() *GitBotUpsert { u.SetExcluded(gitbot.FieldDeletedAt) return u } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *GitBotUpsert) ClearDeletedAt() *GitBotUpsert { u.SetNull(gitbot.FieldDeletedAt) return u } // SetUserID sets the "user_id" field. func (u *GitBotUpsert) SetUserID(v uuid.UUID) *GitBotUpsert { u.Set(gitbot.FieldUserID, v) return u } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *GitBotUpsert) UpdateUserID() *GitBotUpsert { u.SetExcluded(gitbot.FieldUserID) return u } // SetName sets the "name" field. func (u *GitBotUpsert) SetName(v string) *GitBotUpsert { u.Set(gitbot.FieldName, v) return u } // UpdateName sets the "name" field to the value that was provided on create. func (u *GitBotUpsert) UpdateName() *GitBotUpsert { u.SetExcluded(gitbot.FieldName) return u } // ClearName clears the value of the "name" field. func (u *GitBotUpsert) ClearName() *GitBotUpsert { u.SetNull(gitbot.FieldName) return u } // SetHostID sets the "host_id" field. func (u *GitBotUpsert) SetHostID(v string) *GitBotUpsert { u.Set(gitbot.FieldHostID, v) return u } // UpdateHostID sets the "host_id" field to the value that was provided on create. func (u *GitBotUpsert) UpdateHostID() *GitBotUpsert { u.SetExcluded(gitbot.FieldHostID) return u } // SetToken sets the "token" field. func (u *GitBotUpsert) SetToken(v string) *GitBotUpsert { u.Set(gitbot.FieldToken, v) return u } // UpdateToken sets the "token" field to the value that was provided on create. func (u *GitBotUpsert) UpdateToken() *GitBotUpsert { u.SetExcluded(gitbot.FieldToken) return u } // ClearToken clears the value of the "token" field. func (u *GitBotUpsert) ClearToken() *GitBotUpsert { u.SetNull(gitbot.FieldToken) return u } // SetSecretToken sets the "secret_token" field. func (u *GitBotUpsert) SetSecretToken(v string) *GitBotUpsert { u.Set(gitbot.FieldSecretToken, v) return u } // UpdateSecretToken sets the "secret_token" field to the value that was provided on create. func (u *GitBotUpsert) UpdateSecretToken() *GitBotUpsert { u.SetExcluded(gitbot.FieldSecretToken) return u } // ClearSecretToken clears the value of the "secret_token" field. func (u *GitBotUpsert) ClearSecretToken() *GitBotUpsert { u.SetNull(gitbot.FieldSecretToken) return u } // SetPlatform sets the "platform" field. func (u *GitBotUpsert) SetPlatform(v consts.GitPlatform) *GitBotUpsert { u.Set(gitbot.FieldPlatform, v) return u } // UpdatePlatform sets the "platform" field to the value that was provided on create. func (u *GitBotUpsert) UpdatePlatform() *GitBotUpsert { u.SetExcluded(gitbot.FieldPlatform) return u } // SetCreatedAt sets the "created_at" field. func (u *GitBotUpsert) SetCreatedAt(v time.Time) *GitBotUpsert { u.Set(gitbot.FieldCreatedAt, v) return u } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *GitBotUpsert) UpdateCreatedAt() *GitBotUpsert { u.SetExcluded(gitbot.FieldCreatedAt) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. // Using this option is equivalent to using: // // client.GitBot.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(gitbot.FieldID) // }), // ). // Exec(ctx) func (u *GitBotUpsertOne) UpdateNewValues() *GitBotUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { if _, exists := u.create.mutation.ID(); exists { s.SetIgnore(gitbot.FieldID) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.GitBot.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *GitBotUpsertOne) Ignore() *GitBotUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *GitBotUpsertOne) DoNothing() *GitBotUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the GitBotCreate.OnConflict // documentation for more info. func (u *GitBotUpsertOne) Update(set func(*GitBotUpsert)) *GitBotUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&GitBotUpsert{UpdateSet: update}) })) return u } // SetDeletedAt sets the "deleted_at" field. func (u *GitBotUpsertOne) SetDeletedAt(v time.Time) *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *GitBotUpsertOne) UpdateDeletedAt() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *GitBotUpsertOne) ClearDeletedAt() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.ClearDeletedAt() }) } // SetUserID sets the "user_id" field. func (u *GitBotUpsertOne) SetUserID(v uuid.UUID) *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.SetUserID(v) }) } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *GitBotUpsertOne) UpdateUserID() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.UpdateUserID() }) } // SetName sets the "name" field. func (u *GitBotUpsertOne) SetName(v string) *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *GitBotUpsertOne) UpdateName() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.UpdateName() }) } // ClearName clears the value of the "name" field. func (u *GitBotUpsertOne) ClearName() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.ClearName() }) } // SetHostID sets the "host_id" field. func (u *GitBotUpsertOne) SetHostID(v string) *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.SetHostID(v) }) } // UpdateHostID sets the "host_id" field to the value that was provided on create. func (u *GitBotUpsertOne) UpdateHostID() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.UpdateHostID() }) } // SetToken sets the "token" field. func (u *GitBotUpsertOne) SetToken(v string) *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.SetToken(v) }) } // UpdateToken sets the "token" field to the value that was provided on create. func (u *GitBotUpsertOne) UpdateToken() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.UpdateToken() }) } // ClearToken clears the value of the "token" field. func (u *GitBotUpsertOne) ClearToken() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.ClearToken() }) } // SetSecretToken sets the "secret_token" field. func (u *GitBotUpsertOne) SetSecretToken(v string) *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.SetSecretToken(v) }) } // UpdateSecretToken sets the "secret_token" field to the value that was provided on create. func (u *GitBotUpsertOne) UpdateSecretToken() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.UpdateSecretToken() }) } // ClearSecretToken clears the value of the "secret_token" field. func (u *GitBotUpsertOne) ClearSecretToken() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.ClearSecretToken() }) } // SetPlatform sets the "platform" field. func (u *GitBotUpsertOne) SetPlatform(v consts.GitPlatform) *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.SetPlatform(v) }) } // UpdatePlatform sets the "platform" field to the value that was provided on create. func (u *GitBotUpsertOne) UpdatePlatform() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.UpdatePlatform() }) } // SetCreatedAt sets the "created_at" field. func (u *GitBotUpsertOne) SetCreatedAt(v time.Time) *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *GitBotUpsertOne) UpdateCreatedAt() *GitBotUpsertOne { return u.Update(func(s *GitBotUpsert) { s.UpdateCreatedAt() }) } // Exec executes the query. func (u *GitBotUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("db: missing options for GitBotCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *GitBotUpsertOne) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } } // Exec executes the UPSERT query and returns the inserted/updated ID. func (u *GitBotUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) { if u.create.driver.Dialect() == dialect.MySQL { // In case of "ON CONFLICT", there is no way to get back non-numeric ID // fields from the database since MySQL does not support the RETURNING clause. return id, errors.New("db: GitBotUpsertOne.ID is not supported by MySQL driver. Use GitBotUpsertOne.Exec instead") } node, err := u.create.Save(ctx) if err != nil { return id, err } return node.ID, nil } // IDX is like ID, but panics if an error occurs. func (u *GitBotUpsertOne) IDX(ctx context.Context) uuid.UUID { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // GitBotCreateBulk is the builder for creating many GitBot entities in bulk. type GitBotCreateBulk struct { config err error builders []*GitBotCreate conflict []sql.ConflictOption } // Save creates the GitBot entities in the database. func (_c *GitBotCreateBulk) Save(ctx context.Context) ([]*GitBot, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*GitBot, len(_c.builders)) mutators := make([]Mutator, len(_c.builders)) for i := range _c.builders { func(i int, root context.Context) { builder := _c.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*GitBotMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } if err := builder.check(); err != nil { return nil, err } builder.mutation = mutation var err error nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = _c.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } } } if err != nil { return nil, err } mutation.id = &nodes[i].ID mutation.done = true return nodes[i], nil }) for i := len(builder.hooks) - 1; i >= 0; i-- { mut = builder.hooks[i](mut) } mutators[i] = mut }(i, ctx) } if len(mutators) > 0 { if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (_c *GitBotCreateBulk) SaveX(ctx context.Context) []*GitBot { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *GitBotCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *GitBotCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.GitBot.CreateBulk(builders...). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.GitBotUpsert) { // SetDeletedAt(v+v). // }). // Exec(ctx) func (_c *GitBotCreateBulk) OnConflict(opts ...sql.ConflictOption) *GitBotUpsertBulk { _c.conflict = opts return &GitBotUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.GitBot.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *GitBotCreateBulk) OnConflictColumns(columns ...string) *GitBotUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &GitBotUpsertBulk{ create: _c, } } // GitBotUpsertBulk is the builder for "upsert"-ing // a bulk of GitBot nodes. type GitBotUpsertBulk struct { create *GitBotCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.GitBot.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(gitbot.FieldID) // }), // ). // Exec(ctx) func (u *GitBotUpsertBulk) UpdateNewValues() *GitBotUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { for _, b := range u.create.builders { if _, exists := b.mutation.ID(); exists { s.SetIgnore(gitbot.FieldID) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.GitBot.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *GitBotUpsertBulk) Ignore() *GitBotUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *GitBotUpsertBulk) DoNothing() *GitBotUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the GitBotCreateBulk.OnConflict // documentation for more info. func (u *GitBotUpsertBulk) Update(set func(*GitBotUpsert)) *GitBotUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&GitBotUpsert{UpdateSet: update}) })) return u } // SetDeletedAt sets the "deleted_at" field. func (u *GitBotUpsertBulk) SetDeletedAt(v time.Time) *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *GitBotUpsertBulk) UpdateDeletedAt() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *GitBotUpsertBulk) ClearDeletedAt() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.ClearDeletedAt() }) } // SetUserID sets the "user_id" field. func (u *GitBotUpsertBulk) SetUserID(v uuid.UUID) *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.SetUserID(v) }) } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *GitBotUpsertBulk) UpdateUserID() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.UpdateUserID() }) } // SetName sets the "name" field. func (u *GitBotUpsertBulk) SetName(v string) *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *GitBotUpsertBulk) UpdateName() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.UpdateName() }) } // ClearName clears the value of the "name" field. func (u *GitBotUpsertBulk) ClearName() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.ClearName() }) } // SetHostID sets the "host_id" field. func (u *GitBotUpsertBulk) SetHostID(v string) *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.SetHostID(v) }) } // UpdateHostID sets the "host_id" field to the value that was provided on create. func (u *GitBotUpsertBulk) UpdateHostID() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.UpdateHostID() }) } // SetToken sets the "token" field. func (u *GitBotUpsertBulk) SetToken(v string) *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.SetToken(v) }) } // UpdateToken sets the "token" field to the value that was provided on create. func (u *GitBotUpsertBulk) UpdateToken() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.UpdateToken() }) } // ClearToken clears the value of the "token" field. func (u *GitBotUpsertBulk) ClearToken() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.ClearToken() }) } // SetSecretToken sets the "secret_token" field. func (u *GitBotUpsertBulk) SetSecretToken(v string) *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.SetSecretToken(v) }) } // UpdateSecretToken sets the "secret_token" field to the value that was provided on create. func (u *GitBotUpsertBulk) UpdateSecretToken() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.UpdateSecretToken() }) } // ClearSecretToken clears the value of the "secret_token" field. func (u *GitBotUpsertBulk) ClearSecretToken() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.ClearSecretToken() }) } // SetPlatform sets the "platform" field. func (u *GitBotUpsertBulk) SetPlatform(v consts.GitPlatform) *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.SetPlatform(v) }) } // UpdatePlatform sets the "platform" field to the value that was provided on create. func (u *GitBotUpsertBulk) UpdatePlatform() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.UpdatePlatform() }) } // SetCreatedAt sets the "created_at" field. func (u *GitBotUpsertBulk) SetCreatedAt(v time.Time) *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *GitBotUpsertBulk) UpdateCreatedAt() *GitBotUpsertBulk { return u.Update(func(s *GitBotUpsert) { s.UpdateCreatedAt() }) } // Exec executes the query. func (u *GitBotUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { return u.create.err } for i, b := range u.create.builders { if len(b.conflict) != 0 { return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the GitBotCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("db: missing options for GitBotCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *GitBotUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }