// 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/image" "github.com/chaitin/MonkeyCode/backend/db/model" "github.com/chaitin/MonkeyCode/backend/db/team" "github.com/chaitin/MonkeyCode/backend/db/teamgroup" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) // TeamCreate is the builder for creating a Team entity. type TeamCreate struct { config mutation *TeamMutation hooks []Hook conflict []sql.ConflictOption } // SetDeletedAt sets the "deleted_at" field. func (_c *TeamCreate) SetDeletedAt(v time.Time) *TeamCreate { _c.mutation.SetDeletedAt(v) return _c } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_c *TeamCreate) SetNillableDeletedAt(v *time.Time) *TeamCreate { if v != nil { _c.SetDeletedAt(*v) } return _c } // SetName sets the "name" field. func (_c *TeamCreate) SetName(v string) *TeamCreate { _c.mutation.SetName(v) return _c } // SetMemberLimit sets the "member_limit" field. func (_c *TeamCreate) SetMemberLimit(v int) *TeamCreate { _c.mutation.SetMemberLimit(v) return _c } // SetCreatedAt sets the "created_at" field. func (_c *TeamCreate) SetCreatedAt(v time.Time) *TeamCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *TeamCreate) SetNillableCreatedAt(v *time.Time) *TeamCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *TeamCreate) SetUpdatedAt(v time.Time) *TeamCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *TeamCreate) SetNillableUpdatedAt(v *time.Time) *TeamCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetID sets the "id" field. func (_c *TeamCreate) SetID(v uuid.UUID) *TeamCreate { _c.mutation.SetID(v) return _c } // AddGroupIDs adds the "groups" edge to the TeamGroup entity by IDs. func (_c *TeamCreate) AddGroupIDs(ids ...uuid.UUID) *TeamCreate { _c.mutation.AddGroupIDs(ids...) return _c } // AddGroups adds the "groups" edges to the TeamGroup entity. func (_c *TeamCreate) AddGroups(v ...*TeamGroup) *TeamCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddGroupIDs(ids...) } // AddMemberIDs adds the "members" edge to the User entity by IDs. func (_c *TeamCreate) AddMemberIDs(ids ...uuid.UUID) *TeamCreate { _c.mutation.AddMemberIDs(ids...) return _c } // AddMembers adds the "members" edges to the User entity. func (_c *TeamCreate) AddMembers(v ...*User) *TeamCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddMemberIDs(ids...) } // AddModelIDs adds the "models" edge to the Model entity by IDs. func (_c *TeamCreate) AddModelIDs(ids ...uuid.UUID) *TeamCreate { _c.mutation.AddModelIDs(ids...) return _c } // AddModels adds the "models" edges to the Model entity. func (_c *TeamCreate) AddModels(v ...*Model) *TeamCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddModelIDs(ids...) } // AddImageIDs adds the "images" edge to the Image entity by IDs. func (_c *TeamCreate) AddImageIDs(ids ...uuid.UUID) *TeamCreate { _c.mutation.AddImageIDs(ids...) return _c } // AddImages adds the "images" edges to the Image entity. func (_c *TeamCreate) AddImages(v ...*Image) *TeamCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddImageIDs(ids...) } // AddTeamMemberIDs adds the "team_members" edge to the TeamMember entity by IDs. func (_c *TeamCreate) AddTeamMemberIDs(ids ...uuid.UUID) *TeamCreate { _c.mutation.AddTeamMemberIDs(ids...) return _c } // AddTeamMembers adds the "team_members" edges to the TeamMember entity. func (_c *TeamCreate) AddTeamMembers(v ...*TeamMember) *TeamCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddTeamMemberIDs(ids...) } // AddTeamModelIDs adds the "team_models" edge to the TeamModel entity by IDs. func (_c *TeamCreate) AddTeamModelIDs(ids ...uuid.UUID) *TeamCreate { _c.mutation.AddTeamModelIDs(ids...) return _c } // AddTeamModels adds the "team_models" edges to the TeamModel entity. func (_c *TeamCreate) AddTeamModels(v ...*TeamModel) *TeamCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddTeamModelIDs(ids...) } // AddTeamImageIDs adds the "team_images" edge to the TeamImage entity by IDs. func (_c *TeamCreate) AddTeamImageIDs(ids ...uuid.UUID) *TeamCreate { _c.mutation.AddTeamImageIDs(ids...) return _c } // AddTeamImages adds the "team_images" edges to the TeamImage entity. func (_c *TeamCreate) AddTeamImages(v ...*TeamImage) *TeamCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddTeamImageIDs(ids...) } // Mutation returns the TeamMutation object of the builder. func (_c *TeamCreate) Mutation() *TeamMutation { return _c.mutation } // Save creates the Team in the database. func (_c *TeamCreate) Save(ctx context.Context) (*Team, 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 *TeamCreate) SaveX(ctx context.Context) *Team { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *TeamCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *TeamCreate) 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 *TeamCreate) defaults() error { if _, ok := _c.mutation.CreatedAt(); !ok { if team.DefaultCreatedAt == nil { return fmt.Errorf("db: uninitialized team.DefaultCreatedAt (forgotten import db/runtime?)") } v := team.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { if team.DefaultUpdatedAt == nil { return fmt.Errorf("db: uninitialized team.DefaultUpdatedAt (forgotten import db/runtime?)") } v := team.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (_c *TeamCreate) check() error { if _, ok := _c.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`db: missing required field "Team.name"`)} } if v, ok := _c.mutation.Name(); ok { if err := team.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Team.name": %w`, err)} } } if _, ok := _c.mutation.MemberLimit(); !ok { return &ValidationError{Name: "member_limit", err: errors.New(`db: missing required field "Team.member_limit"`)} } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "Team.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "Team.updated_at"`)} } return nil } func (_c *TeamCreate) sqlSave(ctx context.Context) (*Team, 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 *TeamCreate) createSpec() (*Team, *sqlgraph.CreateSpec) { var ( _node = &Team{config: _c.config} _spec = sqlgraph.NewCreateSpec(team.Table, sqlgraph.NewFieldSpec(team.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(team.FieldDeletedAt, field.TypeTime, value) _node.DeletedAt = value } if value, ok := _c.mutation.Name(); ok { _spec.SetField(team.FieldName, field.TypeString, value) _node.Name = value } if value, ok := _c.mutation.MemberLimit(); ok { _spec.SetField(team.FieldMemberLimit, field.TypeInt, value) _node.MemberLimit = value } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(team.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(team.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if nodes := _c.mutation.GroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: team.GroupsTable, Columns: []string{team.GroupsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(teamgroup.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.MembersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: team.MembersTable, Columns: team.MembersPrimaryKey, 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 := &TeamMemberCreate{config: _c.config, mutation: newTeamMemberMutation(_c.config, OpCreate)} createE.defaults() _, specE := createE.createSpec() edge.Target.Fields = specE.Fields _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.ModelsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: team.ModelsTable, Columns: team.ModelsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } createE := &TeamModelCreate{config: _c.config, mutation: newTeamModelMutation(_c.config, OpCreate)} createE.defaults() _, specE := createE.createSpec() edge.Target.Fields = specE.Fields _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.ImagesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: team.ImagesTable, Columns: team.ImagesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(image.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } createE := &TeamImageCreate{config: _c.config, mutation: newTeamImageMutation(_c.config, OpCreate)} createE.defaults() _, specE := createE.createSpec() edge.Target.Fields = specE.Fields _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.TeamMembersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: team.TeamMembersTable, Columns: []string{team.TeamMembersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(teammember.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.TeamModelsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: team.TeamModelsTable, Columns: []string{team.TeamModelsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(teammodel.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.TeamImagesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: team.TeamImagesTable, Columns: []string{team.TeamImagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(teamimage.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.Team.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.TeamUpsert) { // SetDeletedAt(v+v). // }). // Exec(ctx) func (_c *TeamCreate) OnConflict(opts ...sql.ConflictOption) *TeamUpsertOne { _c.conflict = opts return &TeamUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.Team.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *TeamCreate) OnConflictColumns(columns ...string) *TeamUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &TeamUpsertOne{ create: _c, } } type ( // TeamUpsertOne is the builder for "upsert"-ing // one Team node. TeamUpsertOne struct { create *TeamCreate } // TeamUpsert is the "OnConflict" setter. TeamUpsert struct { *sql.UpdateSet } ) // SetDeletedAt sets the "deleted_at" field. func (u *TeamUpsert) SetDeletedAt(v time.Time) *TeamUpsert { u.Set(team.FieldDeletedAt, v) return u } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *TeamUpsert) UpdateDeletedAt() *TeamUpsert { u.SetExcluded(team.FieldDeletedAt) return u } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *TeamUpsert) ClearDeletedAt() *TeamUpsert { u.SetNull(team.FieldDeletedAt) return u } // SetName sets the "name" field. func (u *TeamUpsert) SetName(v string) *TeamUpsert { u.Set(team.FieldName, v) return u } // UpdateName sets the "name" field to the value that was provided on create. func (u *TeamUpsert) UpdateName() *TeamUpsert { u.SetExcluded(team.FieldName) return u } // SetMemberLimit sets the "member_limit" field. func (u *TeamUpsert) SetMemberLimit(v int) *TeamUpsert { u.Set(team.FieldMemberLimit, v) return u } // UpdateMemberLimit sets the "member_limit" field to the value that was provided on create. func (u *TeamUpsert) UpdateMemberLimit() *TeamUpsert { u.SetExcluded(team.FieldMemberLimit) return u } // AddMemberLimit adds v to the "member_limit" field. func (u *TeamUpsert) AddMemberLimit(v int) *TeamUpsert { u.Add(team.FieldMemberLimit, v) return u } // SetCreatedAt sets the "created_at" field. func (u *TeamUpsert) SetCreatedAt(v time.Time) *TeamUpsert { u.Set(team.FieldCreatedAt, v) return u } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *TeamUpsert) UpdateCreatedAt() *TeamUpsert { u.SetExcluded(team.FieldCreatedAt) return u } // SetUpdatedAt sets the "updated_at" field. func (u *TeamUpsert) SetUpdatedAt(v time.Time) *TeamUpsert { u.Set(team.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *TeamUpsert) UpdateUpdatedAt() *TeamUpsert { u.SetExcluded(team.FieldUpdatedAt) 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.Team.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(team.FieldID) // }), // ). // Exec(ctx) func (u *TeamUpsertOne) UpdateNewValues() *TeamUpsertOne { 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(team.FieldID) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.Team.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *TeamUpsertOne) Ignore() *TeamUpsertOne { 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 *TeamUpsertOne) DoNothing() *TeamUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the TeamCreate.OnConflict // documentation for more info. func (u *TeamUpsertOne) Update(set func(*TeamUpsert)) *TeamUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&TeamUpsert{UpdateSet: update}) })) return u } // SetDeletedAt sets the "deleted_at" field. func (u *TeamUpsertOne) SetDeletedAt(v time.Time) *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *TeamUpsertOne) UpdateDeletedAt() *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *TeamUpsertOne) ClearDeletedAt() *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.ClearDeletedAt() }) } // SetName sets the "name" field. func (u *TeamUpsertOne) SetName(v string) *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *TeamUpsertOne) UpdateName() *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.UpdateName() }) } // SetMemberLimit sets the "member_limit" field. func (u *TeamUpsertOne) SetMemberLimit(v int) *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.SetMemberLimit(v) }) } // AddMemberLimit adds v to the "member_limit" field. func (u *TeamUpsertOne) AddMemberLimit(v int) *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.AddMemberLimit(v) }) } // UpdateMemberLimit sets the "member_limit" field to the value that was provided on create. func (u *TeamUpsertOne) UpdateMemberLimit() *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.UpdateMemberLimit() }) } // SetCreatedAt sets the "created_at" field. func (u *TeamUpsertOne) SetCreatedAt(v time.Time) *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *TeamUpsertOne) UpdateCreatedAt() *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.UpdateCreatedAt() }) } // SetUpdatedAt sets the "updated_at" field. func (u *TeamUpsertOne) SetUpdatedAt(v time.Time) *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *TeamUpsertOne) UpdateUpdatedAt() *TeamUpsertOne { return u.Update(func(s *TeamUpsert) { s.UpdateUpdatedAt() }) } // Exec executes the query. func (u *TeamUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("db: missing options for TeamCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *TeamUpsertOne) 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 *TeamUpsertOne) 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: TeamUpsertOne.ID is not supported by MySQL driver. Use TeamUpsertOne.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 *TeamUpsertOne) IDX(ctx context.Context) uuid.UUID { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // TeamCreateBulk is the builder for creating many Team entities in bulk. type TeamCreateBulk struct { config err error builders []*TeamCreate conflict []sql.ConflictOption } // Save creates the Team entities in the database. func (_c *TeamCreateBulk) Save(ctx context.Context) ([]*Team, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*Team, 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.(*TeamMutation) 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 *TeamCreateBulk) SaveX(ctx context.Context) []*Team { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *TeamCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *TeamCreateBulk) 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.Team.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.TeamUpsert) { // SetDeletedAt(v+v). // }). // Exec(ctx) func (_c *TeamCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamUpsertBulk { _c.conflict = opts return &TeamUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.Team.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *TeamCreateBulk) OnConflictColumns(columns ...string) *TeamUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &TeamUpsertBulk{ create: _c, } } // TeamUpsertBulk is the builder for "upsert"-ing // a bulk of Team nodes. type TeamUpsertBulk struct { create *TeamCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.Team.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(team.FieldID) // }), // ). // Exec(ctx) func (u *TeamUpsertBulk) UpdateNewValues() *TeamUpsertBulk { 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(team.FieldID) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.Team.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *TeamUpsertBulk) Ignore() *TeamUpsertBulk { 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 *TeamUpsertBulk) DoNothing() *TeamUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the TeamCreateBulk.OnConflict // documentation for more info. func (u *TeamUpsertBulk) Update(set func(*TeamUpsert)) *TeamUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&TeamUpsert{UpdateSet: update}) })) return u } // SetDeletedAt sets the "deleted_at" field. func (u *TeamUpsertBulk) SetDeletedAt(v time.Time) *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *TeamUpsertBulk) UpdateDeletedAt() *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *TeamUpsertBulk) ClearDeletedAt() *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.ClearDeletedAt() }) } // SetName sets the "name" field. func (u *TeamUpsertBulk) SetName(v string) *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *TeamUpsertBulk) UpdateName() *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.UpdateName() }) } // SetMemberLimit sets the "member_limit" field. func (u *TeamUpsertBulk) SetMemberLimit(v int) *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.SetMemberLimit(v) }) } // AddMemberLimit adds v to the "member_limit" field. func (u *TeamUpsertBulk) AddMemberLimit(v int) *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.AddMemberLimit(v) }) } // UpdateMemberLimit sets the "member_limit" field to the value that was provided on create. func (u *TeamUpsertBulk) UpdateMemberLimit() *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.UpdateMemberLimit() }) } // SetCreatedAt sets the "created_at" field. func (u *TeamUpsertBulk) SetCreatedAt(v time.Time) *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *TeamUpsertBulk) UpdateCreatedAt() *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.UpdateCreatedAt() }) } // SetUpdatedAt sets the "updated_at" field. func (u *TeamUpsertBulk) SetUpdatedAt(v time.Time) *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *TeamUpsertBulk) UpdateUpdatedAt() *TeamUpsertBulk { return u.Update(func(s *TeamUpsert) { s.UpdateUpdatedAt() }) } // Exec executes the query. func (u *TeamUpsertBulk) 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 TeamCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("db: missing options for TeamCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *TeamUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }