// 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/host" "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/teamgrouphost" "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) // TeamGroupCreate is the builder for creating a TeamGroup entity. type TeamGroupCreate struct { config mutation *TeamGroupMutation hooks []Hook conflict []sql.ConflictOption } // SetDeletedAt sets the "deleted_at" field. func (_c *TeamGroupCreate) SetDeletedAt(v time.Time) *TeamGroupCreate { _c.mutation.SetDeletedAt(v) return _c } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_c *TeamGroupCreate) SetNillableDeletedAt(v *time.Time) *TeamGroupCreate { if v != nil { _c.SetDeletedAt(*v) } return _c } // SetTeamID sets the "team_id" field. func (_c *TeamGroupCreate) SetTeamID(v uuid.UUID) *TeamGroupCreate { _c.mutation.SetTeamID(v) return _c } // SetName sets the "name" field. func (_c *TeamGroupCreate) SetName(v string) *TeamGroupCreate { _c.mutation.SetName(v) return _c } // SetCreatedAt sets the "created_at" field. func (_c *TeamGroupCreate) SetCreatedAt(v time.Time) *TeamGroupCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *TeamGroupCreate) SetNillableCreatedAt(v *time.Time) *TeamGroupCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *TeamGroupCreate) SetUpdatedAt(v time.Time) *TeamGroupCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *TeamGroupCreate) SetNillableUpdatedAt(v *time.Time) *TeamGroupCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetID sets the "id" field. func (_c *TeamGroupCreate) SetID(v uuid.UUID) *TeamGroupCreate { _c.mutation.SetID(v) return _c } // AddMemberIDs adds the "members" edge to the User entity by IDs. func (_c *TeamGroupCreate) AddMemberIDs(ids ...uuid.UUID) *TeamGroupCreate { _c.mutation.AddMemberIDs(ids...) return _c } // AddMembers adds the "members" edges to the User entity. func (_c *TeamGroupCreate) AddMembers(v ...*User) *TeamGroupCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddMemberIDs(ids...) } // SetTeam sets the "team" edge to the Team entity. func (_c *TeamGroupCreate) SetTeam(v *Team) *TeamGroupCreate { return _c.SetTeamID(v.ID) } // AddModelIDs adds the "models" edge to the Model entity by IDs. func (_c *TeamGroupCreate) AddModelIDs(ids ...uuid.UUID) *TeamGroupCreate { _c.mutation.AddModelIDs(ids...) return _c } // AddModels adds the "models" edges to the Model entity. func (_c *TeamGroupCreate) AddModels(v ...*Model) *TeamGroupCreate { 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 *TeamGroupCreate) AddImageIDs(ids ...uuid.UUID) *TeamGroupCreate { _c.mutation.AddImageIDs(ids...) return _c } // AddImages adds the "images" edges to the Image entity. func (_c *TeamGroupCreate) AddImages(v ...*Image) *TeamGroupCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddImageIDs(ids...) } // AddHostIDs adds the "hosts" edge to the Host entity by IDs. func (_c *TeamGroupCreate) AddHostIDs(ids ...string) *TeamGroupCreate { _c.mutation.AddHostIDs(ids...) return _c } // AddHosts adds the "hosts" edges to the Host entity. func (_c *TeamGroupCreate) AddHosts(v ...*Host) *TeamGroupCreate { ids := make([]string, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddHostIDs(ids...) } // AddTeamGroupMemberIDs adds the "team_group_members" edge to the TeamGroupMember entity by IDs. func (_c *TeamGroupCreate) AddTeamGroupMemberIDs(ids ...uuid.UUID) *TeamGroupCreate { _c.mutation.AddTeamGroupMemberIDs(ids...) return _c } // AddTeamGroupMembers adds the "team_group_members" edges to the TeamGroupMember entity. func (_c *TeamGroupCreate) AddTeamGroupMembers(v ...*TeamGroupMember) *TeamGroupCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddTeamGroupMemberIDs(ids...) } // AddTeamGroupModelIDs adds the "team_group_models" edge to the TeamGroupModel entity by IDs. func (_c *TeamGroupCreate) AddTeamGroupModelIDs(ids ...uuid.UUID) *TeamGroupCreate { _c.mutation.AddTeamGroupModelIDs(ids...) return _c } // AddTeamGroupModels adds the "team_group_models" edges to the TeamGroupModel entity. func (_c *TeamGroupCreate) AddTeamGroupModels(v ...*TeamGroupModel) *TeamGroupCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddTeamGroupModelIDs(ids...) } // AddTeamGroupImageIDs adds the "team_group_images" edge to the TeamGroupImage entity by IDs. func (_c *TeamGroupCreate) AddTeamGroupImageIDs(ids ...uuid.UUID) *TeamGroupCreate { _c.mutation.AddTeamGroupImageIDs(ids...) return _c } // AddTeamGroupImages adds the "team_group_images" edges to the TeamGroupImage entity. func (_c *TeamGroupCreate) AddTeamGroupImages(v ...*TeamGroupImage) *TeamGroupCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddTeamGroupImageIDs(ids...) } // AddTeamGroupHostIDs adds the "team_group_hosts" edge to the TeamGroupHost entity by IDs. func (_c *TeamGroupCreate) AddTeamGroupHostIDs(ids ...uuid.UUID) *TeamGroupCreate { _c.mutation.AddTeamGroupHostIDs(ids...) return _c } // AddTeamGroupHosts adds the "team_group_hosts" edges to the TeamGroupHost entity. func (_c *TeamGroupCreate) AddTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddTeamGroupHostIDs(ids...) } // Mutation returns the TeamGroupMutation object of the builder. func (_c *TeamGroupCreate) Mutation() *TeamGroupMutation { return _c.mutation } // Save creates the TeamGroup in the database. func (_c *TeamGroupCreate) Save(ctx context.Context) (*TeamGroup, 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 *TeamGroupCreate) SaveX(ctx context.Context) *TeamGroup { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *TeamGroupCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *TeamGroupCreate) 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 *TeamGroupCreate) defaults() error { if _, ok := _c.mutation.CreatedAt(); !ok { if teamgroup.DefaultCreatedAt == nil { return fmt.Errorf("db: uninitialized teamgroup.DefaultCreatedAt (forgotten import db/runtime?)") } v := teamgroup.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { if teamgroup.DefaultUpdatedAt == nil { return fmt.Errorf("db: uninitialized teamgroup.DefaultUpdatedAt (forgotten import db/runtime?)") } v := teamgroup.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (_c *TeamGroupCreate) check() error { if _, ok := _c.mutation.TeamID(); !ok { return &ValidationError{Name: "team_id", err: errors.New(`db: missing required field "TeamGroup.team_id"`)} } if _, ok := _c.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`db: missing required field "TeamGroup.name"`)} } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "TeamGroup.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "TeamGroup.updated_at"`)} } if len(_c.mutation.TeamIDs()) == 0 { return &ValidationError{Name: "team", err: errors.New(`db: missing required edge "TeamGroup.team"`)} } return nil } func (_c *TeamGroupCreate) sqlSave(ctx context.Context) (*TeamGroup, 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 *TeamGroupCreate) createSpec() (*TeamGroup, *sqlgraph.CreateSpec) { var ( _node = &TeamGroup{config: _c.config} _spec = sqlgraph.NewCreateSpec(teamgroup.Table, sqlgraph.NewFieldSpec(teamgroup.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(teamgroup.FieldDeletedAt, field.TypeTime, value) _node.DeletedAt = value } if value, ok := _c.mutation.Name(); ok { _spec.SetField(teamgroup.FieldName, field.TypeString, value) _node.Name = value } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(teamgroup.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(teamgroup.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if nodes := _c.mutation.MembersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: teamgroup.MembersTable, Columns: teamgroup.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 := &TeamGroupMemberCreate{config: _c.config, mutation: newTeamGroupMemberMutation(_c.config, OpCreate)} createE.defaults() _, specE := createE.createSpec() edge.Target.Fields = specE.Fields _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.TeamIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: teamgroup.TeamTable, Columns: []string{teamgroup.TeamColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.TeamID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.ModelsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: teamgroup.ModelsTable, Columns: teamgroup.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 := &TeamGroupModelCreate{config: _c.config, mutation: newTeamGroupModelMutation(_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: teamgroup.ImagesTable, Columns: teamgroup.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 := &TeamGroupImageCreate{config: _c.config, mutation: newTeamGroupImageMutation(_c.config, OpCreate)} createE.defaults() _, specE := createE.createSpec() edge.Target.Fields = specE.Fields _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.HostsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: teamgroup.HostsTable, Columns: teamgroup.HostsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(host.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } createE := &TeamGroupHostCreate{config: _c.config, mutation: newTeamGroupHostMutation(_c.config, OpCreate)} createE.defaults() _, specE := createE.createSpec() edge.Target.Fields = specE.Fields _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.TeamGroupMembersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: teamgroup.TeamGroupMembersTable, Columns: []string{teamgroup.TeamGroupMembersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(teamgroupmember.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.TeamGroupModelsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: teamgroup.TeamGroupModelsTable, Columns: []string{teamgroup.TeamGroupModelsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(teamgroupmodel.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.TeamGroupImagesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: teamgroup.TeamGroupImagesTable, Columns: []string{teamgroup.TeamGroupImagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(teamgroupimage.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.TeamGroupHostsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: teamgroup.TeamGroupHostsTable, Columns: []string{teamgroup.TeamGroupHostsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(teamgrouphost.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.TeamGroup.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.TeamGroupUpsert) { // SetDeletedAt(v+v). // }). // Exec(ctx) func (_c *TeamGroupCreate) OnConflict(opts ...sql.ConflictOption) *TeamGroupUpsertOne { _c.conflict = opts return &TeamGroupUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.TeamGroup.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *TeamGroupCreate) OnConflictColumns(columns ...string) *TeamGroupUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &TeamGroupUpsertOne{ create: _c, } } type ( // TeamGroupUpsertOne is the builder for "upsert"-ing // one TeamGroup node. TeamGroupUpsertOne struct { create *TeamGroupCreate } // TeamGroupUpsert is the "OnConflict" setter. TeamGroupUpsert struct { *sql.UpdateSet } ) // SetDeletedAt sets the "deleted_at" field. func (u *TeamGroupUpsert) SetDeletedAt(v time.Time) *TeamGroupUpsert { u.Set(teamgroup.FieldDeletedAt, v) return u } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *TeamGroupUpsert) UpdateDeletedAt() *TeamGroupUpsert { u.SetExcluded(teamgroup.FieldDeletedAt) return u } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *TeamGroupUpsert) ClearDeletedAt() *TeamGroupUpsert { u.SetNull(teamgroup.FieldDeletedAt) return u } // SetTeamID sets the "team_id" field. func (u *TeamGroupUpsert) SetTeamID(v uuid.UUID) *TeamGroupUpsert { u.Set(teamgroup.FieldTeamID, v) return u } // UpdateTeamID sets the "team_id" field to the value that was provided on create. func (u *TeamGroupUpsert) UpdateTeamID() *TeamGroupUpsert { u.SetExcluded(teamgroup.FieldTeamID) return u } // SetName sets the "name" field. func (u *TeamGroupUpsert) SetName(v string) *TeamGroupUpsert { u.Set(teamgroup.FieldName, v) return u } // UpdateName sets the "name" field to the value that was provided on create. func (u *TeamGroupUpsert) UpdateName() *TeamGroupUpsert { u.SetExcluded(teamgroup.FieldName) return u } // SetCreatedAt sets the "created_at" field. func (u *TeamGroupUpsert) SetCreatedAt(v time.Time) *TeamGroupUpsert { u.Set(teamgroup.FieldCreatedAt, v) return u } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *TeamGroupUpsert) UpdateCreatedAt() *TeamGroupUpsert { u.SetExcluded(teamgroup.FieldCreatedAt) return u } // SetUpdatedAt sets the "updated_at" field. func (u *TeamGroupUpsert) SetUpdatedAt(v time.Time) *TeamGroupUpsert { u.Set(teamgroup.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *TeamGroupUpsert) UpdateUpdatedAt() *TeamGroupUpsert { u.SetExcluded(teamgroup.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.TeamGroup.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(teamgroup.FieldID) // }), // ). // Exec(ctx) func (u *TeamGroupUpsertOne) UpdateNewValues() *TeamGroupUpsertOne { 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(teamgroup.FieldID) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.TeamGroup.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *TeamGroupUpsertOne) Ignore() *TeamGroupUpsertOne { 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 *TeamGroupUpsertOne) DoNothing() *TeamGroupUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the TeamGroupCreate.OnConflict // documentation for more info. func (u *TeamGroupUpsertOne) Update(set func(*TeamGroupUpsert)) *TeamGroupUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&TeamGroupUpsert{UpdateSet: update}) })) return u } // SetDeletedAt sets the "deleted_at" field. func (u *TeamGroupUpsertOne) SetDeletedAt(v time.Time) *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *TeamGroupUpsertOne) UpdateDeletedAt() *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *TeamGroupUpsertOne) ClearDeletedAt() *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.ClearDeletedAt() }) } // SetTeamID sets the "team_id" field. func (u *TeamGroupUpsertOne) SetTeamID(v uuid.UUID) *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.SetTeamID(v) }) } // UpdateTeamID sets the "team_id" field to the value that was provided on create. func (u *TeamGroupUpsertOne) UpdateTeamID() *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.UpdateTeamID() }) } // SetName sets the "name" field. func (u *TeamGroupUpsertOne) SetName(v string) *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *TeamGroupUpsertOne) UpdateName() *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.UpdateName() }) } // SetCreatedAt sets the "created_at" field. func (u *TeamGroupUpsertOne) SetCreatedAt(v time.Time) *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *TeamGroupUpsertOne) UpdateCreatedAt() *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.UpdateCreatedAt() }) } // SetUpdatedAt sets the "updated_at" field. func (u *TeamGroupUpsertOne) SetUpdatedAt(v time.Time) *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *TeamGroupUpsertOne) UpdateUpdatedAt() *TeamGroupUpsertOne { return u.Update(func(s *TeamGroupUpsert) { s.UpdateUpdatedAt() }) } // Exec executes the query. func (u *TeamGroupUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("db: missing options for TeamGroupCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *TeamGroupUpsertOne) 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 *TeamGroupUpsertOne) 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: TeamGroupUpsertOne.ID is not supported by MySQL driver. Use TeamGroupUpsertOne.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 *TeamGroupUpsertOne) IDX(ctx context.Context) uuid.UUID { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // TeamGroupCreateBulk is the builder for creating many TeamGroup entities in bulk. type TeamGroupCreateBulk struct { config err error builders []*TeamGroupCreate conflict []sql.ConflictOption } // Save creates the TeamGroup entities in the database. func (_c *TeamGroupCreateBulk) Save(ctx context.Context) ([]*TeamGroup, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*TeamGroup, 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.(*TeamGroupMutation) 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 *TeamGroupCreateBulk) SaveX(ctx context.Context) []*TeamGroup { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *TeamGroupCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *TeamGroupCreateBulk) 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.TeamGroup.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.TeamGroupUpsert) { // SetDeletedAt(v+v). // }). // Exec(ctx) func (_c *TeamGroupCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamGroupUpsertBulk { _c.conflict = opts return &TeamGroupUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.TeamGroup.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *TeamGroupCreateBulk) OnConflictColumns(columns ...string) *TeamGroupUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &TeamGroupUpsertBulk{ create: _c, } } // TeamGroupUpsertBulk is the builder for "upsert"-ing // a bulk of TeamGroup nodes. type TeamGroupUpsertBulk struct { create *TeamGroupCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.TeamGroup.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(teamgroup.FieldID) // }), // ). // Exec(ctx) func (u *TeamGroupUpsertBulk) UpdateNewValues() *TeamGroupUpsertBulk { 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(teamgroup.FieldID) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.TeamGroup.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *TeamGroupUpsertBulk) Ignore() *TeamGroupUpsertBulk { 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 *TeamGroupUpsertBulk) DoNothing() *TeamGroupUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the TeamGroupCreateBulk.OnConflict // documentation for more info. func (u *TeamGroupUpsertBulk) Update(set func(*TeamGroupUpsert)) *TeamGroupUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&TeamGroupUpsert{UpdateSet: update}) })) return u } // SetDeletedAt sets the "deleted_at" field. func (u *TeamGroupUpsertBulk) SetDeletedAt(v time.Time) *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *TeamGroupUpsertBulk) UpdateDeletedAt() *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *TeamGroupUpsertBulk) ClearDeletedAt() *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.ClearDeletedAt() }) } // SetTeamID sets the "team_id" field. func (u *TeamGroupUpsertBulk) SetTeamID(v uuid.UUID) *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.SetTeamID(v) }) } // UpdateTeamID sets the "team_id" field to the value that was provided on create. func (u *TeamGroupUpsertBulk) UpdateTeamID() *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.UpdateTeamID() }) } // SetName sets the "name" field. func (u *TeamGroupUpsertBulk) SetName(v string) *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *TeamGroupUpsertBulk) UpdateName() *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.UpdateName() }) } // SetCreatedAt sets the "created_at" field. func (u *TeamGroupUpsertBulk) SetCreatedAt(v time.Time) *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *TeamGroupUpsertBulk) UpdateCreatedAt() *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.UpdateCreatedAt() }) } // SetUpdatedAt sets the "updated_at" field. func (u *TeamGroupUpsertBulk) SetUpdatedAt(v time.Time) *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *TeamGroupUpsertBulk) UpdateUpdatedAt() *TeamGroupUpsertBulk { return u.Update(func(s *TeamGroupUpsert) { s.UpdateUpdatedAt() }) } // Exec executes the query. func (u *TeamGroupUpsertBulk) 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 TeamGroupCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("db: missing options for TeamGroupCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *TeamGroupUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }