// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/Wei-Shaw/sub2api/ent/soratask" ) // SoraTaskCreate is the builder for creating a SoraTask entity. type SoraTaskCreate struct { config mutation *SoraTaskMutation hooks []Hook conflict []sql.ConflictOption } // SetTaskID sets the "task_id" field. func (_c *SoraTaskCreate) SetTaskID(v string) *SoraTaskCreate { _c.mutation.SetTaskID(v) return _c } // SetAccountID sets the "account_id" field. func (_c *SoraTaskCreate) SetAccountID(v int64) *SoraTaskCreate { _c.mutation.SetAccountID(v) return _c } // SetModel sets the "model" field. func (_c *SoraTaskCreate) SetModel(v string) *SoraTaskCreate { _c.mutation.SetModel(v) return _c } // SetPrompt sets the "prompt" field. func (_c *SoraTaskCreate) SetPrompt(v string) *SoraTaskCreate { _c.mutation.SetPrompt(v) return _c } // SetStatus sets the "status" field. func (_c *SoraTaskCreate) SetStatus(v string) *SoraTaskCreate { _c.mutation.SetStatus(v) return _c } // SetNillableStatus sets the "status" field if the given value is not nil. func (_c *SoraTaskCreate) SetNillableStatus(v *string) *SoraTaskCreate { if v != nil { _c.SetStatus(*v) } return _c } // SetProgress sets the "progress" field. func (_c *SoraTaskCreate) SetProgress(v float64) *SoraTaskCreate { _c.mutation.SetProgress(v) return _c } // SetNillableProgress sets the "progress" field if the given value is not nil. func (_c *SoraTaskCreate) SetNillableProgress(v *float64) *SoraTaskCreate { if v != nil { _c.SetProgress(*v) } return _c } // SetResultUrls sets the "result_urls" field. func (_c *SoraTaskCreate) SetResultUrls(v string) *SoraTaskCreate { _c.mutation.SetResultUrls(v) return _c } // SetNillableResultUrls sets the "result_urls" field if the given value is not nil. func (_c *SoraTaskCreate) SetNillableResultUrls(v *string) *SoraTaskCreate { if v != nil { _c.SetResultUrls(*v) } return _c } // SetErrorMessage sets the "error_message" field. func (_c *SoraTaskCreate) SetErrorMessage(v string) *SoraTaskCreate { _c.mutation.SetErrorMessage(v) return _c } // SetNillableErrorMessage sets the "error_message" field if the given value is not nil. func (_c *SoraTaskCreate) SetNillableErrorMessage(v *string) *SoraTaskCreate { if v != nil { _c.SetErrorMessage(*v) } return _c } // SetRetryCount sets the "retry_count" field. func (_c *SoraTaskCreate) SetRetryCount(v int) *SoraTaskCreate { _c.mutation.SetRetryCount(v) return _c } // SetNillableRetryCount sets the "retry_count" field if the given value is not nil. func (_c *SoraTaskCreate) SetNillableRetryCount(v *int) *SoraTaskCreate { if v != nil { _c.SetRetryCount(*v) } return _c } // SetCreatedAt sets the "created_at" field. func (_c *SoraTaskCreate) SetCreatedAt(v time.Time) *SoraTaskCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *SoraTaskCreate) SetNillableCreatedAt(v *time.Time) *SoraTaskCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetCompletedAt sets the "completed_at" field. func (_c *SoraTaskCreate) SetCompletedAt(v time.Time) *SoraTaskCreate { _c.mutation.SetCompletedAt(v) return _c } // SetNillableCompletedAt sets the "completed_at" field if the given value is not nil. func (_c *SoraTaskCreate) SetNillableCompletedAt(v *time.Time) *SoraTaskCreate { if v != nil { _c.SetCompletedAt(*v) } return _c } // Mutation returns the SoraTaskMutation object of the builder. func (_c *SoraTaskCreate) Mutation() *SoraTaskMutation { return _c.mutation } // Save creates the SoraTask in the database. func (_c *SoraTaskCreate) Save(ctx context.Context) (*SoraTask, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *SoraTaskCreate) SaveX(ctx context.Context) *SoraTask { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *SoraTaskCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *SoraTaskCreate) 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 *SoraTaskCreate) defaults() { if _, ok := _c.mutation.Status(); !ok { v := soratask.DefaultStatus _c.mutation.SetStatus(v) } if _, ok := _c.mutation.Progress(); !ok { v := soratask.DefaultProgress _c.mutation.SetProgress(v) } if _, ok := _c.mutation.RetryCount(); !ok { v := soratask.DefaultRetryCount _c.mutation.SetRetryCount(v) } if _, ok := _c.mutation.CreatedAt(); !ok { v := soratask.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_c *SoraTaskCreate) check() error { if _, ok := _c.mutation.TaskID(); !ok { return &ValidationError{Name: "task_id", err: errors.New(`ent: missing required field "SoraTask.task_id"`)} } if v, ok := _c.mutation.TaskID(); ok { if err := soratask.TaskIDValidator(v); err != nil { return &ValidationError{Name: "task_id", err: fmt.Errorf(`ent: validator failed for field "SoraTask.task_id": %w`, err)} } } if _, ok := _c.mutation.AccountID(); !ok { return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "SoraTask.account_id"`)} } if _, ok := _c.mutation.Model(); !ok { return &ValidationError{Name: "model", err: errors.New(`ent: missing required field "SoraTask.model"`)} } if v, ok := _c.mutation.Model(); ok { if err := soratask.ModelValidator(v); err != nil { return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "SoraTask.model": %w`, err)} } } if _, ok := _c.mutation.Prompt(); !ok { return &ValidationError{Name: "prompt", err: errors.New(`ent: missing required field "SoraTask.prompt"`)} } if _, ok := _c.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "SoraTask.status"`)} } if v, ok := _c.mutation.Status(); ok { if err := soratask.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "SoraTask.status": %w`, err)} } } if _, ok := _c.mutation.Progress(); !ok { return &ValidationError{Name: "progress", err: errors.New(`ent: missing required field "SoraTask.progress"`)} } if _, ok := _c.mutation.RetryCount(); !ok { return &ValidationError{Name: "retry_count", err: errors.New(`ent: missing required field "SoraTask.retry_count"`)} } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SoraTask.created_at"`)} } return nil } func (_c *SoraTaskCreate) sqlSave(ctx context.Context) (*SoraTask, 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 } id := _spec.ID.Value.(int64) _node.ID = int64(id) _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *SoraTaskCreate) createSpec() (*SoraTask, *sqlgraph.CreateSpec) { var ( _node = &SoraTask{config: _c.config} _spec = sqlgraph.NewCreateSpec(soratask.Table, sqlgraph.NewFieldSpec(soratask.FieldID, field.TypeInt64)) ) _spec.OnConflict = _c.conflict if value, ok := _c.mutation.TaskID(); ok { _spec.SetField(soratask.FieldTaskID, field.TypeString, value) _node.TaskID = value } if value, ok := _c.mutation.AccountID(); ok { _spec.SetField(soratask.FieldAccountID, field.TypeInt64, value) _node.AccountID = value } if value, ok := _c.mutation.Model(); ok { _spec.SetField(soratask.FieldModel, field.TypeString, value) _node.Model = value } if value, ok := _c.mutation.Prompt(); ok { _spec.SetField(soratask.FieldPrompt, field.TypeString, value) _node.Prompt = value } if value, ok := _c.mutation.Status(); ok { _spec.SetField(soratask.FieldStatus, field.TypeString, value) _node.Status = value } if value, ok := _c.mutation.Progress(); ok { _spec.SetField(soratask.FieldProgress, field.TypeFloat64, value) _node.Progress = value } if value, ok := _c.mutation.ResultUrls(); ok { _spec.SetField(soratask.FieldResultUrls, field.TypeString, value) _node.ResultUrls = &value } if value, ok := _c.mutation.ErrorMessage(); ok { _spec.SetField(soratask.FieldErrorMessage, field.TypeString, value) _node.ErrorMessage = &value } if value, ok := _c.mutation.RetryCount(); ok { _spec.SetField(soratask.FieldRetryCount, field.TypeInt, value) _node.RetryCount = value } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(soratask.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.CompletedAt(); ok { _spec.SetField(soratask.FieldCompletedAt, field.TypeTime, value) _node.CompletedAt = &value } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.SoraTask.Create(). // SetTaskID(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.SoraTaskUpsert) { // SetTaskID(v+v). // }). // Exec(ctx) func (_c *SoraTaskCreate) OnConflict(opts ...sql.ConflictOption) *SoraTaskUpsertOne { _c.conflict = opts return &SoraTaskUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.SoraTask.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *SoraTaskCreate) OnConflictColumns(columns ...string) *SoraTaskUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &SoraTaskUpsertOne{ create: _c, } } type ( // SoraTaskUpsertOne is the builder for "upsert"-ing // one SoraTask node. SoraTaskUpsertOne struct { create *SoraTaskCreate } // SoraTaskUpsert is the "OnConflict" setter. SoraTaskUpsert struct { *sql.UpdateSet } ) // SetTaskID sets the "task_id" field. func (u *SoraTaskUpsert) SetTaskID(v string) *SoraTaskUpsert { u.Set(soratask.FieldTaskID, v) return u } // UpdateTaskID sets the "task_id" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateTaskID() *SoraTaskUpsert { u.SetExcluded(soratask.FieldTaskID) return u } // SetAccountID sets the "account_id" field. func (u *SoraTaskUpsert) SetAccountID(v int64) *SoraTaskUpsert { u.Set(soratask.FieldAccountID, v) return u } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateAccountID() *SoraTaskUpsert { u.SetExcluded(soratask.FieldAccountID) return u } // AddAccountID adds v to the "account_id" field. func (u *SoraTaskUpsert) AddAccountID(v int64) *SoraTaskUpsert { u.Add(soratask.FieldAccountID, v) return u } // SetModel sets the "model" field. func (u *SoraTaskUpsert) SetModel(v string) *SoraTaskUpsert { u.Set(soratask.FieldModel, v) return u } // UpdateModel sets the "model" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateModel() *SoraTaskUpsert { u.SetExcluded(soratask.FieldModel) return u } // SetPrompt sets the "prompt" field. func (u *SoraTaskUpsert) SetPrompt(v string) *SoraTaskUpsert { u.Set(soratask.FieldPrompt, v) return u } // UpdatePrompt sets the "prompt" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdatePrompt() *SoraTaskUpsert { u.SetExcluded(soratask.FieldPrompt) return u } // SetStatus sets the "status" field. func (u *SoraTaskUpsert) SetStatus(v string) *SoraTaskUpsert { u.Set(soratask.FieldStatus, v) return u } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateStatus() *SoraTaskUpsert { u.SetExcluded(soratask.FieldStatus) return u } // SetProgress sets the "progress" field. func (u *SoraTaskUpsert) SetProgress(v float64) *SoraTaskUpsert { u.Set(soratask.FieldProgress, v) return u } // UpdateProgress sets the "progress" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateProgress() *SoraTaskUpsert { u.SetExcluded(soratask.FieldProgress) return u } // AddProgress adds v to the "progress" field. func (u *SoraTaskUpsert) AddProgress(v float64) *SoraTaskUpsert { u.Add(soratask.FieldProgress, v) return u } // SetResultUrls sets the "result_urls" field. func (u *SoraTaskUpsert) SetResultUrls(v string) *SoraTaskUpsert { u.Set(soratask.FieldResultUrls, v) return u } // UpdateResultUrls sets the "result_urls" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateResultUrls() *SoraTaskUpsert { u.SetExcluded(soratask.FieldResultUrls) return u } // ClearResultUrls clears the value of the "result_urls" field. func (u *SoraTaskUpsert) ClearResultUrls() *SoraTaskUpsert { u.SetNull(soratask.FieldResultUrls) return u } // SetErrorMessage sets the "error_message" field. func (u *SoraTaskUpsert) SetErrorMessage(v string) *SoraTaskUpsert { u.Set(soratask.FieldErrorMessage, v) return u } // UpdateErrorMessage sets the "error_message" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateErrorMessage() *SoraTaskUpsert { u.SetExcluded(soratask.FieldErrorMessage) return u } // ClearErrorMessage clears the value of the "error_message" field. func (u *SoraTaskUpsert) ClearErrorMessage() *SoraTaskUpsert { u.SetNull(soratask.FieldErrorMessage) return u } // SetRetryCount sets the "retry_count" field. func (u *SoraTaskUpsert) SetRetryCount(v int) *SoraTaskUpsert { u.Set(soratask.FieldRetryCount, v) return u } // UpdateRetryCount sets the "retry_count" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateRetryCount() *SoraTaskUpsert { u.SetExcluded(soratask.FieldRetryCount) return u } // AddRetryCount adds v to the "retry_count" field. func (u *SoraTaskUpsert) AddRetryCount(v int) *SoraTaskUpsert { u.Add(soratask.FieldRetryCount, v) return u } // SetCreatedAt sets the "created_at" field. func (u *SoraTaskUpsert) SetCreatedAt(v time.Time) *SoraTaskUpsert { u.Set(soratask.FieldCreatedAt, v) return u } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateCreatedAt() *SoraTaskUpsert { u.SetExcluded(soratask.FieldCreatedAt) return u } // SetCompletedAt sets the "completed_at" field. func (u *SoraTaskUpsert) SetCompletedAt(v time.Time) *SoraTaskUpsert { u.Set(soratask.FieldCompletedAt, v) return u } // UpdateCompletedAt sets the "completed_at" field to the value that was provided on create. func (u *SoraTaskUpsert) UpdateCompletedAt() *SoraTaskUpsert { u.SetExcluded(soratask.FieldCompletedAt) return u } // ClearCompletedAt clears the value of the "completed_at" field. func (u *SoraTaskUpsert) ClearCompletedAt() *SoraTaskUpsert { u.SetNull(soratask.FieldCompletedAt) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // // client.SoraTask.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *SoraTaskUpsertOne) UpdateNewValues() *SoraTaskUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.SoraTask.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SoraTaskUpsertOne) Ignore() *SoraTaskUpsertOne { 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 *SoraTaskUpsertOne) DoNothing() *SoraTaskUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SoraTaskCreate.OnConflict // documentation for more info. func (u *SoraTaskUpsertOne) Update(set func(*SoraTaskUpsert)) *SoraTaskUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SoraTaskUpsert{UpdateSet: update}) })) return u } // SetTaskID sets the "task_id" field. func (u *SoraTaskUpsertOne) SetTaskID(v string) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetTaskID(v) }) } // UpdateTaskID sets the "task_id" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateTaskID() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateTaskID() }) } // SetAccountID sets the "account_id" field. func (u *SoraTaskUpsertOne) SetAccountID(v int64) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetAccountID(v) }) } // AddAccountID adds v to the "account_id" field. func (u *SoraTaskUpsertOne) AddAccountID(v int64) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.AddAccountID(v) }) } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateAccountID() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateAccountID() }) } // SetModel sets the "model" field. func (u *SoraTaskUpsertOne) SetModel(v string) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetModel(v) }) } // UpdateModel sets the "model" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateModel() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateModel() }) } // SetPrompt sets the "prompt" field. func (u *SoraTaskUpsertOne) SetPrompt(v string) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetPrompt(v) }) } // UpdatePrompt sets the "prompt" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdatePrompt() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdatePrompt() }) } // SetStatus sets the "status" field. func (u *SoraTaskUpsertOne) SetStatus(v string) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetStatus(v) }) } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateStatus() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateStatus() }) } // SetProgress sets the "progress" field. func (u *SoraTaskUpsertOne) SetProgress(v float64) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetProgress(v) }) } // AddProgress adds v to the "progress" field. func (u *SoraTaskUpsertOne) AddProgress(v float64) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.AddProgress(v) }) } // UpdateProgress sets the "progress" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateProgress() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateProgress() }) } // SetResultUrls sets the "result_urls" field. func (u *SoraTaskUpsertOne) SetResultUrls(v string) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetResultUrls(v) }) } // UpdateResultUrls sets the "result_urls" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateResultUrls() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateResultUrls() }) } // ClearResultUrls clears the value of the "result_urls" field. func (u *SoraTaskUpsertOne) ClearResultUrls() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.ClearResultUrls() }) } // SetErrorMessage sets the "error_message" field. func (u *SoraTaskUpsertOne) SetErrorMessage(v string) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetErrorMessage(v) }) } // UpdateErrorMessage sets the "error_message" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateErrorMessage() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateErrorMessage() }) } // ClearErrorMessage clears the value of the "error_message" field. func (u *SoraTaskUpsertOne) ClearErrorMessage() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.ClearErrorMessage() }) } // SetRetryCount sets the "retry_count" field. func (u *SoraTaskUpsertOne) SetRetryCount(v int) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetRetryCount(v) }) } // AddRetryCount adds v to the "retry_count" field. func (u *SoraTaskUpsertOne) AddRetryCount(v int) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.AddRetryCount(v) }) } // UpdateRetryCount sets the "retry_count" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateRetryCount() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateRetryCount() }) } // SetCreatedAt sets the "created_at" field. func (u *SoraTaskUpsertOne) SetCreatedAt(v time.Time) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateCreatedAt() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateCreatedAt() }) } // SetCompletedAt sets the "completed_at" field. func (u *SoraTaskUpsertOne) SetCompletedAt(v time.Time) *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.SetCompletedAt(v) }) } // UpdateCompletedAt sets the "completed_at" field to the value that was provided on create. func (u *SoraTaskUpsertOne) UpdateCompletedAt() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.UpdateCompletedAt() }) } // ClearCompletedAt clears the value of the "completed_at" field. func (u *SoraTaskUpsertOne) ClearCompletedAt() *SoraTaskUpsertOne { return u.Update(func(s *SoraTaskUpsert) { s.ClearCompletedAt() }) } // Exec executes the query. func (u *SoraTaskUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SoraTaskCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SoraTaskUpsertOne) 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 *SoraTaskUpsertOne) ID(ctx context.Context) (id int64, 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 *SoraTaskUpsertOne) IDX(ctx context.Context) int64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // SoraTaskCreateBulk is the builder for creating many SoraTask entities in bulk. type SoraTaskCreateBulk struct { config err error builders []*SoraTaskCreate conflict []sql.ConflictOption } // Save creates the SoraTask entities in the database. func (_c *SoraTaskCreateBulk) Save(ctx context.Context) ([]*SoraTask, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*SoraTask, 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.(*SoraTaskMutation) 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 if specs[i].ID.Value != nil { id := specs[i].ID.Value.(int64) nodes[i].ID = int64(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 *SoraTaskCreateBulk) SaveX(ctx context.Context) []*SoraTask { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *SoraTaskCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *SoraTaskCreateBulk) 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.SoraTask.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.SoraTaskUpsert) { // SetTaskID(v+v). // }). // Exec(ctx) func (_c *SoraTaskCreateBulk) OnConflict(opts ...sql.ConflictOption) *SoraTaskUpsertBulk { _c.conflict = opts return &SoraTaskUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.SoraTask.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *SoraTaskCreateBulk) OnConflictColumns(columns ...string) *SoraTaskUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &SoraTaskUpsertBulk{ create: _c, } } // SoraTaskUpsertBulk is the builder for "upsert"-ing // a bulk of SoraTask nodes. type SoraTaskUpsertBulk struct { create *SoraTaskCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.SoraTask.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *SoraTaskUpsertBulk) UpdateNewValues() *SoraTaskUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.SoraTask.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SoraTaskUpsertBulk) Ignore() *SoraTaskUpsertBulk { 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 *SoraTaskUpsertBulk) DoNothing() *SoraTaskUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SoraTaskCreateBulk.OnConflict // documentation for more info. func (u *SoraTaskUpsertBulk) Update(set func(*SoraTaskUpsert)) *SoraTaskUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SoraTaskUpsert{UpdateSet: update}) })) return u } // SetTaskID sets the "task_id" field. func (u *SoraTaskUpsertBulk) SetTaskID(v string) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetTaskID(v) }) } // UpdateTaskID sets the "task_id" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateTaskID() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateTaskID() }) } // SetAccountID sets the "account_id" field. func (u *SoraTaskUpsertBulk) SetAccountID(v int64) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetAccountID(v) }) } // AddAccountID adds v to the "account_id" field. func (u *SoraTaskUpsertBulk) AddAccountID(v int64) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.AddAccountID(v) }) } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateAccountID() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateAccountID() }) } // SetModel sets the "model" field. func (u *SoraTaskUpsertBulk) SetModel(v string) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetModel(v) }) } // UpdateModel sets the "model" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateModel() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateModel() }) } // SetPrompt sets the "prompt" field. func (u *SoraTaskUpsertBulk) SetPrompt(v string) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetPrompt(v) }) } // UpdatePrompt sets the "prompt" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdatePrompt() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdatePrompt() }) } // SetStatus sets the "status" field. func (u *SoraTaskUpsertBulk) SetStatus(v string) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetStatus(v) }) } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateStatus() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateStatus() }) } // SetProgress sets the "progress" field. func (u *SoraTaskUpsertBulk) SetProgress(v float64) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetProgress(v) }) } // AddProgress adds v to the "progress" field. func (u *SoraTaskUpsertBulk) AddProgress(v float64) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.AddProgress(v) }) } // UpdateProgress sets the "progress" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateProgress() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateProgress() }) } // SetResultUrls sets the "result_urls" field. func (u *SoraTaskUpsertBulk) SetResultUrls(v string) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetResultUrls(v) }) } // UpdateResultUrls sets the "result_urls" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateResultUrls() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateResultUrls() }) } // ClearResultUrls clears the value of the "result_urls" field. func (u *SoraTaskUpsertBulk) ClearResultUrls() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.ClearResultUrls() }) } // SetErrorMessage sets the "error_message" field. func (u *SoraTaskUpsertBulk) SetErrorMessage(v string) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetErrorMessage(v) }) } // UpdateErrorMessage sets the "error_message" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateErrorMessage() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateErrorMessage() }) } // ClearErrorMessage clears the value of the "error_message" field. func (u *SoraTaskUpsertBulk) ClearErrorMessage() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.ClearErrorMessage() }) } // SetRetryCount sets the "retry_count" field. func (u *SoraTaskUpsertBulk) SetRetryCount(v int) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetRetryCount(v) }) } // AddRetryCount adds v to the "retry_count" field. func (u *SoraTaskUpsertBulk) AddRetryCount(v int) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.AddRetryCount(v) }) } // UpdateRetryCount sets the "retry_count" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateRetryCount() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateRetryCount() }) } // SetCreatedAt sets the "created_at" field. func (u *SoraTaskUpsertBulk) SetCreatedAt(v time.Time) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateCreatedAt() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateCreatedAt() }) } // SetCompletedAt sets the "completed_at" field. func (u *SoraTaskUpsertBulk) SetCompletedAt(v time.Time) *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.SetCompletedAt(v) }) } // UpdateCompletedAt sets the "completed_at" field to the value that was provided on create. func (u *SoraTaskUpsertBulk) UpdateCompletedAt() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.UpdateCompletedAt() }) } // ClearCompletedAt clears the value of the "completed_at" field. func (u *SoraTaskUpsertBulk) ClearCompletedAt() *SoraTaskUpsertBulk { return u.Update(func(s *SoraTaskUpsert) { s.ClearCompletedAt() }) } // Exec executes the query. func (u *SoraTaskUpsertBulk) 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 SoraTaskCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SoraTaskCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SoraTaskUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }