123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/compapijob"
- "wechat-api/ent/custom_types"
- "wechat-api/ent/predicate"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // CompapiJobUpdate is the builder for updating CompapiJob entities.
- type CompapiJobUpdate struct {
- config
- hooks []Hook
- mutation *CompapiJobMutation
- }
- // Where appends a list predicates to the CompapiJobUpdate builder.
- func (cju *CompapiJobUpdate) Where(ps ...predicate.CompapiJob) *CompapiJobUpdate {
- cju.mutation.Where(ps...)
- return cju
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cju *CompapiJobUpdate) SetUpdatedAt(t time.Time) *CompapiJobUpdate {
- cju.mutation.SetUpdatedAt(t)
- return cju
- }
- // SetDistAt sets the "dist_at" field.
- func (cju *CompapiJobUpdate) SetDistAt(t time.Time) *CompapiJobUpdate {
- cju.mutation.SetDistAt(t)
- return cju
- }
- // SetNillableDistAt sets the "dist_at" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableDistAt(t *time.Time) *CompapiJobUpdate {
- if t != nil {
- cju.SetDistAt(*t)
- }
- return cju
- }
- // ClearDistAt clears the value of the "dist_at" field.
- func (cju *CompapiJobUpdate) ClearDistAt() *CompapiJobUpdate {
- cju.mutation.ClearDistAt()
- return cju
- }
- // SetDistStatus sets the "dist_status" field.
- func (cju *CompapiJobUpdate) SetDistStatus(i int8) *CompapiJobUpdate {
- cju.mutation.ResetDistStatus()
- cju.mutation.SetDistStatus(i)
- return cju
- }
- // SetNillableDistStatus sets the "dist_status" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableDistStatus(i *int8) *CompapiJobUpdate {
- if i != nil {
- cju.SetDistStatus(*i)
- }
- return cju
- }
- // AddDistStatus adds i to the "dist_status" field.
- func (cju *CompapiJobUpdate) AddDistStatus(i int8) *CompapiJobUpdate {
- cju.mutation.AddDistStatus(i)
- return cju
- }
- // ClearDistStatus clears the value of the "dist_status" field.
- func (cju *CompapiJobUpdate) ClearDistStatus() *CompapiJobUpdate {
- cju.mutation.ClearDistStatus()
- return cju
- }
- // SetCallbackStatus sets the "callback_status" field.
- func (cju *CompapiJobUpdate) SetCallbackStatus(i int8) *CompapiJobUpdate {
- cju.mutation.ResetCallbackStatus()
- cju.mutation.SetCallbackStatus(i)
- return cju
- }
- // SetNillableCallbackStatus sets the "callback_status" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableCallbackStatus(i *int8) *CompapiJobUpdate {
- if i != nil {
- cju.SetCallbackStatus(*i)
- }
- return cju
- }
- // AddCallbackStatus adds i to the "callback_status" field.
- func (cju *CompapiJobUpdate) AddCallbackStatus(i int8) *CompapiJobUpdate {
- cju.mutation.AddCallbackStatus(i)
- return cju
- }
- // ClearCallbackStatus clears the value of the "callback_status" field.
- func (cju *CompapiJobUpdate) ClearCallbackStatus() *CompapiJobUpdate {
- cju.mutation.ClearCallbackStatus()
- return cju
- }
- // SetCallbackURL sets the "callback_url" field.
- func (cju *CompapiJobUpdate) SetCallbackURL(s string) *CompapiJobUpdate {
- cju.mutation.SetCallbackURL(s)
- return cju
- }
- // SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableCallbackURL(s *string) *CompapiJobUpdate {
- if s != nil {
- cju.SetCallbackURL(*s)
- }
- return cju
- }
- // SetRequestJSON sets the "request_json" field.
- func (cju *CompapiJobUpdate) SetRequestJSON(ctd custom_types.OriginalData) *CompapiJobUpdate {
- cju.mutation.SetRequestJSON(ctd)
- return cju
- }
- // SetNillableRequestJSON sets the "request_json" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableRequestJSON(ctd *custom_types.OriginalData) *CompapiJobUpdate {
- if ctd != nil {
- cju.SetRequestJSON(*ctd)
- }
- return cju
- }
- // SetAuthToken sets the "auth_token" field.
- func (cju *CompapiJobUpdate) SetAuthToken(s string) *CompapiJobUpdate {
- cju.mutation.SetAuthToken(s)
- return cju
- }
- // SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableAuthToken(s *string) *CompapiJobUpdate {
- if s != nil {
- cju.SetAuthToken(*s)
- }
- return cju
- }
- // SetEventType sets the "event_type" field.
- func (cju *CompapiJobUpdate) SetEventType(s string) *CompapiJobUpdate {
- cju.mutation.SetEventType(s)
- return cju
- }
- // SetNillableEventType sets the "event_type" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableEventType(s *string) *CompapiJobUpdate {
- if s != nil {
- cju.SetEventType(*s)
- }
- return cju
- }
- // SetWorkidIdx sets the "workid_idx" field.
- func (cju *CompapiJobUpdate) SetWorkidIdx(i int8) *CompapiJobUpdate {
- cju.mutation.ResetWorkidIdx()
- cju.mutation.SetWorkidIdx(i)
- return cju
- }
- // SetNillableWorkidIdx sets the "workid_idx" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableWorkidIdx(i *int8) *CompapiJobUpdate {
- if i != nil {
- cju.SetWorkidIdx(*i)
- }
- return cju
- }
- // AddWorkidIdx adds i to the "workid_idx" field.
- func (cju *CompapiJobUpdate) AddWorkidIdx(i int8) *CompapiJobUpdate {
- cju.mutation.AddWorkidIdx(i)
- return cju
- }
- // ClearWorkidIdx clears the value of the "workid_idx" field.
- func (cju *CompapiJobUpdate) ClearWorkidIdx() *CompapiJobUpdate {
- cju.mutation.ClearWorkidIdx()
- return cju
- }
- // SetChatID sets the "chat_id" field.
- func (cju *CompapiJobUpdate) SetChatID(s string) *CompapiJobUpdate {
- cju.mutation.SetChatID(s)
- return cju
- }
- // SetNillableChatID sets the "chat_id" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableChatID(s *string) *CompapiJobUpdate {
- if s != nil {
- cju.SetChatID(*s)
- }
- return cju
- }
- // ClearChatID clears the value of the "chat_id" field.
- func (cju *CompapiJobUpdate) ClearChatID() *CompapiJobUpdate {
- cju.mutation.ClearChatID()
- return cju
- }
- // SetRetryCount sets the "retry_count" field.
- func (cju *CompapiJobUpdate) SetRetryCount(i int8) *CompapiJobUpdate {
- cju.mutation.ResetRetryCount()
- cju.mutation.SetRetryCount(i)
- return cju
- }
- // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
- func (cju *CompapiJobUpdate) SetNillableRetryCount(i *int8) *CompapiJobUpdate {
- if i != nil {
- cju.SetRetryCount(*i)
- }
- return cju
- }
- // AddRetryCount adds i to the "retry_count" field.
- func (cju *CompapiJobUpdate) AddRetryCount(i int8) *CompapiJobUpdate {
- cju.mutation.AddRetryCount(i)
- return cju
- }
- // ClearRetryCount clears the value of the "retry_count" field.
- func (cju *CompapiJobUpdate) ClearRetryCount() *CompapiJobUpdate {
- cju.mutation.ClearRetryCount()
- return cju
- }
- // Mutation returns the CompapiJobMutation object of the builder.
- func (cju *CompapiJobUpdate) Mutation() *CompapiJobMutation {
- return cju.mutation
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (cju *CompapiJobUpdate) Save(ctx context.Context) (int, error) {
- cju.defaults()
- return withHooks(ctx, cju.sqlSave, cju.mutation, cju.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (cju *CompapiJobUpdate) SaveX(ctx context.Context) int {
- affected, err := cju.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (cju *CompapiJobUpdate) Exec(ctx context.Context) error {
- _, err := cju.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cju *CompapiJobUpdate) ExecX(ctx context.Context) {
- if err := cju.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cju *CompapiJobUpdate) defaults() {
- if _, ok := cju.mutation.UpdatedAt(); !ok {
- v := compapijob.UpdateDefaultUpdatedAt()
- cju.mutation.SetUpdatedAt(v)
- }
- }
- func (cju *CompapiJobUpdate) sqlSave(ctx context.Context) (n int, err error) {
- _spec := sqlgraph.NewUpdateSpec(compapijob.Table, compapijob.Columns, sqlgraph.NewFieldSpec(compapijob.FieldID, field.TypeUint64))
- if ps := cju.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := cju.mutation.UpdatedAt(); ok {
- _spec.SetField(compapijob.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := cju.mutation.DistAt(); ok {
- _spec.SetField(compapijob.FieldDistAt, field.TypeTime, value)
- }
- if cju.mutation.DistAtCleared() {
- _spec.ClearField(compapijob.FieldDistAt, field.TypeTime)
- }
- if value, ok := cju.mutation.DistStatus(); ok {
- _spec.SetField(compapijob.FieldDistStatus, field.TypeInt8, value)
- }
- if value, ok := cju.mutation.AddedDistStatus(); ok {
- _spec.AddField(compapijob.FieldDistStatus, field.TypeInt8, value)
- }
- if cju.mutation.DistStatusCleared() {
- _spec.ClearField(compapijob.FieldDistStatus, field.TypeInt8)
- }
- if value, ok := cju.mutation.CallbackStatus(); ok {
- _spec.SetField(compapijob.FieldCallbackStatus, field.TypeInt8, value)
- }
- if value, ok := cju.mutation.AddedCallbackStatus(); ok {
- _spec.AddField(compapijob.FieldCallbackStatus, field.TypeInt8, value)
- }
- if cju.mutation.CallbackStatusCleared() {
- _spec.ClearField(compapijob.FieldCallbackStatus, field.TypeInt8)
- }
- if value, ok := cju.mutation.CallbackURL(); ok {
- _spec.SetField(compapijob.FieldCallbackURL, field.TypeString, value)
- }
- if value, ok := cju.mutation.RequestJSON(); ok {
- _spec.SetField(compapijob.FieldRequestJSON, field.TypeJSON, value)
- }
- if value, ok := cju.mutation.AuthToken(); ok {
- _spec.SetField(compapijob.FieldAuthToken, field.TypeString, value)
- }
- if value, ok := cju.mutation.EventType(); ok {
- _spec.SetField(compapijob.FieldEventType, field.TypeString, value)
- }
- if value, ok := cju.mutation.WorkidIdx(); ok {
- _spec.SetField(compapijob.FieldWorkidIdx, field.TypeInt8, value)
- }
- if value, ok := cju.mutation.AddedWorkidIdx(); ok {
- _spec.AddField(compapijob.FieldWorkidIdx, field.TypeInt8, value)
- }
- if cju.mutation.WorkidIdxCleared() {
- _spec.ClearField(compapijob.FieldWorkidIdx, field.TypeInt8)
- }
- if value, ok := cju.mutation.ChatID(); ok {
- _spec.SetField(compapijob.FieldChatID, field.TypeString, value)
- }
- if cju.mutation.ChatIDCleared() {
- _spec.ClearField(compapijob.FieldChatID, field.TypeString)
- }
- if value, ok := cju.mutation.RetryCount(); ok {
- _spec.SetField(compapijob.FieldRetryCount, field.TypeInt8, value)
- }
- if value, ok := cju.mutation.AddedRetryCount(); ok {
- _spec.AddField(compapijob.FieldRetryCount, field.TypeInt8, value)
- }
- if cju.mutation.RetryCountCleared() {
- _spec.ClearField(compapijob.FieldRetryCount, field.TypeInt8)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, cju.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{compapijob.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- cju.mutation.done = true
- return n, nil
- }
- // CompapiJobUpdateOne is the builder for updating a single CompapiJob entity.
- type CompapiJobUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *CompapiJobMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cjuo *CompapiJobUpdateOne) SetUpdatedAt(t time.Time) *CompapiJobUpdateOne {
- cjuo.mutation.SetUpdatedAt(t)
- return cjuo
- }
- // SetDistAt sets the "dist_at" field.
- func (cjuo *CompapiJobUpdateOne) SetDistAt(t time.Time) *CompapiJobUpdateOne {
- cjuo.mutation.SetDistAt(t)
- return cjuo
- }
- // SetNillableDistAt sets the "dist_at" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableDistAt(t *time.Time) *CompapiJobUpdateOne {
- if t != nil {
- cjuo.SetDistAt(*t)
- }
- return cjuo
- }
- // ClearDistAt clears the value of the "dist_at" field.
- func (cjuo *CompapiJobUpdateOne) ClearDistAt() *CompapiJobUpdateOne {
- cjuo.mutation.ClearDistAt()
- return cjuo
- }
- // SetDistStatus sets the "dist_status" field.
- func (cjuo *CompapiJobUpdateOne) SetDistStatus(i int8) *CompapiJobUpdateOne {
- cjuo.mutation.ResetDistStatus()
- cjuo.mutation.SetDistStatus(i)
- return cjuo
- }
- // SetNillableDistStatus sets the "dist_status" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableDistStatus(i *int8) *CompapiJobUpdateOne {
- if i != nil {
- cjuo.SetDistStatus(*i)
- }
- return cjuo
- }
- // AddDistStatus adds i to the "dist_status" field.
- func (cjuo *CompapiJobUpdateOne) AddDistStatus(i int8) *CompapiJobUpdateOne {
- cjuo.mutation.AddDistStatus(i)
- return cjuo
- }
- // ClearDistStatus clears the value of the "dist_status" field.
- func (cjuo *CompapiJobUpdateOne) ClearDistStatus() *CompapiJobUpdateOne {
- cjuo.mutation.ClearDistStatus()
- return cjuo
- }
- // SetCallbackStatus sets the "callback_status" field.
- func (cjuo *CompapiJobUpdateOne) SetCallbackStatus(i int8) *CompapiJobUpdateOne {
- cjuo.mutation.ResetCallbackStatus()
- cjuo.mutation.SetCallbackStatus(i)
- return cjuo
- }
- // SetNillableCallbackStatus sets the "callback_status" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableCallbackStatus(i *int8) *CompapiJobUpdateOne {
- if i != nil {
- cjuo.SetCallbackStatus(*i)
- }
- return cjuo
- }
- // AddCallbackStatus adds i to the "callback_status" field.
- func (cjuo *CompapiJobUpdateOne) AddCallbackStatus(i int8) *CompapiJobUpdateOne {
- cjuo.mutation.AddCallbackStatus(i)
- return cjuo
- }
- // ClearCallbackStatus clears the value of the "callback_status" field.
- func (cjuo *CompapiJobUpdateOne) ClearCallbackStatus() *CompapiJobUpdateOne {
- cjuo.mutation.ClearCallbackStatus()
- return cjuo
- }
- // SetCallbackURL sets the "callback_url" field.
- func (cjuo *CompapiJobUpdateOne) SetCallbackURL(s string) *CompapiJobUpdateOne {
- cjuo.mutation.SetCallbackURL(s)
- return cjuo
- }
- // SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableCallbackURL(s *string) *CompapiJobUpdateOne {
- if s != nil {
- cjuo.SetCallbackURL(*s)
- }
- return cjuo
- }
- // SetRequestJSON sets the "request_json" field.
- func (cjuo *CompapiJobUpdateOne) SetRequestJSON(ctd custom_types.OriginalData) *CompapiJobUpdateOne {
- cjuo.mutation.SetRequestJSON(ctd)
- return cjuo
- }
- // SetNillableRequestJSON sets the "request_json" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableRequestJSON(ctd *custom_types.OriginalData) *CompapiJobUpdateOne {
- if ctd != nil {
- cjuo.SetRequestJSON(*ctd)
- }
- return cjuo
- }
- // SetAuthToken sets the "auth_token" field.
- func (cjuo *CompapiJobUpdateOne) SetAuthToken(s string) *CompapiJobUpdateOne {
- cjuo.mutation.SetAuthToken(s)
- return cjuo
- }
- // SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableAuthToken(s *string) *CompapiJobUpdateOne {
- if s != nil {
- cjuo.SetAuthToken(*s)
- }
- return cjuo
- }
- // SetEventType sets the "event_type" field.
- func (cjuo *CompapiJobUpdateOne) SetEventType(s string) *CompapiJobUpdateOne {
- cjuo.mutation.SetEventType(s)
- return cjuo
- }
- // SetNillableEventType sets the "event_type" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableEventType(s *string) *CompapiJobUpdateOne {
- if s != nil {
- cjuo.SetEventType(*s)
- }
- return cjuo
- }
- // SetWorkidIdx sets the "workid_idx" field.
- func (cjuo *CompapiJobUpdateOne) SetWorkidIdx(i int8) *CompapiJobUpdateOne {
- cjuo.mutation.ResetWorkidIdx()
- cjuo.mutation.SetWorkidIdx(i)
- return cjuo
- }
- // SetNillableWorkidIdx sets the "workid_idx" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableWorkidIdx(i *int8) *CompapiJobUpdateOne {
- if i != nil {
- cjuo.SetWorkidIdx(*i)
- }
- return cjuo
- }
- // AddWorkidIdx adds i to the "workid_idx" field.
- func (cjuo *CompapiJobUpdateOne) AddWorkidIdx(i int8) *CompapiJobUpdateOne {
- cjuo.mutation.AddWorkidIdx(i)
- return cjuo
- }
- // ClearWorkidIdx clears the value of the "workid_idx" field.
- func (cjuo *CompapiJobUpdateOne) ClearWorkidIdx() *CompapiJobUpdateOne {
- cjuo.mutation.ClearWorkidIdx()
- return cjuo
- }
- // SetChatID sets the "chat_id" field.
- func (cjuo *CompapiJobUpdateOne) SetChatID(s string) *CompapiJobUpdateOne {
- cjuo.mutation.SetChatID(s)
- return cjuo
- }
- // SetNillableChatID sets the "chat_id" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableChatID(s *string) *CompapiJobUpdateOne {
- if s != nil {
- cjuo.SetChatID(*s)
- }
- return cjuo
- }
- // ClearChatID clears the value of the "chat_id" field.
- func (cjuo *CompapiJobUpdateOne) ClearChatID() *CompapiJobUpdateOne {
- cjuo.mutation.ClearChatID()
- return cjuo
- }
- // SetRetryCount sets the "retry_count" field.
- func (cjuo *CompapiJobUpdateOne) SetRetryCount(i int8) *CompapiJobUpdateOne {
- cjuo.mutation.ResetRetryCount()
- cjuo.mutation.SetRetryCount(i)
- return cjuo
- }
- // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
- func (cjuo *CompapiJobUpdateOne) SetNillableRetryCount(i *int8) *CompapiJobUpdateOne {
- if i != nil {
- cjuo.SetRetryCount(*i)
- }
- return cjuo
- }
- // AddRetryCount adds i to the "retry_count" field.
- func (cjuo *CompapiJobUpdateOne) AddRetryCount(i int8) *CompapiJobUpdateOne {
- cjuo.mutation.AddRetryCount(i)
- return cjuo
- }
- // ClearRetryCount clears the value of the "retry_count" field.
- func (cjuo *CompapiJobUpdateOne) ClearRetryCount() *CompapiJobUpdateOne {
- cjuo.mutation.ClearRetryCount()
- return cjuo
- }
- // Mutation returns the CompapiJobMutation object of the builder.
- func (cjuo *CompapiJobUpdateOne) Mutation() *CompapiJobMutation {
- return cjuo.mutation
- }
- // Where appends a list predicates to the CompapiJobUpdate builder.
- func (cjuo *CompapiJobUpdateOne) Where(ps ...predicate.CompapiJob) *CompapiJobUpdateOne {
- cjuo.mutation.Where(ps...)
- return cjuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (cjuo *CompapiJobUpdateOne) Select(field string, fields ...string) *CompapiJobUpdateOne {
- cjuo.fields = append([]string{field}, fields...)
- return cjuo
- }
- // Save executes the query and returns the updated CompapiJob entity.
- func (cjuo *CompapiJobUpdateOne) Save(ctx context.Context) (*CompapiJob, error) {
- cjuo.defaults()
- return withHooks(ctx, cjuo.sqlSave, cjuo.mutation, cjuo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (cjuo *CompapiJobUpdateOne) SaveX(ctx context.Context) *CompapiJob {
- node, err := cjuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (cjuo *CompapiJobUpdateOne) Exec(ctx context.Context) error {
- _, err := cjuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cjuo *CompapiJobUpdateOne) ExecX(ctx context.Context) {
- if err := cjuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cjuo *CompapiJobUpdateOne) defaults() {
- if _, ok := cjuo.mutation.UpdatedAt(); !ok {
- v := compapijob.UpdateDefaultUpdatedAt()
- cjuo.mutation.SetUpdatedAt(v)
- }
- }
- func (cjuo *CompapiJobUpdateOne) sqlSave(ctx context.Context) (_node *CompapiJob, err error) {
- _spec := sqlgraph.NewUpdateSpec(compapijob.Table, compapijob.Columns, sqlgraph.NewFieldSpec(compapijob.FieldID, field.TypeUint64))
- id, ok := cjuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CompapiJob.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := cjuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, compapijob.FieldID)
- for _, f := range fields {
- if !compapijob.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != compapijob.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := cjuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := cjuo.mutation.UpdatedAt(); ok {
- _spec.SetField(compapijob.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := cjuo.mutation.DistAt(); ok {
- _spec.SetField(compapijob.FieldDistAt, field.TypeTime, value)
- }
- if cjuo.mutation.DistAtCleared() {
- _spec.ClearField(compapijob.FieldDistAt, field.TypeTime)
- }
- if value, ok := cjuo.mutation.DistStatus(); ok {
- _spec.SetField(compapijob.FieldDistStatus, field.TypeInt8, value)
- }
- if value, ok := cjuo.mutation.AddedDistStatus(); ok {
- _spec.AddField(compapijob.FieldDistStatus, field.TypeInt8, value)
- }
- if cjuo.mutation.DistStatusCleared() {
- _spec.ClearField(compapijob.FieldDistStatus, field.TypeInt8)
- }
- if value, ok := cjuo.mutation.CallbackStatus(); ok {
- _spec.SetField(compapijob.FieldCallbackStatus, field.TypeInt8, value)
- }
- if value, ok := cjuo.mutation.AddedCallbackStatus(); ok {
- _spec.AddField(compapijob.FieldCallbackStatus, field.TypeInt8, value)
- }
- if cjuo.mutation.CallbackStatusCleared() {
- _spec.ClearField(compapijob.FieldCallbackStatus, field.TypeInt8)
- }
- if value, ok := cjuo.mutation.CallbackURL(); ok {
- _spec.SetField(compapijob.FieldCallbackURL, field.TypeString, value)
- }
- if value, ok := cjuo.mutation.RequestJSON(); ok {
- _spec.SetField(compapijob.FieldRequestJSON, field.TypeJSON, value)
- }
- if value, ok := cjuo.mutation.AuthToken(); ok {
- _spec.SetField(compapijob.FieldAuthToken, field.TypeString, value)
- }
- if value, ok := cjuo.mutation.EventType(); ok {
- _spec.SetField(compapijob.FieldEventType, field.TypeString, value)
- }
- if value, ok := cjuo.mutation.WorkidIdx(); ok {
- _spec.SetField(compapijob.FieldWorkidIdx, field.TypeInt8, value)
- }
- if value, ok := cjuo.mutation.AddedWorkidIdx(); ok {
- _spec.AddField(compapijob.FieldWorkidIdx, field.TypeInt8, value)
- }
- if cjuo.mutation.WorkidIdxCleared() {
- _spec.ClearField(compapijob.FieldWorkidIdx, field.TypeInt8)
- }
- if value, ok := cjuo.mutation.ChatID(); ok {
- _spec.SetField(compapijob.FieldChatID, field.TypeString, value)
- }
- if cjuo.mutation.ChatIDCleared() {
- _spec.ClearField(compapijob.FieldChatID, field.TypeString)
- }
- if value, ok := cjuo.mutation.RetryCount(); ok {
- _spec.SetField(compapijob.FieldRetryCount, field.TypeInt8, value)
- }
- if value, ok := cjuo.mutation.AddedRetryCount(); ok {
- _spec.AddField(compapijob.FieldRetryCount, field.TypeInt8, value)
- }
- if cjuo.mutation.RetryCountCleared() {
- _spec.ClearField(compapijob.FieldRetryCount, field.TypeInt8)
- }
- _node = &CompapiJob{config: cjuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, cjuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{compapijob.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- cjuo.mutation.done = true
- return _node, nil
- }
|