123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/compapiasynctask"
- "wechat-api/ent/predicate"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // CompapiAsynctaskUpdate is the builder for updating CompapiAsynctask entities.
- type CompapiAsynctaskUpdate struct {
- config
- hooks []Hook
- mutation *CompapiAsynctaskMutation
- }
- // Where appends a list predicates to the CompapiAsynctaskUpdate builder.
- func (cau *CompapiAsynctaskUpdate) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskUpdate {
- cau.mutation.Where(ps...)
- return cau
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cau *CompapiAsynctaskUpdate) SetUpdatedAt(t time.Time) *CompapiAsynctaskUpdate {
- cau.mutation.SetUpdatedAt(t)
- return cau
- }
- // SetAuthToken sets the "auth_token" field.
- func (cau *CompapiAsynctaskUpdate) SetAuthToken(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetAuthToken(s)
- return cau
- }
- // SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableAuthToken(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetAuthToken(*s)
- }
- return cau
- }
- // SetEventType sets the "event_type" field.
- func (cau *CompapiAsynctaskUpdate) SetEventType(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetEventType(s)
- return cau
- }
- // SetNillableEventType sets the "event_type" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableEventType(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetEventType(*s)
- }
- return cau
- }
- // SetChatID sets the "chat_id" field.
- func (cau *CompapiAsynctaskUpdate) SetChatID(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetChatID(s)
- return cau
- }
- // SetNillableChatID sets the "chat_id" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableChatID(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetChatID(*s)
- }
- return cau
- }
- // ClearChatID clears the value of the "chat_id" field.
- func (cau *CompapiAsynctaskUpdate) ClearChatID() *CompapiAsynctaskUpdate {
- cau.mutation.ClearChatID()
- return cau
- }
- // SetWorkidIdx sets the "workid_idx" field.
- func (cau *CompapiAsynctaskUpdate) SetWorkidIdx(i int8) *CompapiAsynctaskUpdate {
- cau.mutation.ResetWorkidIdx()
- cau.mutation.SetWorkidIdx(i)
- return cau
- }
- // SetNillableWorkidIdx sets the "workid_idx" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableWorkidIdx(i *int8) *CompapiAsynctaskUpdate {
- if i != nil {
- cau.SetWorkidIdx(*i)
- }
- return cau
- }
- // AddWorkidIdx adds i to the "workid_idx" field.
- func (cau *CompapiAsynctaskUpdate) AddWorkidIdx(i int8) *CompapiAsynctaskUpdate {
- cau.mutation.AddWorkidIdx(i)
- return cau
- }
- // ClearWorkidIdx clears the value of the "workid_idx" field.
- func (cau *CompapiAsynctaskUpdate) ClearWorkidIdx() *CompapiAsynctaskUpdate {
- cau.mutation.ClearWorkidIdx()
- return cau
- }
- // SetOpenaiBase sets the "openai_base" field.
- func (cau *CompapiAsynctaskUpdate) SetOpenaiBase(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetOpenaiBase(s)
- return cau
- }
- // SetNillableOpenaiBase sets the "openai_base" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableOpenaiBase(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetOpenaiBase(*s)
- }
- return cau
- }
- // SetOpenaiKey sets the "openai_key" field.
- func (cau *CompapiAsynctaskUpdate) SetOpenaiKey(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetOpenaiKey(s)
- return cau
- }
- // SetNillableOpenaiKey sets the "openai_key" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableOpenaiKey(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetOpenaiKey(*s)
- }
- return cau
- }
- // SetRequestRaw sets the "request_raw" field.
- func (cau *CompapiAsynctaskUpdate) SetRequestRaw(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetRequestRaw(s)
- return cau
- }
- // SetNillableRequestRaw sets the "request_raw" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableRequestRaw(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetRequestRaw(*s)
- }
- return cau
- }
- // SetResponseRaw sets the "response_raw" field.
- func (cau *CompapiAsynctaskUpdate) SetResponseRaw(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetResponseRaw(s)
- return cau
- }
- // SetNillableResponseRaw sets the "response_raw" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableResponseRaw(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetResponseRaw(*s)
- }
- return cau
- }
- // ClearResponseRaw clears the value of the "response_raw" field.
- func (cau *CompapiAsynctaskUpdate) ClearResponseRaw() *CompapiAsynctaskUpdate {
- cau.mutation.ClearResponseRaw()
- return cau
- }
- // SetCallbackURL sets the "callback_url" field.
- func (cau *CompapiAsynctaskUpdate) SetCallbackURL(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetCallbackURL(s)
- return cau
- }
- // SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableCallbackURL(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetCallbackURL(*s)
- }
- return cau
- }
- // SetTaskStatus sets the "task_status" field.
- func (cau *CompapiAsynctaskUpdate) SetTaskStatus(i int8) *CompapiAsynctaskUpdate {
- cau.mutation.ResetTaskStatus()
- cau.mutation.SetTaskStatus(i)
- return cau
- }
- // SetNillableTaskStatus sets the "task_status" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableTaskStatus(i *int8) *CompapiAsynctaskUpdate {
- if i != nil {
- cau.SetTaskStatus(*i)
- }
- return cau
- }
- // AddTaskStatus adds i to the "task_status" field.
- func (cau *CompapiAsynctaskUpdate) AddTaskStatus(i int8) *CompapiAsynctaskUpdate {
- cau.mutation.AddTaskStatus(i)
- return cau
- }
- // ClearTaskStatus clears the value of the "task_status" field.
- func (cau *CompapiAsynctaskUpdate) ClearTaskStatus() *CompapiAsynctaskUpdate {
- cau.mutation.ClearTaskStatus()
- return cau
- }
- // SetRetryCount sets the "retry_count" field.
- func (cau *CompapiAsynctaskUpdate) SetRetryCount(i int8) *CompapiAsynctaskUpdate {
- cau.mutation.ResetRetryCount()
- cau.mutation.SetRetryCount(i)
- return cau
- }
- // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableRetryCount(i *int8) *CompapiAsynctaskUpdate {
- if i != nil {
- cau.SetRetryCount(*i)
- }
- return cau
- }
- // AddRetryCount adds i to the "retry_count" field.
- func (cau *CompapiAsynctaskUpdate) AddRetryCount(i int8) *CompapiAsynctaskUpdate {
- cau.mutation.AddRetryCount(i)
- return cau
- }
- // ClearRetryCount clears the value of the "retry_count" field.
- func (cau *CompapiAsynctaskUpdate) ClearRetryCount() *CompapiAsynctaskUpdate {
- cau.mutation.ClearRetryCount()
- return cau
- }
- // SetLastError sets the "last_error" field.
- func (cau *CompapiAsynctaskUpdate) SetLastError(s string) *CompapiAsynctaskUpdate {
- cau.mutation.SetLastError(s)
- return cau
- }
- // SetNillableLastError sets the "last_error" field if the given value is not nil.
- func (cau *CompapiAsynctaskUpdate) SetNillableLastError(s *string) *CompapiAsynctaskUpdate {
- if s != nil {
- cau.SetLastError(*s)
- }
- return cau
- }
- // ClearLastError clears the value of the "last_error" field.
- func (cau *CompapiAsynctaskUpdate) ClearLastError() *CompapiAsynctaskUpdate {
- cau.mutation.ClearLastError()
- return cau
- }
- // Mutation returns the CompapiAsynctaskMutation object of the builder.
- func (cau *CompapiAsynctaskUpdate) Mutation() *CompapiAsynctaskMutation {
- return cau.mutation
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (cau *CompapiAsynctaskUpdate) Save(ctx context.Context) (int, error) {
- cau.defaults()
- return withHooks(ctx, cau.sqlSave, cau.mutation, cau.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (cau *CompapiAsynctaskUpdate) SaveX(ctx context.Context) int {
- affected, err := cau.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (cau *CompapiAsynctaskUpdate) Exec(ctx context.Context) error {
- _, err := cau.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cau *CompapiAsynctaskUpdate) ExecX(ctx context.Context) {
- if err := cau.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cau *CompapiAsynctaskUpdate) defaults() {
- if _, ok := cau.mutation.UpdatedAt(); !ok {
- v := compapiasynctask.UpdateDefaultUpdatedAt()
- cau.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (cau *CompapiAsynctaskUpdate) check() error {
- if v, ok := cau.mutation.CallbackURL(); ok {
- if err := compapiasynctask.CallbackURLValidator(v); err != nil {
- return &ValidationError{Name: "callback_url", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.callback_url": %w`, err)}
- }
- }
- return nil
- }
- func (cau *CompapiAsynctaskUpdate) sqlSave(ctx context.Context) (n int, err error) {
- if err := cau.check(); err != nil {
- return n, err
- }
- _spec := sqlgraph.NewUpdateSpec(compapiasynctask.Table, compapiasynctask.Columns, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
- if ps := cau.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := cau.mutation.UpdatedAt(); ok {
- _spec.SetField(compapiasynctask.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := cau.mutation.AuthToken(); ok {
- _spec.SetField(compapiasynctask.FieldAuthToken, field.TypeString, value)
- }
- if value, ok := cau.mutation.EventType(); ok {
- _spec.SetField(compapiasynctask.FieldEventType, field.TypeString, value)
- }
- if value, ok := cau.mutation.ChatID(); ok {
- _spec.SetField(compapiasynctask.FieldChatID, field.TypeString, value)
- }
- if cau.mutation.ChatIDCleared() {
- _spec.ClearField(compapiasynctask.FieldChatID, field.TypeString)
- }
- if value, ok := cau.mutation.WorkidIdx(); ok {
- _spec.SetField(compapiasynctask.FieldWorkidIdx, field.TypeInt8, value)
- }
- if value, ok := cau.mutation.AddedWorkidIdx(); ok {
- _spec.AddField(compapiasynctask.FieldWorkidIdx, field.TypeInt8, value)
- }
- if cau.mutation.WorkidIdxCleared() {
- _spec.ClearField(compapiasynctask.FieldWorkidIdx, field.TypeInt8)
- }
- if value, ok := cau.mutation.OpenaiBase(); ok {
- _spec.SetField(compapiasynctask.FieldOpenaiBase, field.TypeString, value)
- }
- if value, ok := cau.mutation.OpenaiKey(); ok {
- _spec.SetField(compapiasynctask.FieldOpenaiKey, field.TypeString, value)
- }
- if value, ok := cau.mutation.RequestRaw(); ok {
- _spec.SetField(compapiasynctask.FieldRequestRaw, field.TypeString, value)
- }
- if value, ok := cau.mutation.ResponseRaw(); ok {
- _spec.SetField(compapiasynctask.FieldResponseRaw, field.TypeString, value)
- }
- if cau.mutation.ResponseRawCleared() {
- _spec.ClearField(compapiasynctask.FieldResponseRaw, field.TypeString)
- }
- if value, ok := cau.mutation.CallbackURL(); ok {
- _spec.SetField(compapiasynctask.FieldCallbackURL, field.TypeString, value)
- }
- if value, ok := cau.mutation.TaskStatus(); ok {
- _spec.SetField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
- }
- if value, ok := cau.mutation.AddedTaskStatus(); ok {
- _spec.AddField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
- }
- if cau.mutation.TaskStatusCleared() {
- _spec.ClearField(compapiasynctask.FieldTaskStatus, field.TypeInt8)
- }
- if value, ok := cau.mutation.RetryCount(); ok {
- _spec.SetField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
- }
- if value, ok := cau.mutation.AddedRetryCount(); ok {
- _spec.AddField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
- }
- if cau.mutation.RetryCountCleared() {
- _spec.ClearField(compapiasynctask.FieldRetryCount, field.TypeInt8)
- }
- if value, ok := cau.mutation.LastError(); ok {
- _spec.SetField(compapiasynctask.FieldLastError, field.TypeString, value)
- }
- if cau.mutation.LastErrorCleared() {
- _spec.ClearField(compapiasynctask.FieldLastError, field.TypeString)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, cau.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{compapiasynctask.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- cau.mutation.done = true
- return n, nil
- }
- // CompapiAsynctaskUpdateOne is the builder for updating a single CompapiAsynctask entity.
- type CompapiAsynctaskUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *CompapiAsynctaskMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetUpdatedAt(t time.Time) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetUpdatedAt(t)
- return cauo
- }
- // SetAuthToken sets the "auth_token" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetAuthToken(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetAuthToken(s)
- return cauo
- }
- // SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableAuthToken(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetAuthToken(*s)
- }
- return cauo
- }
- // SetEventType sets the "event_type" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetEventType(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetEventType(s)
- return cauo
- }
- // SetNillableEventType sets the "event_type" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableEventType(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetEventType(*s)
- }
- return cauo
- }
- // SetChatID sets the "chat_id" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetChatID(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetChatID(s)
- return cauo
- }
- // SetNillableChatID sets the "chat_id" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableChatID(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetChatID(*s)
- }
- return cauo
- }
- // ClearChatID clears the value of the "chat_id" field.
- func (cauo *CompapiAsynctaskUpdateOne) ClearChatID() *CompapiAsynctaskUpdateOne {
- cauo.mutation.ClearChatID()
- return cauo
- }
- // SetWorkidIdx sets the "workid_idx" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetWorkidIdx(i int8) *CompapiAsynctaskUpdateOne {
- cauo.mutation.ResetWorkidIdx()
- cauo.mutation.SetWorkidIdx(i)
- return cauo
- }
- // SetNillableWorkidIdx sets the "workid_idx" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableWorkidIdx(i *int8) *CompapiAsynctaskUpdateOne {
- if i != nil {
- cauo.SetWorkidIdx(*i)
- }
- return cauo
- }
- // AddWorkidIdx adds i to the "workid_idx" field.
- func (cauo *CompapiAsynctaskUpdateOne) AddWorkidIdx(i int8) *CompapiAsynctaskUpdateOne {
- cauo.mutation.AddWorkidIdx(i)
- return cauo
- }
- // ClearWorkidIdx clears the value of the "workid_idx" field.
- func (cauo *CompapiAsynctaskUpdateOne) ClearWorkidIdx() *CompapiAsynctaskUpdateOne {
- cauo.mutation.ClearWorkidIdx()
- return cauo
- }
- // SetOpenaiBase sets the "openai_base" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetOpenaiBase(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetOpenaiBase(s)
- return cauo
- }
- // SetNillableOpenaiBase sets the "openai_base" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableOpenaiBase(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetOpenaiBase(*s)
- }
- return cauo
- }
- // SetOpenaiKey sets the "openai_key" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetOpenaiKey(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetOpenaiKey(s)
- return cauo
- }
- // SetNillableOpenaiKey sets the "openai_key" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableOpenaiKey(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetOpenaiKey(*s)
- }
- return cauo
- }
- // SetRequestRaw sets the "request_raw" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetRequestRaw(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetRequestRaw(s)
- return cauo
- }
- // SetNillableRequestRaw sets the "request_raw" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableRequestRaw(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetRequestRaw(*s)
- }
- return cauo
- }
- // SetResponseRaw sets the "response_raw" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetResponseRaw(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetResponseRaw(s)
- return cauo
- }
- // SetNillableResponseRaw sets the "response_raw" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableResponseRaw(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetResponseRaw(*s)
- }
- return cauo
- }
- // ClearResponseRaw clears the value of the "response_raw" field.
- func (cauo *CompapiAsynctaskUpdateOne) ClearResponseRaw() *CompapiAsynctaskUpdateOne {
- cauo.mutation.ClearResponseRaw()
- return cauo
- }
- // SetCallbackURL sets the "callback_url" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetCallbackURL(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetCallbackURL(s)
- return cauo
- }
- // SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableCallbackURL(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetCallbackURL(*s)
- }
- return cauo
- }
- // SetTaskStatus sets the "task_status" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetTaskStatus(i int8) *CompapiAsynctaskUpdateOne {
- cauo.mutation.ResetTaskStatus()
- cauo.mutation.SetTaskStatus(i)
- return cauo
- }
- // SetNillableTaskStatus sets the "task_status" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableTaskStatus(i *int8) *CompapiAsynctaskUpdateOne {
- if i != nil {
- cauo.SetTaskStatus(*i)
- }
- return cauo
- }
- // AddTaskStatus adds i to the "task_status" field.
- func (cauo *CompapiAsynctaskUpdateOne) AddTaskStatus(i int8) *CompapiAsynctaskUpdateOne {
- cauo.mutation.AddTaskStatus(i)
- return cauo
- }
- // ClearTaskStatus clears the value of the "task_status" field.
- func (cauo *CompapiAsynctaskUpdateOne) ClearTaskStatus() *CompapiAsynctaskUpdateOne {
- cauo.mutation.ClearTaskStatus()
- return cauo
- }
- // SetRetryCount sets the "retry_count" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetRetryCount(i int8) *CompapiAsynctaskUpdateOne {
- cauo.mutation.ResetRetryCount()
- cauo.mutation.SetRetryCount(i)
- return cauo
- }
- // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableRetryCount(i *int8) *CompapiAsynctaskUpdateOne {
- if i != nil {
- cauo.SetRetryCount(*i)
- }
- return cauo
- }
- // AddRetryCount adds i to the "retry_count" field.
- func (cauo *CompapiAsynctaskUpdateOne) AddRetryCount(i int8) *CompapiAsynctaskUpdateOne {
- cauo.mutation.AddRetryCount(i)
- return cauo
- }
- // ClearRetryCount clears the value of the "retry_count" field.
- func (cauo *CompapiAsynctaskUpdateOne) ClearRetryCount() *CompapiAsynctaskUpdateOne {
- cauo.mutation.ClearRetryCount()
- return cauo
- }
- // SetLastError sets the "last_error" field.
- func (cauo *CompapiAsynctaskUpdateOne) SetLastError(s string) *CompapiAsynctaskUpdateOne {
- cauo.mutation.SetLastError(s)
- return cauo
- }
- // SetNillableLastError sets the "last_error" field if the given value is not nil.
- func (cauo *CompapiAsynctaskUpdateOne) SetNillableLastError(s *string) *CompapiAsynctaskUpdateOne {
- if s != nil {
- cauo.SetLastError(*s)
- }
- return cauo
- }
- // ClearLastError clears the value of the "last_error" field.
- func (cauo *CompapiAsynctaskUpdateOne) ClearLastError() *CompapiAsynctaskUpdateOne {
- cauo.mutation.ClearLastError()
- return cauo
- }
- // Mutation returns the CompapiAsynctaskMutation object of the builder.
- func (cauo *CompapiAsynctaskUpdateOne) Mutation() *CompapiAsynctaskMutation {
- return cauo.mutation
- }
- // Where appends a list predicates to the CompapiAsynctaskUpdate builder.
- func (cauo *CompapiAsynctaskUpdateOne) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskUpdateOne {
- cauo.mutation.Where(ps...)
- return cauo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (cauo *CompapiAsynctaskUpdateOne) Select(field string, fields ...string) *CompapiAsynctaskUpdateOne {
- cauo.fields = append([]string{field}, fields...)
- return cauo
- }
- // Save executes the query and returns the updated CompapiAsynctask entity.
- func (cauo *CompapiAsynctaskUpdateOne) Save(ctx context.Context) (*CompapiAsynctask, error) {
- cauo.defaults()
- return withHooks(ctx, cauo.sqlSave, cauo.mutation, cauo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (cauo *CompapiAsynctaskUpdateOne) SaveX(ctx context.Context) *CompapiAsynctask {
- node, err := cauo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (cauo *CompapiAsynctaskUpdateOne) Exec(ctx context.Context) error {
- _, err := cauo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cauo *CompapiAsynctaskUpdateOne) ExecX(ctx context.Context) {
- if err := cauo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cauo *CompapiAsynctaskUpdateOne) defaults() {
- if _, ok := cauo.mutation.UpdatedAt(); !ok {
- v := compapiasynctask.UpdateDefaultUpdatedAt()
- cauo.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (cauo *CompapiAsynctaskUpdateOne) check() error {
- if v, ok := cauo.mutation.CallbackURL(); ok {
- if err := compapiasynctask.CallbackURLValidator(v); err != nil {
- return &ValidationError{Name: "callback_url", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.callback_url": %w`, err)}
- }
- }
- return nil
- }
- func (cauo *CompapiAsynctaskUpdateOne) sqlSave(ctx context.Context) (_node *CompapiAsynctask, err error) {
- if err := cauo.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(compapiasynctask.Table, compapiasynctask.Columns, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
- id, ok := cauo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CompapiAsynctask.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := cauo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, compapiasynctask.FieldID)
- for _, f := range fields {
- if !compapiasynctask.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != compapiasynctask.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := cauo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := cauo.mutation.UpdatedAt(); ok {
- _spec.SetField(compapiasynctask.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := cauo.mutation.AuthToken(); ok {
- _spec.SetField(compapiasynctask.FieldAuthToken, field.TypeString, value)
- }
- if value, ok := cauo.mutation.EventType(); ok {
- _spec.SetField(compapiasynctask.FieldEventType, field.TypeString, value)
- }
- if value, ok := cauo.mutation.ChatID(); ok {
- _spec.SetField(compapiasynctask.FieldChatID, field.TypeString, value)
- }
- if cauo.mutation.ChatIDCleared() {
- _spec.ClearField(compapiasynctask.FieldChatID, field.TypeString)
- }
- if value, ok := cauo.mutation.WorkidIdx(); ok {
- _spec.SetField(compapiasynctask.FieldWorkidIdx, field.TypeInt8, value)
- }
- if value, ok := cauo.mutation.AddedWorkidIdx(); ok {
- _spec.AddField(compapiasynctask.FieldWorkidIdx, field.TypeInt8, value)
- }
- if cauo.mutation.WorkidIdxCleared() {
- _spec.ClearField(compapiasynctask.FieldWorkidIdx, field.TypeInt8)
- }
- if value, ok := cauo.mutation.OpenaiBase(); ok {
- _spec.SetField(compapiasynctask.FieldOpenaiBase, field.TypeString, value)
- }
- if value, ok := cauo.mutation.OpenaiKey(); ok {
- _spec.SetField(compapiasynctask.FieldOpenaiKey, field.TypeString, value)
- }
- if value, ok := cauo.mutation.RequestRaw(); ok {
- _spec.SetField(compapiasynctask.FieldRequestRaw, field.TypeString, value)
- }
- if value, ok := cauo.mutation.ResponseRaw(); ok {
- _spec.SetField(compapiasynctask.FieldResponseRaw, field.TypeString, value)
- }
- if cauo.mutation.ResponseRawCleared() {
- _spec.ClearField(compapiasynctask.FieldResponseRaw, field.TypeString)
- }
- if value, ok := cauo.mutation.CallbackURL(); ok {
- _spec.SetField(compapiasynctask.FieldCallbackURL, field.TypeString, value)
- }
- if value, ok := cauo.mutation.TaskStatus(); ok {
- _spec.SetField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
- }
- if value, ok := cauo.mutation.AddedTaskStatus(); ok {
- _spec.AddField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
- }
- if cauo.mutation.TaskStatusCleared() {
- _spec.ClearField(compapiasynctask.FieldTaskStatus, field.TypeInt8)
- }
- if value, ok := cauo.mutation.RetryCount(); ok {
- _spec.SetField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
- }
- if value, ok := cauo.mutation.AddedRetryCount(); ok {
- _spec.AddField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
- }
- if cauo.mutation.RetryCountCleared() {
- _spec.ClearField(compapiasynctask.FieldRetryCount, field.TypeInt8)
- }
- if value, ok := cauo.mutation.LastError(); ok {
- _spec.SetField(compapiasynctask.FieldLastError, field.TypeString, value)
- }
- if cauo.mutation.LastErrorCleared() {
- _spec.ClearField(compapiasynctask.FieldLastError, field.TypeString)
- }
- _node = &CompapiAsynctask{config: cauo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, cauo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{compapiasynctask.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- cauo.mutation.done = true
- return _node, nil
- }
|