contact_update.go 40 KB

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