// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "wechat-api/ent/predicate" "wechat-api/ent/wxcard" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // WxCardUpdate is the builder for updating WxCard entities. type WxCardUpdate struct { config hooks []Hook mutation *WxCardMutation } // Where appends a list predicates to the WxCardUpdate builder. func (wcu *WxCardUpdate) Where(ps ...predicate.WxCard) *WxCardUpdate { wcu.mutation.Where(ps...) return wcu } // SetUpdatedAt sets the "updated_at" field. func (wcu *WxCardUpdate) SetUpdatedAt(t time.Time) *WxCardUpdate { wcu.mutation.SetUpdatedAt(t) return wcu } // SetDeletedAt sets the "deleted_at" field. func (wcu *WxCardUpdate) SetDeletedAt(t time.Time) *WxCardUpdate { wcu.mutation.SetDeletedAt(t) return wcu } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableDeletedAt(t *time.Time) *WxCardUpdate { if t != nil { wcu.SetDeletedAt(*t) } return wcu } // ClearDeletedAt clears the value of the "deleted_at" field. func (wcu *WxCardUpdate) ClearDeletedAt() *WxCardUpdate { wcu.mutation.ClearDeletedAt() return wcu } // SetUserID sets the "user_id" field. func (wcu *WxCardUpdate) SetUserID(u uint64) *WxCardUpdate { wcu.mutation.ResetUserID() wcu.mutation.SetUserID(u) return wcu } // SetNillableUserID sets the "user_id" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableUserID(u *uint64) *WxCardUpdate { if u != nil { wcu.SetUserID(*u) } return wcu } // AddUserID adds u to the "user_id" field. func (wcu *WxCardUpdate) AddUserID(u int64) *WxCardUpdate { wcu.mutation.AddUserID(u) return wcu } // ClearUserID clears the value of the "user_id" field. func (wcu *WxCardUpdate) ClearUserID() *WxCardUpdate { wcu.mutation.ClearUserID() return wcu } // SetWxUserID sets the "wx_user_id" field. func (wcu *WxCardUpdate) SetWxUserID(u uint64) *WxCardUpdate { wcu.mutation.ResetWxUserID() wcu.mutation.SetWxUserID(u) return wcu } // SetNillableWxUserID sets the "wx_user_id" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableWxUserID(u *uint64) *WxCardUpdate { if u != nil { wcu.SetWxUserID(*u) } return wcu } // AddWxUserID adds u to the "wx_user_id" field. func (wcu *WxCardUpdate) AddWxUserID(u int64) *WxCardUpdate { wcu.mutation.AddWxUserID(u) return wcu } // ClearWxUserID clears the value of the "wx_user_id" field. func (wcu *WxCardUpdate) ClearWxUserID() *WxCardUpdate { wcu.mutation.ClearWxUserID() return wcu } // SetAvatar sets the "avatar" field. func (wcu *WxCardUpdate) SetAvatar(s string) *WxCardUpdate { wcu.mutation.SetAvatar(s) return wcu } // SetNillableAvatar sets the "avatar" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableAvatar(s *string) *WxCardUpdate { if s != nil { wcu.SetAvatar(*s) } return wcu } // SetLogo sets the "logo" field. func (wcu *WxCardUpdate) SetLogo(s string) *WxCardUpdate { wcu.mutation.SetLogo(s) return wcu } // SetNillableLogo sets the "logo" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableLogo(s *string) *WxCardUpdate { if s != nil { wcu.SetLogo(*s) } return wcu } // SetName sets the "name" field. func (wcu *WxCardUpdate) SetName(s string) *WxCardUpdate { wcu.mutation.SetName(s) return wcu } // SetNillableName sets the "name" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableName(s *string) *WxCardUpdate { if s != nil { wcu.SetName(*s) } return wcu } // SetCompany sets the "company" field. func (wcu *WxCardUpdate) SetCompany(s string) *WxCardUpdate { wcu.mutation.SetCompany(s) return wcu } // SetNillableCompany sets the "company" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableCompany(s *string) *WxCardUpdate { if s != nil { wcu.SetCompany(*s) } return wcu } // SetAddress sets the "address" field. func (wcu *WxCardUpdate) SetAddress(s string) *WxCardUpdate { wcu.mutation.SetAddress(s) return wcu } // SetNillableAddress sets the "address" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableAddress(s *string) *WxCardUpdate { if s != nil { wcu.SetAddress(*s) } return wcu } // SetPhone sets the "phone" field. func (wcu *WxCardUpdate) SetPhone(s string) *WxCardUpdate { wcu.mutation.SetPhone(s) return wcu } // SetNillablePhone sets the "phone" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillablePhone(s *string) *WxCardUpdate { if s != nil { wcu.SetPhone(*s) } return wcu } // SetOfficialAccount sets the "official_account" field. func (wcu *WxCardUpdate) SetOfficialAccount(s string) *WxCardUpdate { wcu.mutation.SetOfficialAccount(s) return wcu } // SetNillableOfficialAccount sets the "official_account" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableOfficialAccount(s *string) *WxCardUpdate { if s != nil { wcu.SetOfficialAccount(*s) } return wcu } // SetWechatAccount sets the "wechat_account" field. func (wcu *WxCardUpdate) SetWechatAccount(s string) *WxCardUpdate { wcu.mutation.SetWechatAccount(s) return wcu } // SetNillableWechatAccount sets the "wechat_account" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableWechatAccount(s *string) *WxCardUpdate { if s != nil { wcu.SetWechatAccount(*s) } return wcu } // SetEmail sets the "email" field. func (wcu *WxCardUpdate) SetEmail(s string) *WxCardUpdate { wcu.mutation.SetEmail(s) return wcu } // SetNillableEmail sets the "email" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableEmail(s *string) *WxCardUpdate { if s != nil { wcu.SetEmail(*s) } return wcu } // ClearEmail clears the value of the "email" field. func (wcu *WxCardUpdate) ClearEmail() *WxCardUpdate { wcu.mutation.ClearEmail() return wcu } // SetAPIBase sets the "api_base" field. func (wcu *WxCardUpdate) SetAPIBase(s string) *WxCardUpdate { wcu.mutation.SetAPIBase(s) return wcu } // SetNillableAPIBase sets the "api_base" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableAPIBase(s *string) *WxCardUpdate { if s != nil { wcu.SetAPIBase(*s) } return wcu } // ClearAPIBase clears the value of the "api_base" field. func (wcu *WxCardUpdate) ClearAPIBase() *WxCardUpdate { wcu.mutation.ClearAPIBase() return wcu } // SetAPIKey sets the "api_key" field. func (wcu *WxCardUpdate) SetAPIKey(s string) *WxCardUpdate { wcu.mutation.SetAPIKey(s) return wcu } // SetNillableAPIKey sets the "api_key" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableAPIKey(s *string) *WxCardUpdate { if s != nil { wcu.SetAPIKey(*s) } return wcu } // ClearAPIKey clears the value of the "api_key" field. func (wcu *WxCardUpdate) ClearAPIKey() *WxCardUpdate { wcu.mutation.ClearAPIKey() return wcu } // SetAiInfo sets the "ai_info" field. func (wcu *WxCardUpdate) SetAiInfo(s string) *WxCardUpdate { wcu.mutation.SetAiInfo(s) return wcu } // SetNillableAiInfo sets the "ai_info" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableAiInfo(s *string) *WxCardUpdate { if s != nil { wcu.SetAiInfo(*s) } return wcu } // ClearAiInfo clears the value of the "ai_info" field. func (wcu *WxCardUpdate) ClearAiInfo() *WxCardUpdate { wcu.mutation.ClearAiInfo() return wcu } // SetIntro sets the "intro" field. func (wcu *WxCardUpdate) SetIntro(s string) *WxCardUpdate { wcu.mutation.SetIntro(s) return wcu } // SetNillableIntro sets the "intro" field if the given value is not nil. func (wcu *WxCardUpdate) SetNillableIntro(s *string) *WxCardUpdate { if s != nil { wcu.SetIntro(*s) } return wcu } // ClearIntro clears the value of the "intro" field. func (wcu *WxCardUpdate) ClearIntro() *WxCardUpdate { wcu.mutation.ClearIntro() return wcu } // Mutation returns the WxCardMutation object of the builder. func (wcu *WxCardUpdate) Mutation() *WxCardMutation { return wcu.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (wcu *WxCardUpdate) Save(ctx context.Context) (int, error) { if err := wcu.defaults(); err != nil { return 0, err } return withHooks(ctx, wcu.sqlSave, wcu.mutation, wcu.hooks) } // SaveX is like Save, but panics if an error occurs. func (wcu *WxCardUpdate) SaveX(ctx context.Context) int { affected, err := wcu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (wcu *WxCardUpdate) Exec(ctx context.Context) error { _, err := wcu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (wcu *WxCardUpdate) ExecX(ctx context.Context) { if err := wcu.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (wcu *WxCardUpdate) defaults() error { if _, ok := wcu.mutation.UpdatedAt(); !ok { if wxcard.UpdateDefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized wxcard.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") } v := wxcard.UpdateDefaultUpdatedAt() wcu.mutation.SetUpdatedAt(v) } return nil } func (wcu *WxCardUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := sqlgraph.NewUpdateSpec(wxcard.Table, wxcard.Columns, sqlgraph.NewFieldSpec(wxcard.FieldID, field.TypeUint64)) if ps := wcu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := wcu.mutation.UpdatedAt(); ok { _spec.SetField(wxcard.FieldUpdatedAt, field.TypeTime, value) } if value, ok := wcu.mutation.DeletedAt(); ok { _spec.SetField(wxcard.FieldDeletedAt, field.TypeTime, value) } if wcu.mutation.DeletedAtCleared() { _spec.ClearField(wxcard.FieldDeletedAt, field.TypeTime) } if value, ok := wcu.mutation.UserID(); ok { _spec.SetField(wxcard.FieldUserID, field.TypeUint64, value) } if value, ok := wcu.mutation.AddedUserID(); ok { _spec.AddField(wxcard.FieldUserID, field.TypeUint64, value) } if wcu.mutation.UserIDCleared() { _spec.ClearField(wxcard.FieldUserID, field.TypeUint64) } if value, ok := wcu.mutation.WxUserID(); ok { _spec.SetField(wxcard.FieldWxUserID, field.TypeUint64, value) } if value, ok := wcu.mutation.AddedWxUserID(); ok { _spec.AddField(wxcard.FieldWxUserID, field.TypeUint64, value) } if wcu.mutation.WxUserIDCleared() { _spec.ClearField(wxcard.FieldWxUserID, field.TypeUint64) } if value, ok := wcu.mutation.Avatar(); ok { _spec.SetField(wxcard.FieldAvatar, field.TypeString, value) } if value, ok := wcu.mutation.Logo(); ok { _spec.SetField(wxcard.FieldLogo, field.TypeString, value) } if value, ok := wcu.mutation.Name(); ok { _spec.SetField(wxcard.FieldName, field.TypeString, value) } if value, ok := wcu.mutation.Company(); ok { _spec.SetField(wxcard.FieldCompany, field.TypeString, value) } if value, ok := wcu.mutation.Address(); ok { _spec.SetField(wxcard.FieldAddress, field.TypeString, value) } if value, ok := wcu.mutation.Phone(); ok { _spec.SetField(wxcard.FieldPhone, field.TypeString, value) } if value, ok := wcu.mutation.OfficialAccount(); ok { _spec.SetField(wxcard.FieldOfficialAccount, field.TypeString, value) } if value, ok := wcu.mutation.WechatAccount(); ok { _spec.SetField(wxcard.FieldWechatAccount, field.TypeString, value) } if value, ok := wcu.mutation.Email(); ok { _spec.SetField(wxcard.FieldEmail, field.TypeString, value) } if wcu.mutation.EmailCleared() { _spec.ClearField(wxcard.FieldEmail, field.TypeString) } if value, ok := wcu.mutation.APIBase(); ok { _spec.SetField(wxcard.FieldAPIBase, field.TypeString, value) } if wcu.mutation.APIBaseCleared() { _spec.ClearField(wxcard.FieldAPIBase, field.TypeString) } if value, ok := wcu.mutation.APIKey(); ok { _spec.SetField(wxcard.FieldAPIKey, field.TypeString, value) } if wcu.mutation.APIKeyCleared() { _spec.ClearField(wxcard.FieldAPIKey, field.TypeString) } if value, ok := wcu.mutation.AiInfo(); ok { _spec.SetField(wxcard.FieldAiInfo, field.TypeString, value) } if wcu.mutation.AiInfoCleared() { _spec.ClearField(wxcard.FieldAiInfo, field.TypeString) } if value, ok := wcu.mutation.Intro(); ok { _spec.SetField(wxcard.FieldIntro, field.TypeString, value) } if wcu.mutation.IntroCleared() { _spec.ClearField(wxcard.FieldIntro, field.TypeString) } if n, err = sqlgraph.UpdateNodes(ctx, wcu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{wxcard.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } wcu.mutation.done = true return n, nil } // WxCardUpdateOne is the builder for updating a single WxCard entity. type WxCardUpdateOne struct { config fields []string hooks []Hook mutation *WxCardMutation } // SetUpdatedAt sets the "updated_at" field. func (wcuo *WxCardUpdateOne) SetUpdatedAt(t time.Time) *WxCardUpdateOne { wcuo.mutation.SetUpdatedAt(t) return wcuo } // SetDeletedAt sets the "deleted_at" field. func (wcuo *WxCardUpdateOne) SetDeletedAt(t time.Time) *WxCardUpdateOne { wcuo.mutation.SetDeletedAt(t) return wcuo } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableDeletedAt(t *time.Time) *WxCardUpdateOne { if t != nil { wcuo.SetDeletedAt(*t) } return wcuo } // ClearDeletedAt clears the value of the "deleted_at" field. func (wcuo *WxCardUpdateOne) ClearDeletedAt() *WxCardUpdateOne { wcuo.mutation.ClearDeletedAt() return wcuo } // SetUserID sets the "user_id" field. func (wcuo *WxCardUpdateOne) SetUserID(u uint64) *WxCardUpdateOne { wcuo.mutation.ResetUserID() wcuo.mutation.SetUserID(u) return wcuo } // SetNillableUserID sets the "user_id" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableUserID(u *uint64) *WxCardUpdateOne { if u != nil { wcuo.SetUserID(*u) } return wcuo } // AddUserID adds u to the "user_id" field. func (wcuo *WxCardUpdateOne) AddUserID(u int64) *WxCardUpdateOne { wcuo.mutation.AddUserID(u) return wcuo } // ClearUserID clears the value of the "user_id" field. func (wcuo *WxCardUpdateOne) ClearUserID() *WxCardUpdateOne { wcuo.mutation.ClearUserID() return wcuo } // SetWxUserID sets the "wx_user_id" field. func (wcuo *WxCardUpdateOne) SetWxUserID(u uint64) *WxCardUpdateOne { wcuo.mutation.ResetWxUserID() wcuo.mutation.SetWxUserID(u) return wcuo } // SetNillableWxUserID sets the "wx_user_id" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableWxUserID(u *uint64) *WxCardUpdateOne { if u != nil { wcuo.SetWxUserID(*u) } return wcuo } // AddWxUserID adds u to the "wx_user_id" field. func (wcuo *WxCardUpdateOne) AddWxUserID(u int64) *WxCardUpdateOne { wcuo.mutation.AddWxUserID(u) return wcuo } // ClearWxUserID clears the value of the "wx_user_id" field. func (wcuo *WxCardUpdateOne) ClearWxUserID() *WxCardUpdateOne { wcuo.mutation.ClearWxUserID() return wcuo } // SetAvatar sets the "avatar" field. func (wcuo *WxCardUpdateOne) SetAvatar(s string) *WxCardUpdateOne { wcuo.mutation.SetAvatar(s) return wcuo } // SetNillableAvatar sets the "avatar" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableAvatar(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetAvatar(*s) } return wcuo } // SetLogo sets the "logo" field. func (wcuo *WxCardUpdateOne) SetLogo(s string) *WxCardUpdateOne { wcuo.mutation.SetLogo(s) return wcuo } // SetNillableLogo sets the "logo" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableLogo(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetLogo(*s) } return wcuo } // SetName sets the "name" field. func (wcuo *WxCardUpdateOne) SetName(s string) *WxCardUpdateOne { wcuo.mutation.SetName(s) return wcuo } // SetNillableName sets the "name" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableName(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetName(*s) } return wcuo } // SetCompany sets the "company" field. func (wcuo *WxCardUpdateOne) SetCompany(s string) *WxCardUpdateOne { wcuo.mutation.SetCompany(s) return wcuo } // SetNillableCompany sets the "company" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableCompany(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetCompany(*s) } return wcuo } // SetAddress sets the "address" field. func (wcuo *WxCardUpdateOne) SetAddress(s string) *WxCardUpdateOne { wcuo.mutation.SetAddress(s) return wcuo } // SetNillableAddress sets the "address" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableAddress(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetAddress(*s) } return wcuo } // SetPhone sets the "phone" field. func (wcuo *WxCardUpdateOne) SetPhone(s string) *WxCardUpdateOne { wcuo.mutation.SetPhone(s) return wcuo } // SetNillablePhone sets the "phone" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillablePhone(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetPhone(*s) } return wcuo } // SetOfficialAccount sets the "official_account" field. func (wcuo *WxCardUpdateOne) SetOfficialAccount(s string) *WxCardUpdateOne { wcuo.mutation.SetOfficialAccount(s) return wcuo } // SetNillableOfficialAccount sets the "official_account" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableOfficialAccount(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetOfficialAccount(*s) } return wcuo } // SetWechatAccount sets the "wechat_account" field. func (wcuo *WxCardUpdateOne) SetWechatAccount(s string) *WxCardUpdateOne { wcuo.mutation.SetWechatAccount(s) return wcuo } // SetNillableWechatAccount sets the "wechat_account" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableWechatAccount(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetWechatAccount(*s) } return wcuo } // SetEmail sets the "email" field. func (wcuo *WxCardUpdateOne) SetEmail(s string) *WxCardUpdateOne { wcuo.mutation.SetEmail(s) return wcuo } // SetNillableEmail sets the "email" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableEmail(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetEmail(*s) } return wcuo } // ClearEmail clears the value of the "email" field. func (wcuo *WxCardUpdateOne) ClearEmail() *WxCardUpdateOne { wcuo.mutation.ClearEmail() return wcuo } // SetAPIBase sets the "api_base" field. func (wcuo *WxCardUpdateOne) SetAPIBase(s string) *WxCardUpdateOne { wcuo.mutation.SetAPIBase(s) return wcuo } // SetNillableAPIBase sets the "api_base" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableAPIBase(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetAPIBase(*s) } return wcuo } // ClearAPIBase clears the value of the "api_base" field. func (wcuo *WxCardUpdateOne) ClearAPIBase() *WxCardUpdateOne { wcuo.mutation.ClearAPIBase() return wcuo } // SetAPIKey sets the "api_key" field. func (wcuo *WxCardUpdateOne) SetAPIKey(s string) *WxCardUpdateOne { wcuo.mutation.SetAPIKey(s) return wcuo } // SetNillableAPIKey sets the "api_key" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableAPIKey(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetAPIKey(*s) } return wcuo } // ClearAPIKey clears the value of the "api_key" field. func (wcuo *WxCardUpdateOne) ClearAPIKey() *WxCardUpdateOne { wcuo.mutation.ClearAPIKey() return wcuo } // SetAiInfo sets the "ai_info" field. func (wcuo *WxCardUpdateOne) SetAiInfo(s string) *WxCardUpdateOne { wcuo.mutation.SetAiInfo(s) return wcuo } // SetNillableAiInfo sets the "ai_info" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableAiInfo(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetAiInfo(*s) } return wcuo } // ClearAiInfo clears the value of the "ai_info" field. func (wcuo *WxCardUpdateOne) ClearAiInfo() *WxCardUpdateOne { wcuo.mutation.ClearAiInfo() return wcuo } // SetIntro sets the "intro" field. func (wcuo *WxCardUpdateOne) SetIntro(s string) *WxCardUpdateOne { wcuo.mutation.SetIntro(s) return wcuo } // SetNillableIntro sets the "intro" field if the given value is not nil. func (wcuo *WxCardUpdateOne) SetNillableIntro(s *string) *WxCardUpdateOne { if s != nil { wcuo.SetIntro(*s) } return wcuo } // ClearIntro clears the value of the "intro" field. func (wcuo *WxCardUpdateOne) ClearIntro() *WxCardUpdateOne { wcuo.mutation.ClearIntro() return wcuo } // Mutation returns the WxCardMutation object of the builder. func (wcuo *WxCardUpdateOne) Mutation() *WxCardMutation { return wcuo.mutation } // Where appends a list predicates to the WxCardUpdate builder. func (wcuo *WxCardUpdateOne) Where(ps ...predicate.WxCard) *WxCardUpdateOne { wcuo.mutation.Where(ps...) return wcuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (wcuo *WxCardUpdateOne) Select(field string, fields ...string) *WxCardUpdateOne { wcuo.fields = append([]string{field}, fields...) return wcuo } // Save executes the query and returns the updated WxCard entity. func (wcuo *WxCardUpdateOne) Save(ctx context.Context) (*WxCard, error) { if err := wcuo.defaults(); err != nil { return nil, err } return withHooks(ctx, wcuo.sqlSave, wcuo.mutation, wcuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (wcuo *WxCardUpdateOne) SaveX(ctx context.Context) *WxCard { node, err := wcuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (wcuo *WxCardUpdateOne) Exec(ctx context.Context) error { _, err := wcuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (wcuo *WxCardUpdateOne) ExecX(ctx context.Context) { if err := wcuo.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (wcuo *WxCardUpdateOne) defaults() error { if _, ok := wcuo.mutation.UpdatedAt(); !ok { if wxcard.UpdateDefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized wxcard.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") } v := wxcard.UpdateDefaultUpdatedAt() wcuo.mutation.SetUpdatedAt(v) } return nil } func (wcuo *WxCardUpdateOne) sqlSave(ctx context.Context) (_node *WxCard, err error) { _spec := sqlgraph.NewUpdateSpec(wxcard.Table, wxcard.Columns, sqlgraph.NewFieldSpec(wxcard.FieldID, field.TypeUint64)) id, ok := wcuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WxCard.id" for update`)} } _spec.Node.ID.Value = id if fields := wcuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, wxcard.FieldID) for _, f := range fields { if !wxcard.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != wxcard.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := wcuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := wcuo.mutation.UpdatedAt(); ok { _spec.SetField(wxcard.FieldUpdatedAt, field.TypeTime, value) } if value, ok := wcuo.mutation.DeletedAt(); ok { _spec.SetField(wxcard.FieldDeletedAt, field.TypeTime, value) } if wcuo.mutation.DeletedAtCleared() { _spec.ClearField(wxcard.FieldDeletedAt, field.TypeTime) } if value, ok := wcuo.mutation.UserID(); ok { _spec.SetField(wxcard.FieldUserID, field.TypeUint64, value) } if value, ok := wcuo.mutation.AddedUserID(); ok { _spec.AddField(wxcard.FieldUserID, field.TypeUint64, value) } if wcuo.mutation.UserIDCleared() { _spec.ClearField(wxcard.FieldUserID, field.TypeUint64) } if value, ok := wcuo.mutation.WxUserID(); ok { _spec.SetField(wxcard.FieldWxUserID, field.TypeUint64, value) } if value, ok := wcuo.mutation.AddedWxUserID(); ok { _spec.AddField(wxcard.FieldWxUserID, field.TypeUint64, value) } if wcuo.mutation.WxUserIDCleared() { _spec.ClearField(wxcard.FieldWxUserID, field.TypeUint64) } if value, ok := wcuo.mutation.Avatar(); ok { _spec.SetField(wxcard.FieldAvatar, field.TypeString, value) } if value, ok := wcuo.mutation.Logo(); ok { _spec.SetField(wxcard.FieldLogo, field.TypeString, value) } if value, ok := wcuo.mutation.Name(); ok { _spec.SetField(wxcard.FieldName, field.TypeString, value) } if value, ok := wcuo.mutation.Company(); ok { _spec.SetField(wxcard.FieldCompany, field.TypeString, value) } if value, ok := wcuo.mutation.Address(); ok { _spec.SetField(wxcard.FieldAddress, field.TypeString, value) } if value, ok := wcuo.mutation.Phone(); ok { _spec.SetField(wxcard.FieldPhone, field.TypeString, value) } if value, ok := wcuo.mutation.OfficialAccount(); ok { _spec.SetField(wxcard.FieldOfficialAccount, field.TypeString, value) } if value, ok := wcuo.mutation.WechatAccount(); ok { _spec.SetField(wxcard.FieldWechatAccount, field.TypeString, value) } if value, ok := wcuo.mutation.Email(); ok { _spec.SetField(wxcard.FieldEmail, field.TypeString, value) } if wcuo.mutation.EmailCleared() { _spec.ClearField(wxcard.FieldEmail, field.TypeString) } if value, ok := wcuo.mutation.APIBase(); ok { _spec.SetField(wxcard.FieldAPIBase, field.TypeString, value) } if wcuo.mutation.APIBaseCleared() { _spec.ClearField(wxcard.FieldAPIBase, field.TypeString) } if value, ok := wcuo.mutation.APIKey(); ok { _spec.SetField(wxcard.FieldAPIKey, field.TypeString, value) } if wcuo.mutation.APIKeyCleared() { _spec.ClearField(wxcard.FieldAPIKey, field.TypeString) } if value, ok := wcuo.mutation.AiInfo(); ok { _spec.SetField(wxcard.FieldAiInfo, field.TypeString, value) } if wcuo.mutation.AiInfoCleared() { _spec.ClearField(wxcard.FieldAiInfo, field.TypeString) } if value, ok := wcuo.mutation.Intro(); ok { _spec.SetField(wxcard.FieldIntro, field.TypeString, value) } if wcuo.mutation.IntroCleared() { _spec.ClearField(wxcard.FieldIntro, field.TypeString) } _node = &WxCard{config: wcuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, wcuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{wxcard.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } wcuo.mutation.done = true return _node, nil }