// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "wechat-api/ent/contact" "wechat-api/ent/labelrelationship" "wechat-api/ent/messagerecords" "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 } // 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 } // SetOrganizationID sets the "organization_id" field. func (cu *ContactUpdate) SetOrganizationID(u uint64) *ContactUpdate { cu.mutation.ResetOrganizationID() cu.mutation.SetOrganizationID(u) return cu } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (cu *ContactUpdate) SetNillableOrganizationID(u *uint64) *ContactUpdate { if u != nil { cu.SetOrganizationID(*u) } return cu } // AddOrganizationID adds u to the "organization_id" field. func (cu *ContactUpdate) AddOrganizationID(u int64) *ContactUpdate { cu.mutation.AddOrganizationID(u) return cu } // ClearOrganizationID clears the value of the "organization_id" field. func (cu *ContactUpdate) ClearOrganizationID() *ContactUpdate { cu.mutation.ClearOrganizationID() return cu } // AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by IDs. func (cu *ContactUpdate) AddContactRelationshipIDs(ids ...uint64) *ContactUpdate { cu.mutation.AddContactRelationshipIDs(ids...) return cu } // AddContactRelationships adds the "contact_relationships" edges to the LabelRelationship entity. func (cu *ContactUpdate) AddContactRelationships(l ...*LabelRelationship) *ContactUpdate { ids := make([]uint64, len(l)) for i := range l { ids[i] = l[i].ID } return cu.AddContactRelationshipIDs(ids...) } // AddContactMessageIDs adds the "contact_messages" edge to the MessageRecords entity by IDs. func (cu *ContactUpdate) AddContactMessageIDs(ids ...uint64) *ContactUpdate { cu.mutation.AddContactMessageIDs(ids...) return cu } // AddContactMessages adds the "contact_messages" edges to the MessageRecords entity. func (cu *ContactUpdate) AddContactMessages(m ...*MessageRecords) *ContactUpdate { ids := make([]uint64, len(m)) for i := range m { ids[i] = m[i].ID } return cu.AddContactMessageIDs(ids...) } // Mutation returns the ContactMutation object of the builder. func (cu *ContactUpdate) Mutation() *ContactMutation { return cu.mutation } // ClearContactRelationships clears all "contact_relationships" edges to the LabelRelationship entity. func (cu *ContactUpdate) ClearContactRelationships() *ContactUpdate { cu.mutation.ClearContactRelationships() return cu } // RemoveContactRelationshipIDs removes the "contact_relationships" edge to LabelRelationship entities by IDs. func (cu *ContactUpdate) RemoveContactRelationshipIDs(ids ...uint64) *ContactUpdate { cu.mutation.RemoveContactRelationshipIDs(ids...) return cu } // RemoveContactRelationships removes "contact_relationships" edges to LabelRelationship entities. func (cu *ContactUpdate) RemoveContactRelationships(l ...*LabelRelationship) *ContactUpdate { ids := make([]uint64, len(l)) for i := range l { ids[i] = l[i].ID } return cu.RemoveContactRelationshipIDs(ids...) } // ClearContactMessages clears all "contact_messages" edges to the MessageRecords entity. func (cu *ContactUpdate) ClearContactMessages() *ContactUpdate { cu.mutation.ClearContactMessages() return cu } // RemoveContactMessageIDs removes the "contact_messages" edge to MessageRecords entities by IDs. func (cu *ContactUpdate) RemoveContactMessageIDs(ids ...uint64) *ContactUpdate { cu.mutation.RemoveContactMessageIDs(ids...) return cu } // RemoveContactMessages removes "contact_messages" edges to MessageRecords entities. func (cu *ContactUpdate) RemoveContactMessages(m ...*MessageRecords) *ContactUpdate { ids := make([]uint64, len(m)) for i := range m { ids[i] = m[i].ID } return cu.RemoveContactMessageIDs(ids...) } // 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 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 value, ok := cu.mutation.OrganizationID(); ok { _spec.SetField(contact.FieldOrganizationID, field.TypeUint64, value) } if value, ok := cu.mutation.AddedOrganizationID(); ok { _spec.AddField(contact.FieldOrganizationID, field.TypeUint64, value) } if cu.mutation.OrganizationIDCleared() { _spec.ClearField(contact.FieldOrganizationID, field.TypeUint64) } if cu.mutation.ContactRelationshipsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactRelationshipsTable, Columns: []string{contact.ContactRelationshipsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := cu.mutation.RemovedContactRelationshipsIDs(); len(nodes) > 0 && !cu.mutation.ContactRelationshipsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactRelationshipsTable, Columns: []string{contact.ContactRelationshipsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := cu.mutation.ContactRelationshipsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactRelationshipsTable, Columns: []string{contact.ContactRelationshipsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if cu.mutation.ContactMessagesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactMessagesTable, Columns: []string{contact.ContactMessagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := cu.mutation.RemovedContactMessagesIDs(); len(nodes) > 0 && !cu.mutation.ContactMessagesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactMessagesTable, Columns: []string{contact.ContactMessagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := cu.mutation.ContactMessagesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactMessagesTable, Columns: []string{contact.ContactMessagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } 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 } // 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 } // SetOrganizationID sets the "organization_id" field. func (cuo *ContactUpdateOne) SetOrganizationID(u uint64) *ContactUpdateOne { cuo.mutation.ResetOrganizationID() cuo.mutation.SetOrganizationID(u) return cuo } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (cuo *ContactUpdateOne) SetNillableOrganizationID(u *uint64) *ContactUpdateOne { if u != nil { cuo.SetOrganizationID(*u) } return cuo } // AddOrganizationID adds u to the "organization_id" field. func (cuo *ContactUpdateOne) AddOrganizationID(u int64) *ContactUpdateOne { cuo.mutation.AddOrganizationID(u) return cuo } // ClearOrganizationID clears the value of the "organization_id" field. func (cuo *ContactUpdateOne) ClearOrganizationID() *ContactUpdateOne { cuo.mutation.ClearOrganizationID() return cuo } // AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by IDs. func (cuo *ContactUpdateOne) AddContactRelationshipIDs(ids ...uint64) *ContactUpdateOne { cuo.mutation.AddContactRelationshipIDs(ids...) return cuo } // AddContactRelationships adds the "contact_relationships" edges to the LabelRelationship entity. func (cuo *ContactUpdateOne) AddContactRelationships(l ...*LabelRelationship) *ContactUpdateOne { ids := make([]uint64, len(l)) for i := range l { ids[i] = l[i].ID } return cuo.AddContactRelationshipIDs(ids...) } // AddContactMessageIDs adds the "contact_messages" edge to the MessageRecords entity by IDs. func (cuo *ContactUpdateOne) AddContactMessageIDs(ids ...uint64) *ContactUpdateOne { cuo.mutation.AddContactMessageIDs(ids...) return cuo } // AddContactMessages adds the "contact_messages" edges to the MessageRecords entity. func (cuo *ContactUpdateOne) AddContactMessages(m ...*MessageRecords) *ContactUpdateOne { ids := make([]uint64, len(m)) for i := range m { ids[i] = m[i].ID } return cuo.AddContactMessageIDs(ids...) } // Mutation returns the ContactMutation object of the builder. func (cuo *ContactUpdateOne) Mutation() *ContactMutation { return cuo.mutation } // ClearContactRelationships clears all "contact_relationships" edges to the LabelRelationship entity. func (cuo *ContactUpdateOne) ClearContactRelationships() *ContactUpdateOne { cuo.mutation.ClearContactRelationships() return cuo } // RemoveContactRelationshipIDs removes the "contact_relationships" edge to LabelRelationship entities by IDs. func (cuo *ContactUpdateOne) RemoveContactRelationshipIDs(ids ...uint64) *ContactUpdateOne { cuo.mutation.RemoveContactRelationshipIDs(ids...) return cuo } // RemoveContactRelationships removes "contact_relationships" edges to LabelRelationship entities. func (cuo *ContactUpdateOne) RemoveContactRelationships(l ...*LabelRelationship) *ContactUpdateOne { ids := make([]uint64, len(l)) for i := range l { ids[i] = l[i].ID } return cuo.RemoveContactRelationshipIDs(ids...) } // ClearContactMessages clears all "contact_messages" edges to the MessageRecords entity. func (cuo *ContactUpdateOne) ClearContactMessages() *ContactUpdateOne { cuo.mutation.ClearContactMessages() return cuo } // RemoveContactMessageIDs removes the "contact_messages" edge to MessageRecords entities by IDs. func (cuo *ContactUpdateOne) RemoveContactMessageIDs(ids ...uint64) *ContactUpdateOne { cuo.mutation.RemoveContactMessageIDs(ids...) return cuo } // RemoveContactMessages removes "contact_messages" edges to MessageRecords entities. func (cuo *ContactUpdateOne) RemoveContactMessages(m ...*MessageRecords) *ContactUpdateOne { ids := make([]uint64, len(m)) for i := range m { ids[i] = m[i].ID } return cuo.RemoveContactMessageIDs(ids...) } // 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 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) } if value, ok := cuo.mutation.OrganizationID(); ok { _spec.SetField(contact.FieldOrganizationID, field.TypeUint64, value) } if value, ok := cuo.mutation.AddedOrganizationID(); ok { _spec.AddField(contact.FieldOrganizationID, field.TypeUint64, value) } if cuo.mutation.OrganizationIDCleared() { _spec.ClearField(contact.FieldOrganizationID, field.TypeUint64) } if cuo.mutation.ContactRelationshipsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactRelationshipsTable, Columns: []string{contact.ContactRelationshipsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := cuo.mutation.RemovedContactRelationshipsIDs(); len(nodes) > 0 && !cuo.mutation.ContactRelationshipsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactRelationshipsTable, Columns: []string{contact.ContactRelationshipsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := cuo.mutation.ContactRelationshipsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactRelationshipsTable, Columns: []string{contact.ContactRelationshipsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if cuo.mutation.ContactMessagesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactMessagesTable, Columns: []string{contact.ContactMessagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := cuo.mutation.RemovedContactMessagesIDs(); len(nodes) > 0 && !cuo.mutation.ContactMessagesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactMessagesTable, Columns: []string{contact.ContactMessagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := cuo.mutation.ContactMessagesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: contact.ContactMessagesTable, Columns: []string{contact.ContactMessagesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _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 }