contact_update.go 39 KB

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