123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/contact"
- "wechat-api/ent/predicate"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // ContactUpdate is the builder for updating Contact entities.
- type ContactUpdate struct {
- config
- hooks []Hook
- mutation *ContactMutation
- }
- // Where appends a list predicates to the ContactUpdate builder.
- func (cu *ContactUpdate) Where(ps ...predicate.Contact) *ContactUpdate {
- cu.mutation.Where(ps...)
- return cu
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cu *ContactUpdate) SetUpdatedAt(t time.Time) *ContactUpdate {
- cu.mutation.SetUpdatedAt(t)
- return cu
- }
- // SetStatus sets the "status" field.
- func (cu *ContactUpdate) SetStatus(u uint8) *ContactUpdate {
- cu.mutation.ResetStatus()
- cu.mutation.SetStatus(u)
- return cu
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableStatus(u *uint8) *ContactUpdate {
- if u != nil {
- cu.SetStatus(*u)
- }
- return cu
- }
- // AddStatus adds u to the "status" field.
- func (cu *ContactUpdate) AddStatus(u int8) *ContactUpdate {
- cu.mutation.AddStatus(u)
- return cu
- }
- // ClearStatus clears the value of the "status" field.
- func (cu *ContactUpdate) ClearStatus() *ContactUpdate {
- cu.mutation.ClearStatus()
- return cu
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (cu *ContactUpdate) SetDeletedAt(t time.Time) *ContactUpdate {
- cu.mutation.SetDeletedAt(t)
- return cu
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableDeletedAt(t *time.Time) *ContactUpdate {
- if t != nil {
- cu.SetDeletedAt(*t)
- }
- return cu
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (cu *ContactUpdate) ClearDeletedAt() *ContactUpdate {
- cu.mutation.ClearDeletedAt()
- return cu
- }
- // SetWxWxid sets the "wx_wxid" field.
- func (cu *ContactUpdate) SetWxWxid(s string) *ContactUpdate {
- cu.mutation.SetWxWxid(s)
- return cu
- }
- // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableWxWxid(s *string) *ContactUpdate {
- if s != nil {
- cu.SetWxWxid(*s)
- }
- return cu
- }
- // ClearWxWxid clears the value of the "wx_wxid" field.
- func (cu *ContactUpdate) ClearWxWxid() *ContactUpdate {
- cu.mutation.ClearWxWxid()
- return cu
- }
- // SetType sets the "type" field.
- func (cu *ContactUpdate) SetType(i int) *ContactUpdate {
- cu.mutation.ResetType()
- cu.mutation.SetType(i)
- return cu
- }
- // SetNillableType sets the "type" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableType(i *int) *ContactUpdate {
- if i != nil {
- cu.SetType(*i)
- }
- return cu
- }
- // AddType adds i to the "type" field.
- func (cu *ContactUpdate) AddType(i int) *ContactUpdate {
- cu.mutation.AddType(i)
- return cu
- }
- // ClearType clears the value of the "type" field.
- func (cu *ContactUpdate) ClearType() *ContactUpdate {
- cu.mutation.ClearType()
- return cu
- }
- // SetWxid sets the "wxid" field.
- func (cu *ContactUpdate) SetWxid(s string) *ContactUpdate {
- cu.mutation.SetWxid(s)
- return cu
- }
- // SetNillableWxid sets the "wxid" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableWxid(s *string) *ContactUpdate {
- if s != nil {
- cu.SetWxid(*s)
- }
- return cu
- }
- // SetAccount sets the "account" field.
- func (cu *ContactUpdate) SetAccount(s string) *ContactUpdate {
- cu.mutation.SetAccount(s)
- return cu
- }
- // SetNillableAccount sets the "account" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableAccount(s *string) *ContactUpdate {
- if s != nil {
- cu.SetAccount(*s)
- }
- return cu
- }
- // SetNickname sets the "nickname" field.
- func (cu *ContactUpdate) SetNickname(s string) *ContactUpdate {
- cu.mutation.SetNickname(s)
- return cu
- }
- // SetNillableNickname sets the "nickname" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableNickname(s *string) *ContactUpdate {
- if s != nil {
- cu.SetNickname(*s)
- }
- return cu
- }
- // SetMarkname sets the "markname" field.
- func (cu *ContactUpdate) SetMarkname(s string) *ContactUpdate {
- cu.mutation.SetMarkname(s)
- return cu
- }
- // SetNillableMarkname sets the "markname" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableMarkname(s *string) *ContactUpdate {
- if s != nil {
- cu.SetMarkname(*s)
- }
- return cu
- }
- // SetHeadimg sets the "headimg" field.
- func (cu *ContactUpdate) SetHeadimg(s string) *ContactUpdate {
- cu.mutation.SetHeadimg(s)
- return cu
- }
- // SetNillableHeadimg sets the "headimg" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableHeadimg(s *string) *ContactUpdate {
- if s != nil {
- cu.SetHeadimg(*s)
- }
- return cu
- }
- // SetSex sets the "sex" field.
- func (cu *ContactUpdate) SetSex(i int) *ContactUpdate {
- cu.mutation.ResetSex()
- cu.mutation.SetSex(i)
- return cu
- }
- // SetNillableSex sets the "sex" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableSex(i *int) *ContactUpdate {
- if i != nil {
- cu.SetSex(*i)
- }
- return cu
- }
- // AddSex adds i to the "sex" field.
- func (cu *ContactUpdate) AddSex(i int) *ContactUpdate {
- cu.mutation.AddSex(i)
- return cu
- }
- // SetStarrole sets the "starrole" field.
- func (cu *ContactUpdate) SetStarrole(s string) *ContactUpdate {
- cu.mutation.SetStarrole(s)
- return cu
- }
- // SetNillableStarrole sets the "starrole" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableStarrole(s *string) *ContactUpdate {
- if s != nil {
- cu.SetStarrole(*s)
- }
- return cu
- }
- // SetDontseeit sets the "dontseeit" field.
- func (cu *ContactUpdate) SetDontseeit(i int) *ContactUpdate {
- cu.mutation.ResetDontseeit()
- cu.mutation.SetDontseeit(i)
- return cu
- }
- // SetNillableDontseeit sets the "dontseeit" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableDontseeit(i *int) *ContactUpdate {
- if i != nil {
- cu.SetDontseeit(*i)
- }
- return cu
- }
- // AddDontseeit adds i to the "dontseeit" field.
- func (cu *ContactUpdate) AddDontseeit(i int) *ContactUpdate {
- cu.mutation.AddDontseeit(i)
- return cu
- }
- // SetDontseeme sets the "dontseeme" field.
- func (cu *ContactUpdate) SetDontseeme(i int) *ContactUpdate {
- cu.mutation.ResetDontseeme()
- cu.mutation.SetDontseeme(i)
- return cu
- }
- // SetNillableDontseeme sets the "dontseeme" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableDontseeme(i *int) *ContactUpdate {
- if i != nil {
- cu.SetDontseeme(*i)
- }
- return cu
- }
- // AddDontseeme adds i to the "dontseeme" field.
- func (cu *ContactUpdate) AddDontseeme(i int) *ContactUpdate {
- cu.mutation.AddDontseeme(i)
- return cu
- }
- // SetLag sets the "lag" field.
- func (cu *ContactUpdate) SetLag(s string) *ContactUpdate {
- cu.mutation.SetLag(s)
- return cu
- }
- // SetNillableLag sets the "lag" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableLag(s *string) *ContactUpdate {
- if s != nil {
- cu.SetLag(*s)
- }
- return cu
- }
- // SetGid sets the "gid" field.
- func (cu *ContactUpdate) SetGid(s string) *ContactUpdate {
- cu.mutation.SetGid(s)
- return cu
- }
- // SetNillableGid sets the "gid" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableGid(s *string) *ContactUpdate {
- if s != nil {
- cu.SetGid(*s)
- }
- return cu
- }
- // SetGname sets the "gname" field.
- func (cu *ContactUpdate) SetGname(s string) *ContactUpdate {
- cu.mutation.SetGname(s)
- return cu
- }
- // SetNillableGname sets the "gname" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableGname(s *string) *ContactUpdate {
- if s != nil {
- cu.SetGname(*s)
- }
- return cu
- }
- // SetV3 sets the "v3" field.
- func (cu *ContactUpdate) SetV3(s string) *ContactUpdate {
- cu.mutation.SetV3(s)
- return cu
- }
- // SetNillableV3 sets the "v3" field if the given value is not nil.
- func (cu *ContactUpdate) SetNillableV3(s *string) *ContactUpdate {
- if s != nil {
- cu.SetV3(*s)
- }
- return cu
- }
- // Mutation returns the ContactMutation object of the builder.
- func (cu *ContactUpdate) Mutation() *ContactMutation {
- return cu.mutation
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (cu *ContactUpdate) Save(ctx context.Context) (int, error) {
- if err := cu.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (cu *ContactUpdate) SaveX(ctx context.Context) int {
- affected, err := cu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (cu *ContactUpdate) Exec(ctx context.Context) error {
- _, err := cu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cu *ContactUpdate) ExecX(ctx context.Context) {
- if err := cu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cu *ContactUpdate) defaults() error {
- if _, ok := cu.mutation.UpdatedAt(); !ok {
- if contact.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized contact.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := contact.UpdateDefaultUpdatedAt()
- cu.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- func (cu *ContactUpdate) sqlSave(ctx context.Context) (n int, err error) {
- _spec := sqlgraph.NewUpdateSpec(contact.Table, contact.Columns, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64))
- if ps := cu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := cu.mutation.UpdatedAt(); ok {
- _spec.SetField(contact.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := cu.mutation.Status(); ok {
- _spec.SetField(contact.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := cu.mutation.AddedStatus(); ok {
- _spec.AddField(contact.FieldStatus, field.TypeUint8, value)
- }
- if cu.mutation.StatusCleared() {
- _spec.ClearField(contact.FieldStatus, field.TypeUint8)
- }
- if value, ok := cu.mutation.DeletedAt(); ok {
- _spec.SetField(contact.FieldDeletedAt, field.TypeTime, value)
- }
- if cu.mutation.DeletedAtCleared() {
- _spec.ClearField(contact.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := cu.mutation.WxWxid(); ok {
- _spec.SetField(contact.FieldWxWxid, field.TypeString, value)
- }
- if cu.mutation.WxWxidCleared() {
- _spec.ClearField(contact.FieldWxWxid, field.TypeString)
- }
- if value, ok := cu.mutation.GetType(); ok {
- _spec.SetField(contact.FieldType, field.TypeInt, value)
- }
- if value, ok := cu.mutation.AddedType(); ok {
- _spec.AddField(contact.FieldType, field.TypeInt, value)
- }
- if cu.mutation.TypeCleared() {
- _spec.ClearField(contact.FieldType, field.TypeInt)
- }
- if value, ok := cu.mutation.Wxid(); ok {
- _spec.SetField(contact.FieldWxid, field.TypeString, value)
- }
- if value, ok := cu.mutation.Account(); ok {
- _spec.SetField(contact.FieldAccount, field.TypeString, value)
- }
- if value, ok := cu.mutation.Nickname(); ok {
- _spec.SetField(contact.FieldNickname, field.TypeString, value)
- }
- if value, ok := cu.mutation.Markname(); ok {
- _spec.SetField(contact.FieldMarkname, field.TypeString, value)
- }
- if value, ok := cu.mutation.Headimg(); ok {
- _spec.SetField(contact.FieldHeadimg, field.TypeString, value)
- }
- if value, ok := cu.mutation.Sex(); ok {
- _spec.SetField(contact.FieldSex, field.TypeInt, value)
- }
- if value, ok := cu.mutation.AddedSex(); ok {
- _spec.AddField(contact.FieldSex, field.TypeInt, value)
- }
- if value, ok := cu.mutation.Starrole(); ok {
- _spec.SetField(contact.FieldStarrole, field.TypeString, value)
- }
- if value, ok := cu.mutation.Dontseeit(); ok {
- _spec.SetField(contact.FieldDontseeit, field.TypeInt, value)
- }
- if value, ok := cu.mutation.AddedDontseeit(); ok {
- _spec.AddField(contact.FieldDontseeit, field.TypeInt, value)
- }
- if value, ok := cu.mutation.Dontseeme(); ok {
- _spec.SetField(contact.FieldDontseeme, field.TypeInt, value)
- }
- if value, ok := cu.mutation.AddedDontseeme(); ok {
- _spec.AddField(contact.FieldDontseeme, field.TypeInt, value)
- }
- if value, ok := cu.mutation.Lag(); ok {
- _spec.SetField(contact.FieldLag, field.TypeString, value)
- }
- if value, ok := cu.mutation.Gid(); ok {
- _spec.SetField(contact.FieldGid, field.TypeString, value)
- }
- if value, ok := cu.mutation.Gname(); ok {
- _spec.SetField(contact.FieldGname, field.TypeString, value)
- }
- if value, ok := cu.mutation.V3(); ok {
- _spec.SetField(contact.FieldV3, field.TypeString, value)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{contact.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- cu.mutation.done = true
- return n, nil
- }
- // ContactUpdateOne is the builder for updating a single Contact entity.
- type ContactUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *ContactMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cuo *ContactUpdateOne) SetUpdatedAt(t time.Time) *ContactUpdateOne {
- cuo.mutation.SetUpdatedAt(t)
- return cuo
- }
- // SetStatus sets the "status" field.
- func (cuo *ContactUpdateOne) SetStatus(u uint8) *ContactUpdateOne {
- cuo.mutation.ResetStatus()
- cuo.mutation.SetStatus(u)
- return cuo
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableStatus(u *uint8) *ContactUpdateOne {
- if u != nil {
- cuo.SetStatus(*u)
- }
- return cuo
- }
- // AddStatus adds u to the "status" field.
- func (cuo *ContactUpdateOne) AddStatus(u int8) *ContactUpdateOne {
- cuo.mutation.AddStatus(u)
- return cuo
- }
- // ClearStatus clears the value of the "status" field.
- func (cuo *ContactUpdateOne) ClearStatus() *ContactUpdateOne {
- cuo.mutation.ClearStatus()
- return cuo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (cuo *ContactUpdateOne) SetDeletedAt(t time.Time) *ContactUpdateOne {
- cuo.mutation.SetDeletedAt(t)
- return cuo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableDeletedAt(t *time.Time) *ContactUpdateOne {
- if t != nil {
- cuo.SetDeletedAt(*t)
- }
- return cuo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (cuo *ContactUpdateOne) ClearDeletedAt() *ContactUpdateOne {
- cuo.mutation.ClearDeletedAt()
- return cuo
- }
- // SetWxWxid sets the "wx_wxid" field.
- func (cuo *ContactUpdateOne) SetWxWxid(s string) *ContactUpdateOne {
- cuo.mutation.SetWxWxid(s)
- return cuo
- }
- // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableWxWxid(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetWxWxid(*s)
- }
- return cuo
- }
- // ClearWxWxid clears the value of the "wx_wxid" field.
- func (cuo *ContactUpdateOne) ClearWxWxid() *ContactUpdateOne {
- cuo.mutation.ClearWxWxid()
- return cuo
- }
- // SetType sets the "type" field.
- func (cuo *ContactUpdateOne) SetType(i int) *ContactUpdateOne {
- cuo.mutation.ResetType()
- cuo.mutation.SetType(i)
- return cuo
- }
- // SetNillableType sets the "type" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableType(i *int) *ContactUpdateOne {
- if i != nil {
- cuo.SetType(*i)
- }
- return cuo
- }
- // AddType adds i to the "type" field.
- func (cuo *ContactUpdateOne) AddType(i int) *ContactUpdateOne {
- cuo.mutation.AddType(i)
- return cuo
- }
- // ClearType clears the value of the "type" field.
- func (cuo *ContactUpdateOne) ClearType() *ContactUpdateOne {
- cuo.mutation.ClearType()
- return cuo
- }
- // SetWxid sets the "wxid" field.
- func (cuo *ContactUpdateOne) SetWxid(s string) *ContactUpdateOne {
- cuo.mutation.SetWxid(s)
- return cuo
- }
- // SetNillableWxid sets the "wxid" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableWxid(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetWxid(*s)
- }
- return cuo
- }
- // SetAccount sets the "account" field.
- func (cuo *ContactUpdateOne) SetAccount(s string) *ContactUpdateOne {
- cuo.mutation.SetAccount(s)
- return cuo
- }
- // SetNillableAccount sets the "account" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableAccount(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetAccount(*s)
- }
- return cuo
- }
- // SetNickname sets the "nickname" field.
- func (cuo *ContactUpdateOne) SetNickname(s string) *ContactUpdateOne {
- cuo.mutation.SetNickname(s)
- return cuo
- }
- // SetNillableNickname sets the "nickname" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableNickname(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetNickname(*s)
- }
- return cuo
- }
- // SetMarkname sets the "markname" field.
- func (cuo *ContactUpdateOne) SetMarkname(s string) *ContactUpdateOne {
- cuo.mutation.SetMarkname(s)
- return cuo
- }
- // SetNillableMarkname sets the "markname" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableMarkname(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetMarkname(*s)
- }
- return cuo
- }
- // SetHeadimg sets the "headimg" field.
- func (cuo *ContactUpdateOne) SetHeadimg(s string) *ContactUpdateOne {
- cuo.mutation.SetHeadimg(s)
- return cuo
- }
- // SetNillableHeadimg sets the "headimg" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableHeadimg(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetHeadimg(*s)
- }
- return cuo
- }
- // SetSex sets the "sex" field.
- func (cuo *ContactUpdateOne) SetSex(i int) *ContactUpdateOne {
- cuo.mutation.ResetSex()
- cuo.mutation.SetSex(i)
- return cuo
- }
- // SetNillableSex sets the "sex" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableSex(i *int) *ContactUpdateOne {
- if i != nil {
- cuo.SetSex(*i)
- }
- return cuo
- }
- // AddSex adds i to the "sex" field.
- func (cuo *ContactUpdateOne) AddSex(i int) *ContactUpdateOne {
- cuo.mutation.AddSex(i)
- return cuo
- }
- // SetStarrole sets the "starrole" field.
- func (cuo *ContactUpdateOne) SetStarrole(s string) *ContactUpdateOne {
- cuo.mutation.SetStarrole(s)
- return cuo
- }
- // SetNillableStarrole sets the "starrole" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableStarrole(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetStarrole(*s)
- }
- return cuo
- }
- // SetDontseeit sets the "dontseeit" field.
- func (cuo *ContactUpdateOne) SetDontseeit(i int) *ContactUpdateOne {
- cuo.mutation.ResetDontseeit()
- cuo.mutation.SetDontseeit(i)
- return cuo
- }
- // SetNillableDontseeit sets the "dontseeit" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableDontseeit(i *int) *ContactUpdateOne {
- if i != nil {
- cuo.SetDontseeit(*i)
- }
- return cuo
- }
- // AddDontseeit adds i to the "dontseeit" field.
- func (cuo *ContactUpdateOne) AddDontseeit(i int) *ContactUpdateOne {
- cuo.mutation.AddDontseeit(i)
- return cuo
- }
- // SetDontseeme sets the "dontseeme" field.
- func (cuo *ContactUpdateOne) SetDontseeme(i int) *ContactUpdateOne {
- cuo.mutation.ResetDontseeme()
- cuo.mutation.SetDontseeme(i)
- return cuo
- }
- // SetNillableDontseeme sets the "dontseeme" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableDontseeme(i *int) *ContactUpdateOne {
- if i != nil {
- cuo.SetDontseeme(*i)
- }
- return cuo
- }
- // AddDontseeme adds i to the "dontseeme" field.
- func (cuo *ContactUpdateOne) AddDontseeme(i int) *ContactUpdateOne {
- cuo.mutation.AddDontseeme(i)
- return cuo
- }
- // SetLag sets the "lag" field.
- func (cuo *ContactUpdateOne) SetLag(s string) *ContactUpdateOne {
- cuo.mutation.SetLag(s)
- return cuo
- }
- // SetNillableLag sets the "lag" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableLag(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetLag(*s)
- }
- return cuo
- }
- // SetGid sets the "gid" field.
- func (cuo *ContactUpdateOne) SetGid(s string) *ContactUpdateOne {
- cuo.mutation.SetGid(s)
- return cuo
- }
- // SetNillableGid sets the "gid" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableGid(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetGid(*s)
- }
- return cuo
- }
- // SetGname sets the "gname" field.
- func (cuo *ContactUpdateOne) SetGname(s string) *ContactUpdateOne {
- cuo.mutation.SetGname(s)
- return cuo
- }
- // SetNillableGname sets the "gname" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableGname(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetGname(*s)
- }
- return cuo
- }
- // SetV3 sets the "v3" field.
- func (cuo *ContactUpdateOne) SetV3(s string) *ContactUpdateOne {
- cuo.mutation.SetV3(s)
- return cuo
- }
- // SetNillableV3 sets the "v3" field if the given value is not nil.
- func (cuo *ContactUpdateOne) SetNillableV3(s *string) *ContactUpdateOne {
- if s != nil {
- cuo.SetV3(*s)
- }
- return cuo
- }
- // Mutation returns the ContactMutation object of the builder.
- func (cuo *ContactUpdateOne) Mutation() *ContactMutation {
- return cuo.mutation
- }
- // Where appends a list predicates to the ContactUpdate builder.
- func (cuo *ContactUpdateOne) Where(ps ...predicate.Contact) *ContactUpdateOne {
- cuo.mutation.Where(ps...)
- return cuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (cuo *ContactUpdateOne) Select(field string, fields ...string) *ContactUpdateOne {
- cuo.fields = append([]string{field}, fields...)
- return cuo
- }
- // Save executes the query and returns the updated Contact entity.
- func (cuo *ContactUpdateOne) Save(ctx context.Context) (*Contact, error) {
- if err := cuo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (cuo *ContactUpdateOne) SaveX(ctx context.Context) *Contact {
- node, err := cuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (cuo *ContactUpdateOne) Exec(ctx context.Context) error {
- _, err := cuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cuo *ContactUpdateOne) ExecX(ctx context.Context) {
- if err := cuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cuo *ContactUpdateOne) defaults() error {
- if _, ok := cuo.mutation.UpdatedAt(); !ok {
- if contact.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized contact.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := contact.UpdateDefaultUpdatedAt()
- cuo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- func (cuo *ContactUpdateOne) sqlSave(ctx context.Context) (_node *Contact, err error) {
- _spec := sqlgraph.NewUpdateSpec(contact.Table, contact.Columns, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64))
- id, ok := cuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Contact.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := cuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, contact.FieldID)
- for _, f := range fields {
- if !contact.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != contact.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := cuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := cuo.mutation.UpdatedAt(); ok {
- _spec.SetField(contact.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := cuo.mutation.Status(); ok {
- _spec.SetField(contact.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := cuo.mutation.AddedStatus(); ok {
- _spec.AddField(contact.FieldStatus, field.TypeUint8, value)
- }
- if cuo.mutation.StatusCleared() {
- _spec.ClearField(contact.FieldStatus, field.TypeUint8)
- }
- if value, ok := cuo.mutation.DeletedAt(); ok {
- _spec.SetField(contact.FieldDeletedAt, field.TypeTime, value)
- }
- if cuo.mutation.DeletedAtCleared() {
- _spec.ClearField(contact.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := cuo.mutation.WxWxid(); ok {
- _spec.SetField(contact.FieldWxWxid, field.TypeString, value)
- }
- if cuo.mutation.WxWxidCleared() {
- _spec.ClearField(contact.FieldWxWxid, field.TypeString)
- }
- if value, ok := cuo.mutation.GetType(); ok {
- _spec.SetField(contact.FieldType, field.TypeInt, value)
- }
- if value, ok := cuo.mutation.AddedType(); ok {
- _spec.AddField(contact.FieldType, field.TypeInt, value)
- }
- if cuo.mutation.TypeCleared() {
- _spec.ClearField(contact.FieldType, field.TypeInt)
- }
- if value, ok := cuo.mutation.Wxid(); ok {
- _spec.SetField(contact.FieldWxid, field.TypeString, value)
- }
- if value, ok := cuo.mutation.Account(); ok {
- _spec.SetField(contact.FieldAccount, field.TypeString, value)
- }
- if value, ok := cuo.mutation.Nickname(); ok {
- _spec.SetField(contact.FieldNickname, field.TypeString, value)
- }
- if value, ok := cuo.mutation.Markname(); ok {
- _spec.SetField(contact.FieldMarkname, field.TypeString, value)
- }
- if value, ok := cuo.mutation.Headimg(); ok {
- _spec.SetField(contact.FieldHeadimg, field.TypeString, value)
- }
- if value, ok := cuo.mutation.Sex(); ok {
- _spec.SetField(contact.FieldSex, field.TypeInt, value)
- }
- if value, ok := cuo.mutation.AddedSex(); ok {
- _spec.AddField(contact.FieldSex, field.TypeInt, value)
- }
- if value, ok := cuo.mutation.Starrole(); ok {
- _spec.SetField(contact.FieldStarrole, field.TypeString, value)
- }
- if value, ok := cuo.mutation.Dontseeit(); ok {
- _spec.SetField(contact.FieldDontseeit, field.TypeInt, value)
- }
- if value, ok := cuo.mutation.AddedDontseeit(); ok {
- _spec.AddField(contact.FieldDontseeit, field.TypeInt, value)
- }
- if value, ok := cuo.mutation.Dontseeme(); ok {
- _spec.SetField(contact.FieldDontseeme, field.TypeInt, value)
- }
- if value, ok := cuo.mutation.AddedDontseeme(); ok {
- _spec.AddField(contact.FieldDontseeme, field.TypeInt, value)
- }
- if value, ok := cuo.mutation.Lag(); ok {
- _spec.SetField(contact.FieldLag, field.TypeString, value)
- }
- if value, ok := cuo.mutation.Gid(); ok {
- _spec.SetField(contact.FieldGid, field.TypeString, value)
- }
- if value, ok := cuo.mutation.Gname(); ok {
- _spec.SetField(contact.FieldGname, field.TypeString, value)
- }
- if value, ok := cuo.mutation.V3(); ok {
- _spec.SetField(contact.FieldV3, field.TypeString, value)
- }
- _node = &Contact{config: cuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{contact.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- cuo.mutation.done = true
- return _node, nil
- }
|