contact_update.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/contact"
  9. "wechat-api/ent/labelrelationship"
  10. "wechat-api/ent/messagerecords"
  11. "wechat-api/ent/predicate"
  12. "entgo.io/ent/dialect/sql"
  13. "entgo.io/ent/dialect/sql/sqlgraph"
  14. "entgo.io/ent/schema/field"
  15. )
  16. // ContactUpdate is the builder for updating Contact entities.
  17. type ContactUpdate struct {
  18. config
  19. hooks []Hook
  20. mutation *ContactMutation
  21. }
  22. // Where appends a list predicates to the ContactUpdate builder.
  23. func (cu *ContactUpdate) Where(ps ...predicate.Contact) *ContactUpdate {
  24. cu.mutation.Where(ps...)
  25. return cu
  26. }
  27. // SetUpdatedAt sets the "updated_at" field.
  28. func (cu *ContactUpdate) SetUpdatedAt(t time.Time) *ContactUpdate {
  29. cu.mutation.SetUpdatedAt(t)
  30. return cu
  31. }
  32. // SetStatus sets the "status" field.
  33. func (cu *ContactUpdate) SetStatus(u uint8) *ContactUpdate {
  34. cu.mutation.ResetStatus()
  35. cu.mutation.SetStatus(u)
  36. return cu
  37. }
  38. // SetNillableStatus sets the "status" field if the given value is not nil.
  39. func (cu *ContactUpdate) SetNillableStatus(u *uint8) *ContactUpdate {
  40. if u != nil {
  41. cu.SetStatus(*u)
  42. }
  43. return cu
  44. }
  45. // AddStatus adds u to the "status" field.
  46. func (cu *ContactUpdate) AddStatus(u int8) *ContactUpdate {
  47. cu.mutation.AddStatus(u)
  48. return cu
  49. }
  50. // ClearStatus clears the value of the "status" field.
  51. func (cu *ContactUpdate) ClearStatus() *ContactUpdate {
  52. cu.mutation.ClearStatus()
  53. return cu
  54. }
  55. // SetDeletedAt sets the "deleted_at" field.
  56. func (cu *ContactUpdate) SetDeletedAt(t time.Time) *ContactUpdate {
  57. cu.mutation.SetDeletedAt(t)
  58. return cu
  59. }
  60. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  61. func (cu *ContactUpdate) SetNillableDeletedAt(t *time.Time) *ContactUpdate {
  62. if t != nil {
  63. cu.SetDeletedAt(*t)
  64. }
  65. return cu
  66. }
  67. // ClearDeletedAt clears the value of the "deleted_at" field.
  68. func (cu *ContactUpdate) ClearDeletedAt() *ContactUpdate {
  69. cu.mutation.ClearDeletedAt()
  70. return cu
  71. }
  72. // SetWxWxid sets the "wx_wxid" field.
  73. func (cu *ContactUpdate) SetWxWxid(s string) *ContactUpdate {
  74. cu.mutation.SetWxWxid(s)
  75. return cu
  76. }
  77. // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
  78. func (cu *ContactUpdate) SetNillableWxWxid(s *string) *ContactUpdate {
  79. if s != nil {
  80. cu.SetWxWxid(*s)
  81. }
  82. return cu
  83. }
  84. // ClearWxWxid clears the value of the "wx_wxid" field.
  85. func (cu *ContactUpdate) ClearWxWxid() *ContactUpdate {
  86. cu.mutation.ClearWxWxid()
  87. return cu
  88. }
  89. // SetType sets the "type" field.
  90. func (cu *ContactUpdate) SetType(i int) *ContactUpdate {
  91. cu.mutation.ResetType()
  92. cu.mutation.SetType(i)
  93. return cu
  94. }
  95. // SetNillableType sets the "type" field if the given value is not nil.
  96. func (cu *ContactUpdate) SetNillableType(i *int) *ContactUpdate {
  97. if i != nil {
  98. cu.SetType(*i)
  99. }
  100. return cu
  101. }
  102. // AddType adds i to the "type" field.
  103. func (cu *ContactUpdate) AddType(i int) *ContactUpdate {
  104. cu.mutation.AddType(i)
  105. return cu
  106. }
  107. // ClearType clears the value of the "type" field.
  108. func (cu *ContactUpdate) ClearType() *ContactUpdate {
  109. cu.mutation.ClearType()
  110. return cu
  111. }
  112. // SetWxid sets the "wxid" field.
  113. func (cu *ContactUpdate) SetWxid(s string) *ContactUpdate {
  114. cu.mutation.SetWxid(s)
  115. return cu
  116. }
  117. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  118. func (cu *ContactUpdate) SetNillableWxid(s *string) *ContactUpdate {
  119. if s != nil {
  120. cu.SetWxid(*s)
  121. }
  122. return cu
  123. }
  124. // SetAccount sets the "account" field.
  125. func (cu *ContactUpdate) SetAccount(s string) *ContactUpdate {
  126. cu.mutation.SetAccount(s)
  127. return cu
  128. }
  129. // SetNillableAccount sets the "account" field if the given value is not nil.
  130. func (cu *ContactUpdate) SetNillableAccount(s *string) *ContactUpdate {
  131. if s != nil {
  132. cu.SetAccount(*s)
  133. }
  134. return cu
  135. }
  136. // SetNickname sets the "nickname" field.
  137. func (cu *ContactUpdate) SetNickname(s string) *ContactUpdate {
  138. cu.mutation.SetNickname(s)
  139. return cu
  140. }
  141. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  142. func (cu *ContactUpdate) SetNillableNickname(s *string) *ContactUpdate {
  143. if s != nil {
  144. cu.SetNickname(*s)
  145. }
  146. return cu
  147. }
  148. // SetMarkname sets the "markname" field.
  149. func (cu *ContactUpdate) SetMarkname(s string) *ContactUpdate {
  150. cu.mutation.SetMarkname(s)
  151. return cu
  152. }
  153. // SetNillableMarkname sets the "markname" field if the given value is not nil.
  154. func (cu *ContactUpdate) SetNillableMarkname(s *string) *ContactUpdate {
  155. if s != nil {
  156. cu.SetMarkname(*s)
  157. }
  158. return cu
  159. }
  160. // SetHeadimg sets the "headimg" field.
  161. func (cu *ContactUpdate) SetHeadimg(s string) *ContactUpdate {
  162. cu.mutation.SetHeadimg(s)
  163. return cu
  164. }
  165. // SetNillableHeadimg sets the "headimg" field if the given value is not nil.
  166. func (cu *ContactUpdate) SetNillableHeadimg(s *string) *ContactUpdate {
  167. if s != nil {
  168. cu.SetHeadimg(*s)
  169. }
  170. return cu
  171. }
  172. // SetSex sets the "sex" field.
  173. func (cu *ContactUpdate) SetSex(i int) *ContactUpdate {
  174. cu.mutation.ResetSex()
  175. cu.mutation.SetSex(i)
  176. return cu
  177. }
  178. // SetNillableSex sets the "sex" field if the given value is not nil.
  179. func (cu *ContactUpdate) SetNillableSex(i *int) *ContactUpdate {
  180. if i != nil {
  181. cu.SetSex(*i)
  182. }
  183. return cu
  184. }
  185. // AddSex adds i to the "sex" field.
  186. func (cu *ContactUpdate) AddSex(i int) *ContactUpdate {
  187. cu.mutation.AddSex(i)
  188. return cu
  189. }
  190. // SetStarrole sets the "starrole" field.
  191. func (cu *ContactUpdate) SetStarrole(s string) *ContactUpdate {
  192. cu.mutation.SetStarrole(s)
  193. return cu
  194. }
  195. // SetNillableStarrole sets the "starrole" field if the given value is not nil.
  196. func (cu *ContactUpdate) SetNillableStarrole(s *string) *ContactUpdate {
  197. if s != nil {
  198. cu.SetStarrole(*s)
  199. }
  200. return cu
  201. }
  202. // SetDontseeit sets the "dontseeit" field.
  203. func (cu *ContactUpdate) SetDontseeit(i int) *ContactUpdate {
  204. cu.mutation.ResetDontseeit()
  205. cu.mutation.SetDontseeit(i)
  206. return cu
  207. }
  208. // SetNillableDontseeit sets the "dontseeit" field if the given value is not nil.
  209. func (cu *ContactUpdate) SetNillableDontseeit(i *int) *ContactUpdate {
  210. if i != nil {
  211. cu.SetDontseeit(*i)
  212. }
  213. return cu
  214. }
  215. // AddDontseeit adds i to the "dontseeit" field.
  216. func (cu *ContactUpdate) AddDontseeit(i int) *ContactUpdate {
  217. cu.mutation.AddDontseeit(i)
  218. return cu
  219. }
  220. // SetDontseeme sets the "dontseeme" field.
  221. func (cu *ContactUpdate) SetDontseeme(i int) *ContactUpdate {
  222. cu.mutation.ResetDontseeme()
  223. cu.mutation.SetDontseeme(i)
  224. return cu
  225. }
  226. // SetNillableDontseeme sets the "dontseeme" field if the given value is not nil.
  227. func (cu *ContactUpdate) SetNillableDontseeme(i *int) *ContactUpdate {
  228. if i != nil {
  229. cu.SetDontseeme(*i)
  230. }
  231. return cu
  232. }
  233. // AddDontseeme adds i to the "dontseeme" field.
  234. func (cu *ContactUpdate) AddDontseeme(i int) *ContactUpdate {
  235. cu.mutation.AddDontseeme(i)
  236. return cu
  237. }
  238. // SetLag sets the "lag" field.
  239. func (cu *ContactUpdate) SetLag(s string) *ContactUpdate {
  240. cu.mutation.SetLag(s)
  241. return cu
  242. }
  243. // SetNillableLag sets the "lag" field if the given value is not nil.
  244. func (cu *ContactUpdate) SetNillableLag(s *string) *ContactUpdate {
  245. if s != nil {
  246. cu.SetLag(*s)
  247. }
  248. return cu
  249. }
  250. // SetGid sets the "gid" field.
  251. func (cu *ContactUpdate) SetGid(s string) *ContactUpdate {
  252. cu.mutation.SetGid(s)
  253. return cu
  254. }
  255. // SetNillableGid sets the "gid" field if the given value is not nil.
  256. func (cu *ContactUpdate) SetNillableGid(s *string) *ContactUpdate {
  257. if s != nil {
  258. cu.SetGid(*s)
  259. }
  260. return cu
  261. }
  262. // SetGname sets the "gname" field.
  263. func (cu *ContactUpdate) SetGname(s string) *ContactUpdate {
  264. cu.mutation.SetGname(s)
  265. return cu
  266. }
  267. // SetNillableGname sets the "gname" field if the given value is not nil.
  268. func (cu *ContactUpdate) SetNillableGname(s *string) *ContactUpdate {
  269. if s != nil {
  270. cu.SetGname(*s)
  271. }
  272. return cu
  273. }
  274. // SetV3 sets the "v3" field.
  275. func (cu *ContactUpdate) SetV3(s string) *ContactUpdate {
  276. cu.mutation.SetV3(s)
  277. return cu
  278. }
  279. // SetNillableV3 sets the "v3" field if the given value is not nil.
  280. func (cu *ContactUpdate) SetNillableV3(s *string) *ContactUpdate {
  281. if s != nil {
  282. cu.SetV3(*s)
  283. }
  284. return cu
  285. }
  286. // AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by IDs.
  287. func (cu *ContactUpdate) AddContactRelationshipIDs(ids ...uint64) *ContactUpdate {
  288. cu.mutation.AddContactRelationshipIDs(ids...)
  289. return cu
  290. }
  291. // AddContactRelationships adds the "contact_relationships" edges to the LabelRelationship entity.
  292. func (cu *ContactUpdate) AddContactRelationships(l ...*LabelRelationship) *ContactUpdate {
  293. ids := make([]uint64, len(l))
  294. for i := range l {
  295. ids[i] = l[i].ID
  296. }
  297. return cu.AddContactRelationshipIDs(ids...)
  298. }
  299. // AddContactMessageIDs adds the "contact_messages" edge to the MessageRecords entity by IDs.
  300. func (cu *ContactUpdate) AddContactMessageIDs(ids ...uint64) *ContactUpdate {
  301. cu.mutation.AddContactMessageIDs(ids...)
  302. return cu
  303. }
  304. // AddContactMessages adds the "contact_messages" edges to the MessageRecords entity.
  305. func (cu *ContactUpdate) AddContactMessages(m ...*MessageRecords) *ContactUpdate {
  306. ids := make([]uint64, len(m))
  307. for i := range m {
  308. ids[i] = m[i].ID
  309. }
  310. return cu.AddContactMessageIDs(ids...)
  311. }
  312. // Mutation returns the ContactMutation object of the builder.
  313. func (cu *ContactUpdate) Mutation() *ContactMutation {
  314. return cu.mutation
  315. }
  316. // ClearContactRelationships clears all "contact_relationships" edges to the LabelRelationship entity.
  317. func (cu *ContactUpdate) ClearContactRelationships() *ContactUpdate {
  318. cu.mutation.ClearContactRelationships()
  319. return cu
  320. }
  321. // RemoveContactRelationshipIDs removes the "contact_relationships" edge to LabelRelationship entities by IDs.
  322. func (cu *ContactUpdate) RemoveContactRelationshipIDs(ids ...uint64) *ContactUpdate {
  323. cu.mutation.RemoveContactRelationshipIDs(ids...)
  324. return cu
  325. }
  326. // RemoveContactRelationships removes "contact_relationships" edges to LabelRelationship entities.
  327. func (cu *ContactUpdate) RemoveContactRelationships(l ...*LabelRelationship) *ContactUpdate {
  328. ids := make([]uint64, len(l))
  329. for i := range l {
  330. ids[i] = l[i].ID
  331. }
  332. return cu.RemoveContactRelationshipIDs(ids...)
  333. }
  334. // ClearContactMessages clears all "contact_messages" edges to the MessageRecords entity.
  335. func (cu *ContactUpdate) ClearContactMessages() *ContactUpdate {
  336. cu.mutation.ClearContactMessages()
  337. return cu
  338. }
  339. // RemoveContactMessageIDs removes the "contact_messages" edge to MessageRecords entities by IDs.
  340. func (cu *ContactUpdate) RemoveContactMessageIDs(ids ...uint64) *ContactUpdate {
  341. cu.mutation.RemoveContactMessageIDs(ids...)
  342. return cu
  343. }
  344. // RemoveContactMessages removes "contact_messages" edges to MessageRecords entities.
  345. func (cu *ContactUpdate) RemoveContactMessages(m ...*MessageRecords) *ContactUpdate {
  346. ids := make([]uint64, len(m))
  347. for i := range m {
  348. ids[i] = m[i].ID
  349. }
  350. return cu.RemoveContactMessageIDs(ids...)
  351. }
  352. // Save executes the query and returns the number of nodes affected by the update operation.
  353. func (cu *ContactUpdate) Save(ctx context.Context) (int, error) {
  354. if err := cu.defaults(); err != nil {
  355. return 0, err
  356. }
  357. return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks)
  358. }
  359. // SaveX is like Save, but panics if an error occurs.
  360. func (cu *ContactUpdate) SaveX(ctx context.Context) int {
  361. affected, err := cu.Save(ctx)
  362. if err != nil {
  363. panic(err)
  364. }
  365. return affected
  366. }
  367. // Exec executes the query.
  368. func (cu *ContactUpdate) Exec(ctx context.Context) error {
  369. _, err := cu.Save(ctx)
  370. return err
  371. }
  372. // ExecX is like Exec, but panics if an error occurs.
  373. func (cu *ContactUpdate) ExecX(ctx context.Context) {
  374. if err := cu.Exec(ctx); err != nil {
  375. panic(err)
  376. }
  377. }
  378. // defaults sets the default values of the builder before save.
  379. func (cu *ContactUpdate) defaults() error {
  380. if _, ok := cu.mutation.UpdatedAt(); !ok {
  381. if contact.UpdateDefaultUpdatedAt == nil {
  382. return fmt.Errorf("ent: uninitialized contact.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  383. }
  384. v := contact.UpdateDefaultUpdatedAt()
  385. cu.mutation.SetUpdatedAt(v)
  386. }
  387. return nil
  388. }
  389. func (cu *ContactUpdate) sqlSave(ctx context.Context) (n int, err error) {
  390. _spec := sqlgraph.NewUpdateSpec(contact.Table, contact.Columns, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64))
  391. if ps := cu.mutation.predicates; len(ps) > 0 {
  392. _spec.Predicate = func(selector *sql.Selector) {
  393. for i := range ps {
  394. ps[i](selector)
  395. }
  396. }
  397. }
  398. if value, ok := cu.mutation.UpdatedAt(); ok {
  399. _spec.SetField(contact.FieldUpdatedAt, field.TypeTime, value)
  400. }
  401. if value, ok := cu.mutation.Status(); ok {
  402. _spec.SetField(contact.FieldStatus, field.TypeUint8, value)
  403. }
  404. if value, ok := cu.mutation.AddedStatus(); ok {
  405. _spec.AddField(contact.FieldStatus, field.TypeUint8, value)
  406. }
  407. if cu.mutation.StatusCleared() {
  408. _spec.ClearField(contact.FieldStatus, field.TypeUint8)
  409. }
  410. if value, ok := cu.mutation.DeletedAt(); ok {
  411. _spec.SetField(contact.FieldDeletedAt, field.TypeTime, value)
  412. }
  413. if cu.mutation.DeletedAtCleared() {
  414. _spec.ClearField(contact.FieldDeletedAt, field.TypeTime)
  415. }
  416. if value, ok := cu.mutation.WxWxid(); ok {
  417. _spec.SetField(contact.FieldWxWxid, field.TypeString, value)
  418. }
  419. if cu.mutation.WxWxidCleared() {
  420. _spec.ClearField(contact.FieldWxWxid, field.TypeString)
  421. }
  422. if value, ok := cu.mutation.GetType(); ok {
  423. _spec.SetField(contact.FieldType, field.TypeInt, value)
  424. }
  425. if value, ok := cu.mutation.AddedType(); ok {
  426. _spec.AddField(contact.FieldType, field.TypeInt, value)
  427. }
  428. if cu.mutation.TypeCleared() {
  429. _spec.ClearField(contact.FieldType, field.TypeInt)
  430. }
  431. if value, ok := cu.mutation.Wxid(); ok {
  432. _spec.SetField(contact.FieldWxid, field.TypeString, value)
  433. }
  434. if value, ok := cu.mutation.Account(); ok {
  435. _spec.SetField(contact.FieldAccount, field.TypeString, value)
  436. }
  437. if value, ok := cu.mutation.Nickname(); ok {
  438. _spec.SetField(contact.FieldNickname, field.TypeString, value)
  439. }
  440. if value, ok := cu.mutation.Markname(); ok {
  441. _spec.SetField(contact.FieldMarkname, field.TypeString, value)
  442. }
  443. if value, ok := cu.mutation.Headimg(); ok {
  444. _spec.SetField(contact.FieldHeadimg, field.TypeString, value)
  445. }
  446. if value, ok := cu.mutation.Sex(); ok {
  447. _spec.SetField(contact.FieldSex, field.TypeInt, value)
  448. }
  449. if value, ok := cu.mutation.AddedSex(); ok {
  450. _spec.AddField(contact.FieldSex, field.TypeInt, value)
  451. }
  452. if value, ok := cu.mutation.Starrole(); ok {
  453. _spec.SetField(contact.FieldStarrole, field.TypeString, value)
  454. }
  455. if value, ok := cu.mutation.Dontseeit(); ok {
  456. _spec.SetField(contact.FieldDontseeit, field.TypeInt, value)
  457. }
  458. if value, ok := cu.mutation.AddedDontseeit(); ok {
  459. _spec.AddField(contact.FieldDontseeit, field.TypeInt, value)
  460. }
  461. if value, ok := cu.mutation.Dontseeme(); ok {
  462. _spec.SetField(contact.FieldDontseeme, field.TypeInt, value)
  463. }
  464. if value, ok := cu.mutation.AddedDontseeme(); ok {
  465. _spec.AddField(contact.FieldDontseeme, field.TypeInt, value)
  466. }
  467. if value, ok := cu.mutation.Lag(); ok {
  468. _spec.SetField(contact.FieldLag, field.TypeString, value)
  469. }
  470. if value, ok := cu.mutation.Gid(); ok {
  471. _spec.SetField(contact.FieldGid, field.TypeString, value)
  472. }
  473. if value, ok := cu.mutation.Gname(); ok {
  474. _spec.SetField(contact.FieldGname, field.TypeString, value)
  475. }
  476. if value, ok := cu.mutation.V3(); ok {
  477. _spec.SetField(contact.FieldV3, field.TypeString, value)
  478. }
  479. if cu.mutation.ContactRelationshipsCleared() {
  480. edge := &sqlgraph.EdgeSpec{
  481. Rel: sqlgraph.O2M,
  482. Inverse: false,
  483. Table: contact.ContactRelationshipsTable,
  484. Columns: []string{contact.ContactRelationshipsColumn},
  485. Bidi: false,
  486. Target: &sqlgraph.EdgeTarget{
  487. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  488. },
  489. }
  490. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  491. }
  492. if nodes := cu.mutation.RemovedContactRelationshipsIDs(); len(nodes) > 0 && !cu.mutation.ContactRelationshipsCleared() {
  493. edge := &sqlgraph.EdgeSpec{
  494. Rel: sqlgraph.O2M,
  495. Inverse: false,
  496. Table: contact.ContactRelationshipsTable,
  497. Columns: []string{contact.ContactRelationshipsColumn},
  498. Bidi: false,
  499. Target: &sqlgraph.EdgeTarget{
  500. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  501. },
  502. }
  503. for _, k := range nodes {
  504. edge.Target.Nodes = append(edge.Target.Nodes, k)
  505. }
  506. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  507. }
  508. if nodes := cu.mutation.ContactRelationshipsIDs(); len(nodes) > 0 {
  509. edge := &sqlgraph.EdgeSpec{
  510. Rel: sqlgraph.O2M,
  511. Inverse: false,
  512. Table: contact.ContactRelationshipsTable,
  513. Columns: []string{contact.ContactRelationshipsColumn},
  514. Bidi: false,
  515. Target: &sqlgraph.EdgeTarget{
  516. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  517. },
  518. }
  519. for _, k := range nodes {
  520. edge.Target.Nodes = append(edge.Target.Nodes, k)
  521. }
  522. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  523. }
  524. if cu.mutation.ContactMessagesCleared() {
  525. edge := &sqlgraph.EdgeSpec{
  526. Rel: sqlgraph.O2M,
  527. Inverse: false,
  528. Table: contact.ContactMessagesTable,
  529. Columns: []string{contact.ContactMessagesColumn},
  530. Bidi: false,
  531. Target: &sqlgraph.EdgeTarget{
  532. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  533. },
  534. }
  535. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  536. }
  537. if nodes := cu.mutation.RemovedContactMessagesIDs(); len(nodes) > 0 && !cu.mutation.ContactMessagesCleared() {
  538. edge := &sqlgraph.EdgeSpec{
  539. Rel: sqlgraph.O2M,
  540. Inverse: false,
  541. Table: contact.ContactMessagesTable,
  542. Columns: []string{contact.ContactMessagesColumn},
  543. Bidi: false,
  544. Target: &sqlgraph.EdgeTarget{
  545. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  546. },
  547. }
  548. for _, k := range nodes {
  549. edge.Target.Nodes = append(edge.Target.Nodes, k)
  550. }
  551. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  552. }
  553. if nodes := cu.mutation.ContactMessagesIDs(); len(nodes) > 0 {
  554. edge := &sqlgraph.EdgeSpec{
  555. Rel: sqlgraph.O2M,
  556. Inverse: false,
  557. Table: contact.ContactMessagesTable,
  558. Columns: []string{contact.ContactMessagesColumn},
  559. Bidi: false,
  560. Target: &sqlgraph.EdgeTarget{
  561. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  562. },
  563. }
  564. for _, k := range nodes {
  565. edge.Target.Nodes = append(edge.Target.Nodes, k)
  566. }
  567. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  568. }
  569. if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
  570. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  571. err = &NotFoundError{contact.Label}
  572. } else if sqlgraph.IsConstraintError(err) {
  573. err = &ConstraintError{msg: err.Error(), wrap: err}
  574. }
  575. return 0, err
  576. }
  577. cu.mutation.done = true
  578. return n, nil
  579. }
  580. // ContactUpdateOne is the builder for updating a single Contact entity.
  581. type ContactUpdateOne struct {
  582. config
  583. fields []string
  584. hooks []Hook
  585. mutation *ContactMutation
  586. }
  587. // SetUpdatedAt sets the "updated_at" field.
  588. func (cuo *ContactUpdateOne) SetUpdatedAt(t time.Time) *ContactUpdateOne {
  589. cuo.mutation.SetUpdatedAt(t)
  590. return cuo
  591. }
  592. // SetStatus sets the "status" field.
  593. func (cuo *ContactUpdateOne) SetStatus(u uint8) *ContactUpdateOne {
  594. cuo.mutation.ResetStatus()
  595. cuo.mutation.SetStatus(u)
  596. return cuo
  597. }
  598. // SetNillableStatus sets the "status" field if the given value is not nil.
  599. func (cuo *ContactUpdateOne) SetNillableStatus(u *uint8) *ContactUpdateOne {
  600. if u != nil {
  601. cuo.SetStatus(*u)
  602. }
  603. return cuo
  604. }
  605. // AddStatus adds u to the "status" field.
  606. func (cuo *ContactUpdateOne) AddStatus(u int8) *ContactUpdateOne {
  607. cuo.mutation.AddStatus(u)
  608. return cuo
  609. }
  610. // ClearStatus clears the value of the "status" field.
  611. func (cuo *ContactUpdateOne) ClearStatus() *ContactUpdateOne {
  612. cuo.mutation.ClearStatus()
  613. return cuo
  614. }
  615. // SetDeletedAt sets the "deleted_at" field.
  616. func (cuo *ContactUpdateOne) SetDeletedAt(t time.Time) *ContactUpdateOne {
  617. cuo.mutation.SetDeletedAt(t)
  618. return cuo
  619. }
  620. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  621. func (cuo *ContactUpdateOne) SetNillableDeletedAt(t *time.Time) *ContactUpdateOne {
  622. if t != nil {
  623. cuo.SetDeletedAt(*t)
  624. }
  625. return cuo
  626. }
  627. // ClearDeletedAt clears the value of the "deleted_at" field.
  628. func (cuo *ContactUpdateOne) ClearDeletedAt() *ContactUpdateOne {
  629. cuo.mutation.ClearDeletedAt()
  630. return cuo
  631. }
  632. // SetWxWxid sets the "wx_wxid" field.
  633. func (cuo *ContactUpdateOne) SetWxWxid(s string) *ContactUpdateOne {
  634. cuo.mutation.SetWxWxid(s)
  635. return cuo
  636. }
  637. // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
  638. func (cuo *ContactUpdateOne) SetNillableWxWxid(s *string) *ContactUpdateOne {
  639. if s != nil {
  640. cuo.SetWxWxid(*s)
  641. }
  642. return cuo
  643. }
  644. // ClearWxWxid clears the value of the "wx_wxid" field.
  645. func (cuo *ContactUpdateOne) ClearWxWxid() *ContactUpdateOne {
  646. cuo.mutation.ClearWxWxid()
  647. return cuo
  648. }
  649. // SetType sets the "type" field.
  650. func (cuo *ContactUpdateOne) SetType(i int) *ContactUpdateOne {
  651. cuo.mutation.ResetType()
  652. cuo.mutation.SetType(i)
  653. return cuo
  654. }
  655. // SetNillableType sets the "type" field if the given value is not nil.
  656. func (cuo *ContactUpdateOne) SetNillableType(i *int) *ContactUpdateOne {
  657. if i != nil {
  658. cuo.SetType(*i)
  659. }
  660. return cuo
  661. }
  662. // AddType adds i to the "type" field.
  663. func (cuo *ContactUpdateOne) AddType(i int) *ContactUpdateOne {
  664. cuo.mutation.AddType(i)
  665. return cuo
  666. }
  667. // ClearType clears the value of the "type" field.
  668. func (cuo *ContactUpdateOne) ClearType() *ContactUpdateOne {
  669. cuo.mutation.ClearType()
  670. return cuo
  671. }
  672. // SetWxid sets the "wxid" field.
  673. func (cuo *ContactUpdateOne) SetWxid(s string) *ContactUpdateOne {
  674. cuo.mutation.SetWxid(s)
  675. return cuo
  676. }
  677. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  678. func (cuo *ContactUpdateOne) SetNillableWxid(s *string) *ContactUpdateOne {
  679. if s != nil {
  680. cuo.SetWxid(*s)
  681. }
  682. return cuo
  683. }
  684. // SetAccount sets the "account" field.
  685. func (cuo *ContactUpdateOne) SetAccount(s string) *ContactUpdateOne {
  686. cuo.mutation.SetAccount(s)
  687. return cuo
  688. }
  689. // SetNillableAccount sets the "account" field if the given value is not nil.
  690. func (cuo *ContactUpdateOne) SetNillableAccount(s *string) *ContactUpdateOne {
  691. if s != nil {
  692. cuo.SetAccount(*s)
  693. }
  694. return cuo
  695. }
  696. // SetNickname sets the "nickname" field.
  697. func (cuo *ContactUpdateOne) SetNickname(s string) *ContactUpdateOne {
  698. cuo.mutation.SetNickname(s)
  699. return cuo
  700. }
  701. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  702. func (cuo *ContactUpdateOne) SetNillableNickname(s *string) *ContactUpdateOne {
  703. if s != nil {
  704. cuo.SetNickname(*s)
  705. }
  706. return cuo
  707. }
  708. // SetMarkname sets the "markname" field.
  709. func (cuo *ContactUpdateOne) SetMarkname(s string) *ContactUpdateOne {
  710. cuo.mutation.SetMarkname(s)
  711. return cuo
  712. }
  713. // SetNillableMarkname sets the "markname" field if the given value is not nil.
  714. func (cuo *ContactUpdateOne) SetNillableMarkname(s *string) *ContactUpdateOne {
  715. if s != nil {
  716. cuo.SetMarkname(*s)
  717. }
  718. return cuo
  719. }
  720. // SetHeadimg sets the "headimg" field.
  721. func (cuo *ContactUpdateOne) SetHeadimg(s string) *ContactUpdateOne {
  722. cuo.mutation.SetHeadimg(s)
  723. return cuo
  724. }
  725. // SetNillableHeadimg sets the "headimg" field if the given value is not nil.
  726. func (cuo *ContactUpdateOne) SetNillableHeadimg(s *string) *ContactUpdateOne {
  727. if s != nil {
  728. cuo.SetHeadimg(*s)
  729. }
  730. return cuo
  731. }
  732. // SetSex sets the "sex" field.
  733. func (cuo *ContactUpdateOne) SetSex(i int) *ContactUpdateOne {
  734. cuo.mutation.ResetSex()
  735. cuo.mutation.SetSex(i)
  736. return cuo
  737. }
  738. // SetNillableSex sets the "sex" field if the given value is not nil.
  739. func (cuo *ContactUpdateOne) SetNillableSex(i *int) *ContactUpdateOne {
  740. if i != nil {
  741. cuo.SetSex(*i)
  742. }
  743. return cuo
  744. }
  745. // AddSex adds i to the "sex" field.
  746. func (cuo *ContactUpdateOne) AddSex(i int) *ContactUpdateOne {
  747. cuo.mutation.AddSex(i)
  748. return cuo
  749. }
  750. // SetStarrole sets the "starrole" field.
  751. func (cuo *ContactUpdateOne) SetStarrole(s string) *ContactUpdateOne {
  752. cuo.mutation.SetStarrole(s)
  753. return cuo
  754. }
  755. // SetNillableStarrole sets the "starrole" field if the given value is not nil.
  756. func (cuo *ContactUpdateOne) SetNillableStarrole(s *string) *ContactUpdateOne {
  757. if s != nil {
  758. cuo.SetStarrole(*s)
  759. }
  760. return cuo
  761. }
  762. // SetDontseeit sets the "dontseeit" field.
  763. func (cuo *ContactUpdateOne) SetDontseeit(i int) *ContactUpdateOne {
  764. cuo.mutation.ResetDontseeit()
  765. cuo.mutation.SetDontseeit(i)
  766. return cuo
  767. }
  768. // SetNillableDontseeit sets the "dontseeit" field if the given value is not nil.
  769. func (cuo *ContactUpdateOne) SetNillableDontseeit(i *int) *ContactUpdateOne {
  770. if i != nil {
  771. cuo.SetDontseeit(*i)
  772. }
  773. return cuo
  774. }
  775. // AddDontseeit adds i to the "dontseeit" field.
  776. func (cuo *ContactUpdateOne) AddDontseeit(i int) *ContactUpdateOne {
  777. cuo.mutation.AddDontseeit(i)
  778. return cuo
  779. }
  780. // SetDontseeme sets the "dontseeme" field.
  781. func (cuo *ContactUpdateOne) SetDontseeme(i int) *ContactUpdateOne {
  782. cuo.mutation.ResetDontseeme()
  783. cuo.mutation.SetDontseeme(i)
  784. return cuo
  785. }
  786. // SetNillableDontseeme sets the "dontseeme" field if the given value is not nil.
  787. func (cuo *ContactUpdateOne) SetNillableDontseeme(i *int) *ContactUpdateOne {
  788. if i != nil {
  789. cuo.SetDontseeme(*i)
  790. }
  791. return cuo
  792. }
  793. // AddDontseeme adds i to the "dontseeme" field.
  794. func (cuo *ContactUpdateOne) AddDontseeme(i int) *ContactUpdateOne {
  795. cuo.mutation.AddDontseeme(i)
  796. return cuo
  797. }
  798. // SetLag sets the "lag" field.
  799. func (cuo *ContactUpdateOne) SetLag(s string) *ContactUpdateOne {
  800. cuo.mutation.SetLag(s)
  801. return cuo
  802. }
  803. // SetNillableLag sets the "lag" field if the given value is not nil.
  804. func (cuo *ContactUpdateOne) SetNillableLag(s *string) *ContactUpdateOne {
  805. if s != nil {
  806. cuo.SetLag(*s)
  807. }
  808. return cuo
  809. }
  810. // SetGid sets the "gid" field.
  811. func (cuo *ContactUpdateOne) SetGid(s string) *ContactUpdateOne {
  812. cuo.mutation.SetGid(s)
  813. return cuo
  814. }
  815. // SetNillableGid sets the "gid" field if the given value is not nil.
  816. func (cuo *ContactUpdateOne) SetNillableGid(s *string) *ContactUpdateOne {
  817. if s != nil {
  818. cuo.SetGid(*s)
  819. }
  820. return cuo
  821. }
  822. // SetGname sets the "gname" field.
  823. func (cuo *ContactUpdateOne) SetGname(s string) *ContactUpdateOne {
  824. cuo.mutation.SetGname(s)
  825. return cuo
  826. }
  827. // SetNillableGname sets the "gname" field if the given value is not nil.
  828. func (cuo *ContactUpdateOne) SetNillableGname(s *string) *ContactUpdateOne {
  829. if s != nil {
  830. cuo.SetGname(*s)
  831. }
  832. return cuo
  833. }
  834. // SetV3 sets the "v3" field.
  835. func (cuo *ContactUpdateOne) SetV3(s string) *ContactUpdateOne {
  836. cuo.mutation.SetV3(s)
  837. return cuo
  838. }
  839. // SetNillableV3 sets the "v3" field if the given value is not nil.
  840. func (cuo *ContactUpdateOne) SetNillableV3(s *string) *ContactUpdateOne {
  841. if s != nil {
  842. cuo.SetV3(*s)
  843. }
  844. return cuo
  845. }
  846. // AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by IDs.
  847. func (cuo *ContactUpdateOne) AddContactRelationshipIDs(ids ...uint64) *ContactUpdateOne {
  848. cuo.mutation.AddContactRelationshipIDs(ids...)
  849. return cuo
  850. }
  851. // AddContactRelationships adds the "contact_relationships" edges to the LabelRelationship entity.
  852. func (cuo *ContactUpdateOne) AddContactRelationships(l ...*LabelRelationship) *ContactUpdateOne {
  853. ids := make([]uint64, len(l))
  854. for i := range l {
  855. ids[i] = l[i].ID
  856. }
  857. return cuo.AddContactRelationshipIDs(ids...)
  858. }
  859. // AddContactMessageIDs adds the "contact_messages" edge to the MessageRecords entity by IDs.
  860. func (cuo *ContactUpdateOne) AddContactMessageIDs(ids ...uint64) *ContactUpdateOne {
  861. cuo.mutation.AddContactMessageIDs(ids...)
  862. return cuo
  863. }
  864. // AddContactMessages adds the "contact_messages" edges to the MessageRecords entity.
  865. func (cuo *ContactUpdateOne) AddContactMessages(m ...*MessageRecords) *ContactUpdateOne {
  866. ids := make([]uint64, len(m))
  867. for i := range m {
  868. ids[i] = m[i].ID
  869. }
  870. return cuo.AddContactMessageIDs(ids...)
  871. }
  872. // Mutation returns the ContactMutation object of the builder.
  873. func (cuo *ContactUpdateOne) Mutation() *ContactMutation {
  874. return cuo.mutation
  875. }
  876. // ClearContactRelationships clears all "contact_relationships" edges to the LabelRelationship entity.
  877. func (cuo *ContactUpdateOne) ClearContactRelationships() *ContactUpdateOne {
  878. cuo.mutation.ClearContactRelationships()
  879. return cuo
  880. }
  881. // RemoveContactRelationshipIDs removes the "contact_relationships" edge to LabelRelationship entities by IDs.
  882. func (cuo *ContactUpdateOne) RemoveContactRelationshipIDs(ids ...uint64) *ContactUpdateOne {
  883. cuo.mutation.RemoveContactRelationshipIDs(ids...)
  884. return cuo
  885. }
  886. // RemoveContactRelationships removes "contact_relationships" edges to LabelRelationship entities.
  887. func (cuo *ContactUpdateOne) RemoveContactRelationships(l ...*LabelRelationship) *ContactUpdateOne {
  888. ids := make([]uint64, len(l))
  889. for i := range l {
  890. ids[i] = l[i].ID
  891. }
  892. return cuo.RemoveContactRelationshipIDs(ids...)
  893. }
  894. // ClearContactMessages clears all "contact_messages" edges to the MessageRecords entity.
  895. func (cuo *ContactUpdateOne) ClearContactMessages() *ContactUpdateOne {
  896. cuo.mutation.ClearContactMessages()
  897. return cuo
  898. }
  899. // RemoveContactMessageIDs removes the "contact_messages" edge to MessageRecords entities by IDs.
  900. func (cuo *ContactUpdateOne) RemoveContactMessageIDs(ids ...uint64) *ContactUpdateOne {
  901. cuo.mutation.RemoveContactMessageIDs(ids...)
  902. return cuo
  903. }
  904. // RemoveContactMessages removes "contact_messages" edges to MessageRecords entities.
  905. func (cuo *ContactUpdateOne) RemoveContactMessages(m ...*MessageRecords) *ContactUpdateOne {
  906. ids := make([]uint64, len(m))
  907. for i := range m {
  908. ids[i] = m[i].ID
  909. }
  910. return cuo.RemoveContactMessageIDs(ids...)
  911. }
  912. // Where appends a list predicates to the ContactUpdate builder.
  913. func (cuo *ContactUpdateOne) Where(ps ...predicate.Contact) *ContactUpdateOne {
  914. cuo.mutation.Where(ps...)
  915. return cuo
  916. }
  917. // Select allows selecting one or more fields (columns) of the returned entity.
  918. // The default is selecting all fields defined in the entity schema.
  919. func (cuo *ContactUpdateOne) Select(field string, fields ...string) *ContactUpdateOne {
  920. cuo.fields = append([]string{field}, fields...)
  921. return cuo
  922. }
  923. // Save executes the query and returns the updated Contact entity.
  924. func (cuo *ContactUpdateOne) Save(ctx context.Context) (*Contact, error) {
  925. if err := cuo.defaults(); err != nil {
  926. return nil, err
  927. }
  928. return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks)
  929. }
  930. // SaveX is like Save, but panics if an error occurs.
  931. func (cuo *ContactUpdateOne) SaveX(ctx context.Context) *Contact {
  932. node, err := cuo.Save(ctx)
  933. if err != nil {
  934. panic(err)
  935. }
  936. return node
  937. }
  938. // Exec executes the query on the entity.
  939. func (cuo *ContactUpdateOne) Exec(ctx context.Context) error {
  940. _, err := cuo.Save(ctx)
  941. return err
  942. }
  943. // ExecX is like Exec, but panics if an error occurs.
  944. func (cuo *ContactUpdateOne) ExecX(ctx context.Context) {
  945. if err := cuo.Exec(ctx); err != nil {
  946. panic(err)
  947. }
  948. }
  949. // defaults sets the default values of the builder before save.
  950. func (cuo *ContactUpdateOne) defaults() error {
  951. if _, ok := cuo.mutation.UpdatedAt(); !ok {
  952. if contact.UpdateDefaultUpdatedAt == nil {
  953. return fmt.Errorf("ent: uninitialized contact.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  954. }
  955. v := contact.UpdateDefaultUpdatedAt()
  956. cuo.mutation.SetUpdatedAt(v)
  957. }
  958. return nil
  959. }
  960. func (cuo *ContactUpdateOne) sqlSave(ctx context.Context) (_node *Contact, err error) {
  961. _spec := sqlgraph.NewUpdateSpec(contact.Table, contact.Columns, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64))
  962. id, ok := cuo.mutation.ID()
  963. if !ok {
  964. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Contact.id" for update`)}
  965. }
  966. _spec.Node.ID.Value = id
  967. if fields := cuo.fields; len(fields) > 0 {
  968. _spec.Node.Columns = make([]string, 0, len(fields))
  969. _spec.Node.Columns = append(_spec.Node.Columns, contact.FieldID)
  970. for _, f := range fields {
  971. if !contact.ValidColumn(f) {
  972. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  973. }
  974. if f != contact.FieldID {
  975. _spec.Node.Columns = append(_spec.Node.Columns, f)
  976. }
  977. }
  978. }
  979. if ps := cuo.mutation.predicates; len(ps) > 0 {
  980. _spec.Predicate = func(selector *sql.Selector) {
  981. for i := range ps {
  982. ps[i](selector)
  983. }
  984. }
  985. }
  986. if value, ok := cuo.mutation.UpdatedAt(); ok {
  987. _spec.SetField(contact.FieldUpdatedAt, field.TypeTime, value)
  988. }
  989. if value, ok := cuo.mutation.Status(); ok {
  990. _spec.SetField(contact.FieldStatus, field.TypeUint8, value)
  991. }
  992. if value, ok := cuo.mutation.AddedStatus(); ok {
  993. _spec.AddField(contact.FieldStatus, field.TypeUint8, value)
  994. }
  995. if cuo.mutation.StatusCleared() {
  996. _spec.ClearField(contact.FieldStatus, field.TypeUint8)
  997. }
  998. if value, ok := cuo.mutation.DeletedAt(); ok {
  999. _spec.SetField(contact.FieldDeletedAt, field.TypeTime, value)
  1000. }
  1001. if cuo.mutation.DeletedAtCleared() {
  1002. _spec.ClearField(contact.FieldDeletedAt, field.TypeTime)
  1003. }
  1004. if value, ok := cuo.mutation.WxWxid(); ok {
  1005. _spec.SetField(contact.FieldWxWxid, field.TypeString, value)
  1006. }
  1007. if cuo.mutation.WxWxidCleared() {
  1008. _spec.ClearField(contact.FieldWxWxid, field.TypeString)
  1009. }
  1010. if value, ok := cuo.mutation.GetType(); ok {
  1011. _spec.SetField(contact.FieldType, field.TypeInt, value)
  1012. }
  1013. if value, ok := cuo.mutation.AddedType(); ok {
  1014. _spec.AddField(contact.FieldType, field.TypeInt, value)
  1015. }
  1016. if cuo.mutation.TypeCleared() {
  1017. _spec.ClearField(contact.FieldType, field.TypeInt)
  1018. }
  1019. if value, ok := cuo.mutation.Wxid(); ok {
  1020. _spec.SetField(contact.FieldWxid, field.TypeString, value)
  1021. }
  1022. if value, ok := cuo.mutation.Account(); ok {
  1023. _spec.SetField(contact.FieldAccount, field.TypeString, value)
  1024. }
  1025. if value, ok := cuo.mutation.Nickname(); ok {
  1026. _spec.SetField(contact.FieldNickname, field.TypeString, value)
  1027. }
  1028. if value, ok := cuo.mutation.Markname(); ok {
  1029. _spec.SetField(contact.FieldMarkname, field.TypeString, value)
  1030. }
  1031. if value, ok := cuo.mutation.Headimg(); ok {
  1032. _spec.SetField(contact.FieldHeadimg, field.TypeString, value)
  1033. }
  1034. if value, ok := cuo.mutation.Sex(); ok {
  1035. _spec.SetField(contact.FieldSex, field.TypeInt, value)
  1036. }
  1037. if value, ok := cuo.mutation.AddedSex(); ok {
  1038. _spec.AddField(contact.FieldSex, field.TypeInt, value)
  1039. }
  1040. if value, ok := cuo.mutation.Starrole(); ok {
  1041. _spec.SetField(contact.FieldStarrole, field.TypeString, value)
  1042. }
  1043. if value, ok := cuo.mutation.Dontseeit(); ok {
  1044. _spec.SetField(contact.FieldDontseeit, field.TypeInt, value)
  1045. }
  1046. if value, ok := cuo.mutation.AddedDontseeit(); ok {
  1047. _spec.AddField(contact.FieldDontseeit, field.TypeInt, value)
  1048. }
  1049. if value, ok := cuo.mutation.Dontseeme(); ok {
  1050. _spec.SetField(contact.FieldDontseeme, field.TypeInt, value)
  1051. }
  1052. if value, ok := cuo.mutation.AddedDontseeme(); ok {
  1053. _spec.AddField(contact.FieldDontseeme, field.TypeInt, value)
  1054. }
  1055. if value, ok := cuo.mutation.Lag(); ok {
  1056. _spec.SetField(contact.FieldLag, field.TypeString, value)
  1057. }
  1058. if value, ok := cuo.mutation.Gid(); ok {
  1059. _spec.SetField(contact.FieldGid, field.TypeString, value)
  1060. }
  1061. if value, ok := cuo.mutation.Gname(); ok {
  1062. _spec.SetField(contact.FieldGname, field.TypeString, value)
  1063. }
  1064. if value, ok := cuo.mutation.V3(); ok {
  1065. _spec.SetField(contact.FieldV3, field.TypeString, value)
  1066. }
  1067. if cuo.mutation.ContactRelationshipsCleared() {
  1068. edge := &sqlgraph.EdgeSpec{
  1069. Rel: sqlgraph.O2M,
  1070. Inverse: false,
  1071. Table: contact.ContactRelationshipsTable,
  1072. Columns: []string{contact.ContactRelationshipsColumn},
  1073. Bidi: false,
  1074. Target: &sqlgraph.EdgeTarget{
  1075. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  1076. },
  1077. }
  1078. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1079. }
  1080. if nodes := cuo.mutation.RemovedContactRelationshipsIDs(); len(nodes) > 0 && !cuo.mutation.ContactRelationshipsCleared() {
  1081. edge := &sqlgraph.EdgeSpec{
  1082. Rel: sqlgraph.O2M,
  1083. Inverse: false,
  1084. Table: contact.ContactRelationshipsTable,
  1085. Columns: []string{contact.ContactRelationshipsColumn},
  1086. Bidi: false,
  1087. Target: &sqlgraph.EdgeTarget{
  1088. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  1089. },
  1090. }
  1091. for _, k := range nodes {
  1092. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1093. }
  1094. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1095. }
  1096. if nodes := cuo.mutation.ContactRelationshipsIDs(); len(nodes) > 0 {
  1097. edge := &sqlgraph.EdgeSpec{
  1098. Rel: sqlgraph.O2M,
  1099. Inverse: false,
  1100. Table: contact.ContactRelationshipsTable,
  1101. Columns: []string{contact.ContactRelationshipsColumn},
  1102. Bidi: false,
  1103. Target: &sqlgraph.EdgeTarget{
  1104. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  1105. },
  1106. }
  1107. for _, k := range nodes {
  1108. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1109. }
  1110. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1111. }
  1112. if cuo.mutation.ContactMessagesCleared() {
  1113. edge := &sqlgraph.EdgeSpec{
  1114. Rel: sqlgraph.O2M,
  1115. Inverse: false,
  1116. Table: contact.ContactMessagesTable,
  1117. Columns: []string{contact.ContactMessagesColumn},
  1118. Bidi: false,
  1119. Target: &sqlgraph.EdgeTarget{
  1120. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  1121. },
  1122. }
  1123. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1124. }
  1125. if nodes := cuo.mutation.RemovedContactMessagesIDs(); len(nodes) > 0 && !cuo.mutation.ContactMessagesCleared() {
  1126. edge := &sqlgraph.EdgeSpec{
  1127. Rel: sqlgraph.O2M,
  1128. Inverse: false,
  1129. Table: contact.ContactMessagesTable,
  1130. Columns: []string{contact.ContactMessagesColumn},
  1131. Bidi: false,
  1132. Target: &sqlgraph.EdgeTarget{
  1133. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  1134. },
  1135. }
  1136. for _, k := range nodes {
  1137. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1138. }
  1139. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1140. }
  1141. if nodes := cuo.mutation.ContactMessagesIDs(); len(nodes) > 0 {
  1142. edge := &sqlgraph.EdgeSpec{
  1143. Rel: sqlgraph.O2M,
  1144. Inverse: false,
  1145. Table: contact.ContactMessagesTable,
  1146. Columns: []string{contact.ContactMessagesColumn},
  1147. Bidi: false,
  1148. Target: &sqlgraph.EdgeTarget{
  1149. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  1150. },
  1151. }
  1152. for _, k := range nodes {
  1153. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1154. }
  1155. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1156. }
  1157. _node = &Contact{config: cuo.config}
  1158. _spec.Assign = _node.assignValues
  1159. _spec.ScanValues = _node.scanValues
  1160. if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
  1161. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1162. err = &NotFoundError{contact.Label}
  1163. } else if sqlgraph.IsConstraintError(err) {
  1164. err = &ConstraintError{msg: err.Error(), wrap: err}
  1165. }
  1166. return nil, err
  1167. }
  1168. cuo.mutation.done = true
  1169. return _node, nil
  1170. }