// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "wechat-api/ent/sopstage" "wechat-api/ent/soptask" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // SopTaskCreate is the builder for creating a SopTask entity. type SopTaskCreate struct { config mutation *SopTaskMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (stc *SopTaskCreate) SetCreatedAt(t time.Time) *SopTaskCreate { stc.mutation.SetCreatedAt(t) return stc } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (stc *SopTaskCreate) SetNillableCreatedAt(t *time.Time) *SopTaskCreate { if t != nil { stc.SetCreatedAt(*t) } return stc } // SetUpdatedAt sets the "updated_at" field. func (stc *SopTaskCreate) SetUpdatedAt(t time.Time) *SopTaskCreate { stc.mutation.SetUpdatedAt(t) return stc } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (stc *SopTaskCreate) SetNillableUpdatedAt(t *time.Time) *SopTaskCreate { if t != nil { stc.SetUpdatedAt(*t) } return stc } // SetStatus sets the "status" field. func (stc *SopTaskCreate) SetStatus(u uint8) *SopTaskCreate { stc.mutation.SetStatus(u) return stc } // SetNillableStatus sets the "status" field if the given value is not nil. func (stc *SopTaskCreate) SetNillableStatus(u *uint8) *SopTaskCreate { if u != nil { stc.SetStatus(*u) } return stc } // SetDeletedAt sets the "deleted_at" field. func (stc *SopTaskCreate) SetDeletedAt(t time.Time) *SopTaskCreate { stc.mutation.SetDeletedAt(t) return stc } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (stc *SopTaskCreate) SetNillableDeletedAt(t *time.Time) *SopTaskCreate { if t != nil { stc.SetDeletedAt(*t) } return stc } // SetName sets the "name" field. func (stc *SopTaskCreate) SetName(s string) *SopTaskCreate { stc.mutation.SetName(s) return stc } // SetBotWxidList sets the "bot_wxid_list" field. func (stc *SopTaskCreate) SetBotWxidList(s []string) *SopTaskCreate { stc.mutation.SetBotWxidList(s) return stc } // SetType sets the "type" field. func (stc *SopTaskCreate) SetType(i int) *SopTaskCreate { stc.mutation.SetType(i) return stc } // SetNillableType sets the "type" field if the given value is not nil. func (stc *SopTaskCreate) SetNillableType(i *int) *SopTaskCreate { if i != nil { stc.SetType(*i) } return stc } // SetPlanStartTime sets the "plan_start_time" field. func (stc *SopTaskCreate) SetPlanStartTime(t time.Time) *SopTaskCreate { stc.mutation.SetPlanStartTime(t) return stc } // SetNillablePlanStartTime sets the "plan_start_time" field if the given value is not nil. func (stc *SopTaskCreate) SetNillablePlanStartTime(t *time.Time) *SopTaskCreate { if t != nil { stc.SetPlanStartTime(*t) } return stc } // SetPlanEndTime sets the "plan_end_time" field. func (stc *SopTaskCreate) SetPlanEndTime(t time.Time) *SopTaskCreate { stc.mutation.SetPlanEndTime(t) return stc } // SetNillablePlanEndTime sets the "plan_end_time" field if the given value is not nil. func (stc *SopTaskCreate) SetNillablePlanEndTime(t *time.Time) *SopTaskCreate { if t != nil { stc.SetPlanEndTime(*t) } return stc } // SetCreatorID sets the "creator_id" field. func (stc *SopTaskCreate) SetCreatorID(s string) *SopTaskCreate { stc.mutation.SetCreatorID(s) return stc } // SetNillableCreatorID sets the "creator_id" field if the given value is not nil. func (stc *SopTaskCreate) SetNillableCreatorID(s *string) *SopTaskCreate { if s != nil { stc.SetCreatorID(*s) } return stc } // SetOrganizationID sets the "organization_id" field. func (stc *SopTaskCreate) SetOrganizationID(u uint64) *SopTaskCreate { stc.mutation.SetOrganizationID(u) return stc } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (stc *SopTaskCreate) SetNillableOrganizationID(u *uint64) *SopTaskCreate { if u != nil { stc.SetOrganizationID(*u) } return stc } // SetToken sets the "token" field. func (stc *SopTaskCreate) SetToken(s []string) *SopTaskCreate { stc.mutation.SetToken(s) return stc } // SetID sets the "id" field. func (stc *SopTaskCreate) SetID(u uint64) *SopTaskCreate { stc.mutation.SetID(u) return stc } // AddTaskStageIDs adds the "task_stages" edge to the SopStage entity by IDs. func (stc *SopTaskCreate) AddTaskStageIDs(ids ...uint64) *SopTaskCreate { stc.mutation.AddTaskStageIDs(ids...) return stc } // AddTaskStages adds the "task_stages" edges to the SopStage entity. func (stc *SopTaskCreate) AddTaskStages(s ...*SopStage) *SopTaskCreate { ids := make([]uint64, len(s)) for i := range s { ids[i] = s[i].ID } return stc.AddTaskStageIDs(ids...) } // Mutation returns the SopTaskMutation object of the builder. func (stc *SopTaskCreate) Mutation() *SopTaskMutation { return stc.mutation } // Save creates the SopTask in the database. func (stc *SopTaskCreate) Save(ctx context.Context) (*SopTask, error) { if err := stc.defaults(); err != nil { return nil, err } return withHooks(ctx, stc.sqlSave, stc.mutation, stc.hooks) } // SaveX calls Save and panics if Save returns an error. func (stc *SopTaskCreate) SaveX(ctx context.Context) *SopTask { v, err := stc.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (stc *SopTaskCreate) Exec(ctx context.Context) error { _, err := stc.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (stc *SopTaskCreate) ExecX(ctx context.Context) { if err := stc.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (stc *SopTaskCreate) defaults() error { if _, ok := stc.mutation.CreatedAt(); !ok { if soptask.DefaultCreatedAt == nil { return fmt.Errorf("ent: uninitialized soptask.DefaultCreatedAt (forgotten import ent/runtime?)") } v := soptask.DefaultCreatedAt() stc.mutation.SetCreatedAt(v) } if _, ok := stc.mutation.UpdatedAt(); !ok { if soptask.DefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized soptask.DefaultUpdatedAt (forgotten import ent/runtime?)") } v := soptask.DefaultUpdatedAt() stc.mutation.SetUpdatedAt(v) } if _, ok := stc.mutation.Status(); !ok { v := soptask.DefaultStatus stc.mutation.SetStatus(v) } if _, ok := stc.mutation.GetType(); !ok { v := soptask.DefaultType stc.mutation.SetType(v) } if _, ok := stc.mutation.OrganizationID(); !ok { v := soptask.DefaultOrganizationID stc.mutation.SetOrganizationID(v) } return nil } // check runs all checks and user-defined validators on the builder. func (stc *SopTaskCreate) check() error { if _, ok := stc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SopTask.created_at"`)} } if _, ok := stc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SopTask.updated_at"`)} } if _, ok := stc.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "SopTask.name"`)} } if v, ok := stc.mutation.Name(); ok { if err := soptask.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "SopTask.name": %w`, err)} } } if _, ok := stc.mutation.GetType(); !ok { return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "SopTask.type"`)} } return nil } func (stc *SopTaskCreate) sqlSave(ctx context.Context) (*SopTask, error) { if err := stc.check(); err != nil { return nil, err } _node, _spec := stc.createSpec() if err := sqlgraph.CreateNode(ctx, stc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } if _spec.ID.Value != _node.ID { id := _spec.ID.Value.(int64) _node.ID = uint64(id) } stc.mutation.id = &_node.ID stc.mutation.done = true return _node, nil } func (stc *SopTaskCreate) createSpec() (*SopTask, *sqlgraph.CreateSpec) { var ( _node = &SopTask{config: stc.config} _spec = sqlgraph.NewCreateSpec(soptask.Table, sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64)) ) _spec.OnConflict = stc.conflict if id, ok := stc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := stc.mutation.CreatedAt(); ok { _spec.SetField(soptask.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := stc.mutation.UpdatedAt(); ok { _spec.SetField(soptask.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := stc.mutation.Status(); ok { _spec.SetField(soptask.FieldStatus, field.TypeUint8, value) _node.Status = value } if value, ok := stc.mutation.DeletedAt(); ok { _spec.SetField(soptask.FieldDeletedAt, field.TypeTime, value) _node.DeletedAt = value } if value, ok := stc.mutation.Name(); ok { _spec.SetField(soptask.FieldName, field.TypeString, value) _node.Name = value } if value, ok := stc.mutation.BotWxidList(); ok { _spec.SetField(soptask.FieldBotWxidList, field.TypeJSON, value) _node.BotWxidList = value } if value, ok := stc.mutation.GetType(); ok { _spec.SetField(soptask.FieldType, field.TypeInt, value) _node.Type = value } if value, ok := stc.mutation.PlanStartTime(); ok { _spec.SetField(soptask.FieldPlanStartTime, field.TypeTime, value) _node.PlanStartTime = value } if value, ok := stc.mutation.PlanEndTime(); ok { _spec.SetField(soptask.FieldPlanEndTime, field.TypeTime, value) _node.PlanEndTime = value } if value, ok := stc.mutation.CreatorID(); ok { _spec.SetField(soptask.FieldCreatorID, field.TypeString, value) _node.CreatorID = value } if value, ok := stc.mutation.OrganizationID(); ok { _spec.SetField(soptask.FieldOrganizationID, field.TypeUint64, value) _node.OrganizationID = value } if value, ok := stc.mutation.Token(); ok { _spec.SetField(soptask.FieldToken, field.TypeJSON, value) _node.Token = value } if nodes := stc.mutation.TaskStagesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: soptask.TaskStagesTable, Columns: []string{soptask.TaskStagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64), }, } 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.SopTask.Create(). // SetCreatedAt(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.SopTaskUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (stc *SopTaskCreate) OnConflict(opts ...sql.ConflictOption) *SopTaskUpsertOne { stc.conflict = opts return &SopTaskUpsertOne{ create: stc, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.SopTask.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (stc *SopTaskCreate) OnConflictColumns(columns ...string) *SopTaskUpsertOne { stc.conflict = append(stc.conflict, sql.ConflictColumns(columns...)) return &SopTaskUpsertOne{ create: stc, } } type ( // SopTaskUpsertOne is the builder for "upsert"-ing // one SopTask node. SopTaskUpsertOne struct { create *SopTaskCreate } // SopTaskUpsert is the "OnConflict" setter. SopTaskUpsert struct { *sql.UpdateSet } ) // SetUpdatedAt sets the "updated_at" field. func (u *SopTaskUpsert) SetUpdatedAt(v time.Time) *SopTaskUpsert { u.Set(soptask.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateUpdatedAt() *SopTaskUpsert { u.SetExcluded(soptask.FieldUpdatedAt) return u } // SetStatus sets the "status" field. func (u *SopTaskUpsert) SetStatus(v uint8) *SopTaskUpsert { u.Set(soptask.FieldStatus, v) return u } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateStatus() *SopTaskUpsert { u.SetExcluded(soptask.FieldStatus) return u } // AddStatus adds v to the "status" field. func (u *SopTaskUpsert) AddStatus(v uint8) *SopTaskUpsert { u.Add(soptask.FieldStatus, v) return u } // ClearStatus clears the value of the "status" field. func (u *SopTaskUpsert) ClearStatus() *SopTaskUpsert { u.SetNull(soptask.FieldStatus) return u } // SetDeletedAt sets the "deleted_at" field. func (u *SopTaskUpsert) SetDeletedAt(v time.Time) *SopTaskUpsert { u.Set(soptask.FieldDeletedAt, v) return u } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateDeletedAt() *SopTaskUpsert { u.SetExcluded(soptask.FieldDeletedAt) return u } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *SopTaskUpsert) ClearDeletedAt() *SopTaskUpsert { u.SetNull(soptask.FieldDeletedAt) return u } // SetName sets the "name" field. func (u *SopTaskUpsert) SetName(v string) *SopTaskUpsert { u.Set(soptask.FieldName, v) return u } // UpdateName sets the "name" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateName() *SopTaskUpsert { u.SetExcluded(soptask.FieldName) return u } // SetBotWxidList sets the "bot_wxid_list" field. func (u *SopTaskUpsert) SetBotWxidList(v []string) *SopTaskUpsert { u.Set(soptask.FieldBotWxidList, v) return u } // UpdateBotWxidList sets the "bot_wxid_list" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateBotWxidList() *SopTaskUpsert { u.SetExcluded(soptask.FieldBotWxidList) return u } // ClearBotWxidList clears the value of the "bot_wxid_list" field. func (u *SopTaskUpsert) ClearBotWxidList() *SopTaskUpsert { u.SetNull(soptask.FieldBotWxidList) return u } // SetType sets the "type" field. func (u *SopTaskUpsert) SetType(v int) *SopTaskUpsert { u.Set(soptask.FieldType, v) return u } // UpdateType sets the "type" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateType() *SopTaskUpsert { u.SetExcluded(soptask.FieldType) return u } // AddType adds v to the "type" field. func (u *SopTaskUpsert) AddType(v int) *SopTaskUpsert { u.Add(soptask.FieldType, v) return u } // SetPlanStartTime sets the "plan_start_time" field. func (u *SopTaskUpsert) SetPlanStartTime(v time.Time) *SopTaskUpsert { u.Set(soptask.FieldPlanStartTime, v) return u } // UpdatePlanStartTime sets the "plan_start_time" field to the value that was provided on create. func (u *SopTaskUpsert) UpdatePlanStartTime() *SopTaskUpsert { u.SetExcluded(soptask.FieldPlanStartTime) return u } // ClearPlanStartTime clears the value of the "plan_start_time" field. func (u *SopTaskUpsert) ClearPlanStartTime() *SopTaskUpsert { u.SetNull(soptask.FieldPlanStartTime) return u } // SetPlanEndTime sets the "plan_end_time" field. func (u *SopTaskUpsert) SetPlanEndTime(v time.Time) *SopTaskUpsert { u.Set(soptask.FieldPlanEndTime, v) return u } // UpdatePlanEndTime sets the "plan_end_time" field to the value that was provided on create. func (u *SopTaskUpsert) UpdatePlanEndTime() *SopTaskUpsert { u.SetExcluded(soptask.FieldPlanEndTime) return u } // ClearPlanEndTime clears the value of the "plan_end_time" field. func (u *SopTaskUpsert) ClearPlanEndTime() *SopTaskUpsert { u.SetNull(soptask.FieldPlanEndTime) return u } // SetCreatorID sets the "creator_id" field. func (u *SopTaskUpsert) SetCreatorID(v string) *SopTaskUpsert { u.Set(soptask.FieldCreatorID, v) return u } // UpdateCreatorID sets the "creator_id" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateCreatorID() *SopTaskUpsert { u.SetExcluded(soptask.FieldCreatorID) return u } // ClearCreatorID clears the value of the "creator_id" field. func (u *SopTaskUpsert) ClearCreatorID() *SopTaskUpsert { u.SetNull(soptask.FieldCreatorID) return u } // SetOrganizationID sets the "organization_id" field. func (u *SopTaskUpsert) SetOrganizationID(v uint64) *SopTaskUpsert { u.Set(soptask.FieldOrganizationID, v) return u } // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateOrganizationID() *SopTaskUpsert { u.SetExcluded(soptask.FieldOrganizationID) return u } // AddOrganizationID adds v to the "organization_id" field. func (u *SopTaskUpsert) AddOrganizationID(v uint64) *SopTaskUpsert { u.Add(soptask.FieldOrganizationID, v) return u } // ClearOrganizationID clears the value of the "organization_id" field. func (u *SopTaskUpsert) ClearOrganizationID() *SopTaskUpsert { u.SetNull(soptask.FieldOrganizationID) return u } // SetToken sets the "token" field. func (u *SopTaskUpsert) SetToken(v []string) *SopTaskUpsert { u.Set(soptask.FieldToken, v) return u } // UpdateToken sets the "token" field to the value that was provided on create. func (u *SopTaskUpsert) UpdateToken() *SopTaskUpsert { u.SetExcluded(soptask.FieldToken) return u } // ClearToken clears the value of the "token" field. func (u *SopTaskUpsert) ClearToken() *SopTaskUpsert { u.SetNull(soptask.FieldToken) 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.SopTask.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(soptask.FieldID) // }), // ). // Exec(ctx) func (u *SopTaskUpsertOne) UpdateNewValues() *SopTaskUpsertOne { 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(soptask.FieldID) } if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(soptask.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.SopTask.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SopTaskUpsertOne) Ignore() *SopTaskUpsertOne { 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 *SopTaskUpsertOne) DoNothing() *SopTaskUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SopTaskCreate.OnConflict // documentation for more info. func (u *SopTaskUpsertOne) Update(set func(*SopTaskUpsert)) *SopTaskUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SopTaskUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *SopTaskUpsertOne) SetUpdatedAt(v time.Time) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateUpdatedAt() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateUpdatedAt() }) } // SetStatus sets the "status" field. func (u *SopTaskUpsertOne) SetStatus(v uint8) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetStatus(v) }) } // AddStatus adds v to the "status" field. func (u *SopTaskUpsertOne) AddStatus(v uint8) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.AddStatus(v) }) } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateStatus() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateStatus() }) } // ClearStatus clears the value of the "status" field. func (u *SopTaskUpsertOne) ClearStatus() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.ClearStatus() }) } // SetDeletedAt sets the "deleted_at" field. func (u *SopTaskUpsertOne) SetDeletedAt(v time.Time) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateDeletedAt() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *SopTaskUpsertOne) ClearDeletedAt() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.ClearDeletedAt() }) } // SetName sets the "name" field. func (u *SopTaskUpsertOne) SetName(v string) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateName() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateName() }) } // SetBotWxidList sets the "bot_wxid_list" field. func (u *SopTaskUpsertOne) SetBotWxidList(v []string) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetBotWxidList(v) }) } // UpdateBotWxidList sets the "bot_wxid_list" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateBotWxidList() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateBotWxidList() }) } // ClearBotWxidList clears the value of the "bot_wxid_list" field. func (u *SopTaskUpsertOne) ClearBotWxidList() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.ClearBotWxidList() }) } // SetType sets the "type" field. func (u *SopTaskUpsertOne) SetType(v int) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetType(v) }) } // AddType adds v to the "type" field. func (u *SopTaskUpsertOne) AddType(v int) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.AddType(v) }) } // UpdateType sets the "type" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateType() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateType() }) } // SetPlanStartTime sets the "plan_start_time" field. func (u *SopTaskUpsertOne) SetPlanStartTime(v time.Time) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetPlanStartTime(v) }) } // UpdatePlanStartTime sets the "plan_start_time" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdatePlanStartTime() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdatePlanStartTime() }) } // ClearPlanStartTime clears the value of the "plan_start_time" field. func (u *SopTaskUpsertOne) ClearPlanStartTime() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.ClearPlanStartTime() }) } // SetPlanEndTime sets the "plan_end_time" field. func (u *SopTaskUpsertOne) SetPlanEndTime(v time.Time) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetPlanEndTime(v) }) } // UpdatePlanEndTime sets the "plan_end_time" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdatePlanEndTime() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdatePlanEndTime() }) } // ClearPlanEndTime clears the value of the "plan_end_time" field. func (u *SopTaskUpsertOne) ClearPlanEndTime() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.ClearPlanEndTime() }) } // SetCreatorID sets the "creator_id" field. func (u *SopTaskUpsertOne) SetCreatorID(v string) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetCreatorID(v) }) } // UpdateCreatorID sets the "creator_id" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateCreatorID() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateCreatorID() }) } // ClearCreatorID clears the value of the "creator_id" field. func (u *SopTaskUpsertOne) ClearCreatorID() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.ClearCreatorID() }) } // SetOrganizationID sets the "organization_id" field. func (u *SopTaskUpsertOne) SetOrganizationID(v uint64) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetOrganizationID(v) }) } // AddOrganizationID adds v to the "organization_id" field. func (u *SopTaskUpsertOne) AddOrganizationID(v uint64) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.AddOrganizationID(v) }) } // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateOrganizationID() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateOrganizationID() }) } // ClearOrganizationID clears the value of the "organization_id" field. func (u *SopTaskUpsertOne) ClearOrganizationID() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.ClearOrganizationID() }) } // SetToken sets the "token" field. func (u *SopTaskUpsertOne) SetToken(v []string) *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.SetToken(v) }) } // UpdateToken sets the "token" field to the value that was provided on create. func (u *SopTaskUpsertOne) UpdateToken() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.UpdateToken() }) } // ClearToken clears the value of the "token" field. func (u *SopTaskUpsertOne) ClearToken() *SopTaskUpsertOne { return u.Update(func(s *SopTaskUpsert) { s.ClearToken() }) } // Exec executes the query. func (u *SopTaskUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SopTaskCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SopTaskUpsertOne) 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 *SopTaskUpsertOne) ID(ctx context.Context) (id uint64, err error) { 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 *SopTaskUpsertOne) IDX(ctx context.Context) uint64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // SopTaskCreateBulk is the builder for creating many SopTask entities in bulk. type SopTaskCreateBulk struct { config err error builders []*SopTaskCreate conflict []sql.ConflictOption } // Save creates the SopTask entities in the database. func (stcb *SopTaskCreateBulk) Save(ctx context.Context) ([]*SopTask, error) { if stcb.err != nil { return nil, stcb.err } specs := make([]*sqlgraph.CreateSpec, len(stcb.builders)) nodes := make([]*SopTask, len(stcb.builders)) mutators := make([]Mutator, len(stcb.builders)) for i := range stcb.builders { func(i int, root context.Context) { builder := stcb.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*SopTaskMutation) 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, stcb.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = stcb.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, stcb.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 if specs[i].ID.Value != nil && nodes[i].ID == 0 { id := specs[i].ID.Value.(int64) nodes[i].ID = uint64(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, stcb.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (stcb *SopTaskCreateBulk) SaveX(ctx context.Context) []*SopTask { v, err := stcb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (stcb *SopTaskCreateBulk) Exec(ctx context.Context) error { _, err := stcb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (stcb *SopTaskCreateBulk) ExecX(ctx context.Context) { if err := stcb.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.SopTask.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.SopTaskUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (stcb *SopTaskCreateBulk) OnConflict(opts ...sql.ConflictOption) *SopTaskUpsertBulk { stcb.conflict = opts return &SopTaskUpsertBulk{ create: stcb, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.SopTask.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (stcb *SopTaskCreateBulk) OnConflictColumns(columns ...string) *SopTaskUpsertBulk { stcb.conflict = append(stcb.conflict, sql.ConflictColumns(columns...)) return &SopTaskUpsertBulk{ create: stcb, } } // SopTaskUpsertBulk is the builder for "upsert"-ing // a bulk of SopTask nodes. type SopTaskUpsertBulk struct { create *SopTaskCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.SopTask.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(soptask.FieldID) // }), // ). // Exec(ctx) func (u *SopTaskUpsertBulk) UpdateNewValues() *SopTaskUpsertBulk { 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(soptask.FieldID) } if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(soptask.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.SopTask.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SopTaskUpsertBulk) Ignore() *SopTaskUpsertBulk { 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 *SopTaskUpsertBulk) DoNothing() *SopTaskUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SopTaskCreateBulk.OnConflict // documentation for more info. func (u *SopTaskUpsertBulk) Update(set func(*SopTaskUpsert)) *SopTaskUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SopTaskUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *SopTaskUpsertBulk) SetUpdatedAt(v time.Time) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateUpdatedAt() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateUpdatedAt() }) } // SetStatus sets the "status" field. func (u *SopTaskUpsertBulk) SetStatus(v uint8) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetStatus(v) }) } // AddStatus adds v to the "status" field. func (u *SopTaskUpsertBulk) AddStatus(v uint8) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.AddStatus(v) }) } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateStatus() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateStatus() }) } // ClearStatus clears the value of the "status" field. func (u *SopTaskUpsertBulk) ClearStatus() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.ClearStatus() }) } // SetDeletedAt sets the "deleted_at" field. func (u *SopTaskUpsertBulk) SetDeletedAt(v time.Time) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateDeletedAt() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *SopTaskUpsertBulk) ClearDeletedAt() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.ClearDeletedAt() }) } // SetName sets the "name" field. func (u *SopTaskUpsertBulk) SetName(v string) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateName() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateName() }) } // SetBotWxidList sets the "bot_wxid_list" field. func (u *SopTaskUpsertBulk) SetBotWxidList(v []string) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetBotWxidList(v) }) } // UpdateBotWxidList sets the "bot_wxid_list" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateBotWxidList() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateBotWxidList() }) } // ClearBotWxidList clears the value of the "bot_wxid_list" field. func (u *SopTaskUpsertBulk) ClearBotWxidList() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.ClearBotWxidList() }) } // SetType sets the "type" field. func (u *SopTaskUpsertBulk) SetType(v int) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetType(v) }) } // AddType adds v to the "type" field. func (u *SopTaskUpsertBulk) AddType(v int) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.AddType(v) }) } // UpdateType sets the "type" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateType() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateType() }) } // SetPlanStartTime sets the "plan_start_time" field. func (u *SopTaskUpsertBulk) SetPlanStartTime(v time.Time) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetPlanStartTime(v) }) } // UpdatePlanStartTime sets the "plan_start_time" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdatePlanStartTime() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdatePlanStartTime() }) } // ClearPlanStartTime clears the value of the "plan_start_time" field. func (u *SopTaskUpsertBulk) ClearPlanStartTime() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.ClearPlanStartTime() }) } // SetPlanEndTime sets the "plan_end_time" field. func (u *SopTaskUpsertBulk) SetPlanEndTime(v time.Time) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetPlanEndTime(v) }) } // UpdatePlanEndTime sets the "plan_end_time" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdatePlanEndTime() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdatePlanEndTime() }) } // ClearPlanEndTime clears the value of the "plan_end_time" field. func (u *SopTaskUpsertBulk) ClearPlanEndTime() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.ClearPlanEndTime() }) } // SetCreatorID sets the "creator_id" field. func (u *SopTaskUpsertBulk) SetCreatorID(v string) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetCreatorID(v) }) } // UpdateCreatorID sets the "creator_id" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateCreatorID() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateCreatorID() }) } // ClearCreatorID clears the value of the "creator_id" field. func (u *SopTaskUpsertBulk) ClearCreatorID() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.ClearCreatorID() }) } // SetOrganizationID sets the "organization_id" field. func (u *SopTaskUpsertBulk) SetOrganizationID(v uint64) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetOrganizationID(v) }) } // AddOrganizationID adds v to the "organization_id" field. func (u *SopTaskUpsertBulk) AddOrganizationID(v uint64) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.AddOrganizationID(v) }) } // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateOrganizationID() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateOrganizationID() }) } // ClearOrganizationID clears the value of the "organization_id" field. func (u *SopTaskUpsertBulk) ClearOrganizationID() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.ClearOrganizationID() }) } // SetToken sets the "token" field. func (u *SopTaskUpsertBulk) SetToken(v []string) *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.SetToken(v) }) } // UpdateToken sets the "token" field to the value that was provided on create. func (u *SopTaskUpsertBulk) UpdateToken() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.UpdateToken() }) } // ClearToken clears the value of the "token" field. func (u *SopTaskUpsertBulk) ClearToken() *SopTaskUpsertBulk { return u.Update(func(s *SopTaskUpsert) { s.ClearToken() }) } // Exec executes the query. func (u *SopTaskUpsertBulk) 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("ent: OnConflict was set for builder %d. Set it on the SopTaskCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SopTaskCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SopTaskUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }