// 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/db/gitbot" "github.com/chaitin/MonkeyCode/backend/db/gitbotuser" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) // GitBotUserCreate is the builder for creating a GitBotUser entity. type GitBotUserCreate struct { config mutation *GitBotUserMutation hooks []Hook conflict []sql.ConflictOption } // SetGitBotID sets the "git_bot_id" field. func (_c *GitBotUserCreate) SetGitBotID(v uuid.UUID) *GitBotUserCreate { _c.mutation.SetGitBotID(v) return _c } // SetUserID sets the "user_id" field. func (_c *GitBotUserCreate) SetUserID(v uuid.UUID) *GitBotUserCreate { _c.mutation.SetUserID(v) return _c } // SetCreatedAt sets the "created_at" field. func (_c *GitBotUserCreate) SetCreatedAt(v time.Time) *GitBotUserCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *GitBotUserCreate) SetNillableCreatedAt(v *time.Time) *GitBotUserCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetID sets the "id" field. func (_c *GitBotUserCreate) SetID(v uuid.UUID) *GitBotUserCreate { _c.mutation.SetID(v) return _c } // SetNillableID sets the "id" field if the given value is not nil. func (_c *GitBotUserCreate) SetNillableID(v *uuid.UUID) *GitBotUserCreate { if v != nil { _c.SetID(*v) } return _c } // SetGitBot sets the "git_bot" edge to the GitBot entity. func (_c *GitBotUserCreate) SetGitBot(v *GitBot) *GitBotUserCreate { return _c.SetGitBotID(v.ID) } // SetUser sets the "user" edge to the User entity. func (_c *GitBotUserCreate) SetUser(v *User) *GitBotUserCreate { return _c.SetUserID(v.ID) } // Mutation returns the GitBotUserMutation object of the builder. func (_c *GitBotUserCreate) Mutation() *GitBotUserMutation { return _c.mutation } // Save creates the GitBotUser in the database. func (_c *GitBotUserCreate) Save(ctx context.Context) (*GitBotUser, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *GitBotUserCreate) SaveX(ctx context.Context) *GitBotUser { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *GitBotUserCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *GitBotUserCreate) 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 *GitBotUserCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := gitbotuser.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.ID(); !ok { v := gitbotuser.DefaultID() _c.mutation.SetID(v) } } // check runs all checks and user-defined validators on the builder. func (_c *GitBotUserCreate) check() error { if _, ok := _c.mutation.GitBotID(); !ok { return &ValidationError{Name: "git_bot_id", err: errors.New(`db: missing required field "GitBotUser.git_bot_id"`)} } if _, ok := _c.mutation.UserID(); !ok { return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "GitBotUser.user_id"`)} } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "GitBotUser.created_at"`)} } if len(_c.mutation.GitBotIDs()) == 0 { return &ValidationError{Name: "git_bot", err: errors.New(`db: missing required edge "GitBotUser.git_bot"`)} } if len(_c.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "GitBotUser.user"`)} } return nil } func (_c *GitBotUserCreate) sqlSave(ctx context.Context) (*GitBotUser, 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 *GitBotUserCreate) createSpec() (*GitBotUser, *sqlgraph.CreateSpec) { var ( _node = &GitBotUser{config: _c.config} _spec = sqlgraph.NewCreateSpec(gitbotuser.Table, sqlgraph.NewFieldSpec(gitbotuser.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.CreatedAt(); ok { _spec.SetField(gitbotuser.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if nodes := _c.mutation.GitBotIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: gitbotuser.GitBotTable, Columns: []string{gitbotuser.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) } _node.GitBotID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.UserIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: gitbotuser.UserTable, Columns: []string{gitbotuser.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.UserID = nodes[0] _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.GitBotUser.Create(). // SetGitBotID(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.GitBotUserUpsert) { // SetGitBotID(v+v). // }). // Exec(ctx) func (_c *GitBotUserCreate) OnConflict(opts ...sql.ConflictOption) *GitBotUserUpsertOne { _c.conflict = opts return &GitBotUserUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.GitBotUser.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *GitBotUserCreate) OnConflictColumns(columns ...string) *GitBotUserUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &GitBotUserUpsertOne{ create: _c, } } type ( // GitBotUserUpsertOne is the builder for "upsert"-ing // one GitBotUser node. GitBotUserUpsertOne struct { create *GitBotUserCreate } // GitBotUserUpsert is the "OnConflict" setter. GitBotUserUpsert struct { *sql.UpdateSet } ) // SetGitBotID sets the "git_bot_id" field. func (u *GitBotUserUpsert) SetGitBotID(v uuid.UUID) *GitBotUserUpsert { u.Set(gitbotuser.FieldGitBotID, v) return u } // UpdateGitBotID sets the "git_bot_id" field to the value that was provided on create. func (u *GitBotUserUpsert) UpdateGitBotID() *GitBotUserUpsert { u.SetExcluded(gitbotuser.FieldGitBotID) return u } // SetUserID sets the "user_id" field. func (u *GitBotUserUpsert) SetUserID(v uuid.UUID) *GitBotUserUpsert { u.Set(gitbotuser.FieldUserID, v) return u } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *GitBotUserUpsert) UpdateUserID() *GitBotUserUpsert { u.SetExcluded(gitbotuser.FieldUserID) return u } // SetCreatedAt sets the "created_at" field. func (u *GitBotUserUpsert) SetCreatedAt(v time.Time) *GitBotUserUpsert { u.Set(gitbotuser.FieldCreatedAt, v) return u } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *GitBotUserUpsert) UpdateCreatedAt() *GitBotUserUpsert { u.SetExcluded(gitbotuser.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.GitBotUser.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(gitbotuser.FieldID) // }), // ). // Exec(ctx) func (u *GitBotUserUpsertOne) UpdateNewValues() *GitBotUserUpsertOne { 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(gitbotuser.FieldID) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.GitBotUser.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *GitBotUserUpsertOne) Ignore() *GitBotUserUpsertOne { 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 *GitBotUserUpsertOne) DoNothing() *GitBotUserUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the GitBotUserCreate.OnConflict // documentation for more info. func (u *GitBotUserUpsertOne) Update(set func(*GitBotUserUpsert)) *GitBotUserUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&GitBotUserUpsert{UpdateSet: update}) })) return u } // SetGitBotID sets the "git_bot_id" field. func (u *GitBotUserUpsertOne) SetGitBotID(v uuid.UUID) *GitBotUserUpsertOne { return u.Update(func(s *GitBotUserUpsert) { s.SetGitBotID(v) }) } // UpdateGitBotID sets the "git_bot_id" field to the value that was provided on create. func (u *GitBotUserUpsertOne) UpdateGitBotID() *GitBotUserUpsertOne { return u.Update(func(s *GitBotUserUpsert) { s.UpdateGitBotID() }) } // SetUserID sets the "user_id" field. func (u *GitBotUserUpsertOne) SetUserID(v uuid.UUID) *GitBotUserUpsertOne { return u.Update(func(s *GitBotUserUpsert) { s.SetUserID(v) }) } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *GitBotUserUpsertOne) UpdateUserID() *GitBotUserUpsertOne { return u.Update(func(s *GitBotUserUpsert) { s.UpdateUserID() }) } // SetCreatedAt sets the "created_at" field. func (u *GitBotUserUpsertOne) SetCreatedAt(v time.Time) *GitBotUserUpsertOne { return u.Update(func(s *GitBotUserUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *GitBotUserUpsertOne) UpdateCreatedAt() *GitBotUserUpsertOne { return u.Update(func(s *GitBotUserUpsert) { s.UpdateCreatedAt() }) } // Exec executes the query. func (u *GitBotUserUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("db: missing options for GitBotUserCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *GitBotUserUpsertOne) 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 *GitBotUserUpsertOne) 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: GitBotUserUpsertOne.ID is not supported by MySQL driver. Use GitBotUserUpsertOne.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 *GitBotUserUpsertOne) IDX(ctx context.Context) uuid.UUID { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // GitBotUserCreateBulk is the builder for creating many GitBotUser entities in bulk. type GitBotUserCreateBulk struct { config err error builders []*GitBotUserCreate conflict []sql.ConflictOption } // Save creates the GitBotUser entities in the database. func (_c *GitBotUserCreateBulk) Save(ctx context.Context) ([]*GitBotUser, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*GitBotUser, 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.(*GitBotUserMutation) 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 *GitBotUserCreateBulk) SaveX(ctx context.Context) []*GitBotUser { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *GitBotUserCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *GitBotUserCreateBulk) 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.GitBotUser.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.GitBotUserUpsert) { // SetGitBotID(v+v). // }). // Exec(ctx) func (_c *GitBotUserCreateBulk) OnConflict(opts ...sql.ConflictOption) *GitBotUserUpsertBulk { _c.conflict = opts return &GitBotUserUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.GitBotUser.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *GitBotUserCreateBulk) OnConflictColumns(columns ...string) *GitBotUserUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &GitBotUserUpsertBulk{ create: _c, } } // GitBotUserUpsertBulk is the builder for "upsert"-ing // a bulk of GitBotUser nodes. type GitBotUserUpsertBulk struct { create *GitBotUserCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.GitBotUser.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(gitbotuser.FieldID) // }), // ). // Exec(ctx) func (u *GitBotUserUpsertBulk) UpdateNewValues() *GitBotUserUpsertBulk { 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(gitbotuser.FieldID) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.GitBotUser.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *GitBotUserUpsertBulk) Ignore() *GitBotUserUpsertBulk { 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 *GitBotUserUpsertBulk) DoNothing() *GitBotUserUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the GitBotUserCreateBulk.OnConflict // documentation for more info. func (u *GitBotUserUpsertBulk) Update(set func(*GitBotUserUpsert)) *GitBotUserUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&GitBotUserUpsert{UpdateSet: update}) })) return u } // SetGitBotID sets the "git_bot_id" field. func (u *GitBotUserUpsertBulk) SetGitBotID(v uuid.UUID) *GitBotUserUpsertBulk { return u.Update(func(s *GitBotUserUpsert) { s.SetGitBotID(v) }) } // UpdateGitBotID sets the "git_bot_id" field to the value that was provided on create. func (u *GitBotUserUpsertBulk) UpdateGitBotID() *GitBotUserUpsertBulk { return u.Update(func(s *GitBotUserUpsert) { s.UpdateGitBotID() }) } // SetUserID sets the "user_id" field. func (u *GitBotUserUpsertBulk) SetUserID(v uuid.UUID) *GitBotUserUpsertBulk { return u.Update(func(s *GitBotUserUpsert) { s.SetUserID(v) }) } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *GitBotUserUpsertBulk) UpdateUserID() *GitBotUserUpsertBulk { return u.Update(func(s *GitBotUserUpsert) { s.UpdateUserID() }) } // SetCreatedAt sets the "created_at" field. func (u *GitBotUserUpsertBulk) SetCreatedAt(v time.Time) *GitBotUserUpsertBulk { return u.Update(func(s *GitBotUserUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *GitBotUserUpsertBulk) UpdateCreatedAt() *GitBotUserUpsertBulk { return u.Update(func(s *GitBotUserUpsert) { s.UpdateCreatedAt() }) } // Exec executes the query. func (u *GitBotUserUpsertBulk) 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 GitBotUserCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("db: missing options for GitBotUserCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *GitBotUserUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }