contact_update.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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/predicate"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // ContactUpdate is the builder for updating Contact entities.
  15. type ContactUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *ContactMutation
  19. }
  20. // Where appends a list predicates to the ContactUpdate builder.
  21. func (cu *ContactUpdate) Where(ps ...predicate.Contact) *ContactUpdate {
  22. cu.mutation.Where(ps...)
  23. return cu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (cu *ContactUpdate) SetUpdatedAt(t time.Time) *ContactUpdate {
  27. cu.mutation.SetUpdatedAt(t)
  28. return cu
  29. }
  30. // SetStatus sets the "status" field.
  31. func (cu *ContactUpdate) SetStatus(u uint8) *ContactUpdate {
  32. cu.mutation.ResetStatus()
  33. cu.mutation.SetStatus(u)
  34. return cu
  35. }
  36. // SetNillableStatus sets the "status" field if the given value is not nil.
  37. func (cu *ContactUpdate) SetNillableStatus(u *uint8) *ContactUpdate {
  38. if u != nil {
  39. cu.SetStatus(*u)
  40. }
  41. return cu
  42. }
  43. // AddStatus adds u to the "status" field.
  44. func (cu *ContactUpdate) AddStatus(u int8) *ContactUpdate {
  45. cu.mutation.AddStatus(u)
  46. return cu
  47. }
  48. // ClearStatus clears the value of the "status" field.
  49. func (cu *ContactUpdate) ClearStatus() *ContactUpdate {
  50. cu.mutation.ClearStatus()
  51. return cu
  52. }
  53. // SetDeletedAt sets the "deleted_at" field.
  54. func (cu *ContactUpdate) SetDeletedAt(t time.Time) *ContactUpdate {
  55. cu.mutation.SetDeletedAt(t)
  56. return cu
  57. }
  58. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  59. func (cu *ContactUpdate) SetNillableDeletedAt(t *time.Time) *ContactUpdate {
  60. if t != nil {
  61. cu.SetDeletedAt(*t)
  62. }
  63. return cu
  64. }
  65. // ClearDeletedAt clears the value of the "deleted_at" field.
  66. func (cu *ContactUpdate) ClearDeletedAt() *ContactUpdate {
  67. cu.mutation.ClearDeletedAt()
  68. return cu
  69. }
  70. // SetWxWxid sets the "wx_wxid" field.
  71. func (cu *ContactUpdate) SetWxWxid(s string) *ContactUpdate {
  72. cu.mutation.SetWxWxid(s)
  73. return cu
  74. }
  75. // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
  76. func (cu *ContactUpdate) SetNillableWxWxid(s *string) *ContactUpdate {
  77. if s != nil {
  78. cu.SetWxWxid(*s)
  79. }
  80. return cu
  81. }
  82. // ClearWxWxid clears the value of the "wx_wxid" field.
  83. func (cu *ContactUpdate) ClearWxWxid() *ContactUpdate {
  84. cu.mutation.ClearWxWxid()
  85. return cu
  86. }
  87. // SetType sets the "type" field.
  88. func (cu *ContactUpdate) SetType(i int) *ContactUpdate {
  89. cu.mutation.ResetType()
  90. cu.mutation.SetType(i)
  91. return cu
  92. }
  93. // SetNillableType sets the "type" field if the given value is not nil.
  94. func (cu *ContactUpdate) SetNillableType(i *int) *ContactUpdate {
  95. if i != nil {
  96. cu.SetType(*i)
  97. }
  98. return cu
  99. }
  100. // AddType adds i to the "type" field.
  101. func (cu *ContactUpdate) AddType(i int) *ContactUpdate {
  102. cu.mutation.AddType(i)
  103. return cu
  104. }
  105. // ClearType clears the value of the "type" field.
  106. func (cu *ContactUpdate) ClearType() *ContactUpdate {
  107. cu.mutation.ClearType()
  108. return cu
  109. }
  110. // SetWxid sets the "wxid" field.
  111. func (cu *ContactUpdate) SetWxid(s string) *ContactUpdate {
  112. cu.mutation.SetWxid(s)
  113. return cu
  114. }
  115. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  116. func (cu *ContactUpdate) SetNillableWxid(s *string) *ContactUpdate {
  117. if s != nil {
  118. cu.SetWxid(*s)
  119. }
  120. return cu
  121. }
  122. // SetAccount sets the "account" field.
  123. func (cu *ContactUpdate) SetAccount(s string) *ContactUpdate {
  124. cu.mutation.SetAccount(s)
  125. return cu
  126. }
  127. // SetNillableAccount sets the "account" field if the given value is not nil.
  128. func (cu *ContactUpdate) SetNillableAccount(s *string) *ContactUpdate {
  129. if s != nil {
  130. cu.SetAccount(*s)
  131. }
  132. return cu
  133. }
  134. // SetNickname sets the "nickname" field.
  135. func (cu *ContactUpdate) SetNickname(s string) *ContactUpdate {
  136. cu.mutation.SetNickname(s)
  137. return cu
  138. }
  139. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  140. func (cu *ContactUpdate) SetNillableNickname(s *string) *ContactUpdate {
  141. if s != nil {
  142. cu.SetNickname(*s)
  143. }
  144. return cu
  145. }
  146. // SetMarkname sets the "markname" field.
  147. func (cu *ContactUpdate) SetMarkname(s string) *ContactUpdate {
  148. cu.mutation.SetMarkname(s)
  149. return cu
  150. }
  151. // SetNillableMarkname sets the "markname" field if the given value is not nil.
  152. func (cu *ContactUpdate) SetNillableMarkname(s *string) *ContactUpdate {
  153. if s != nil {
  154. cu.SetMarkname(*s)
  155. }
  156. return cu
  157. }
  158. // SetHeadimg sets the "headimg" field.
  159. func (cu *ContactUpdate) SetHeadimg(s string) *ContactUpdate {
  160. cu.mutation.SetHeadimg(s)
  161. return cu
  162. }
  163. // SetNillableHeadimg sets the "headimg" field if the given value is not nil.
  164. func (cu *ContactUpdate) SetNillableHeadimg(s *string) *ContactUpdate {
  165. if s != nil {
  166. cu.SetHeadimg(*s)
  167. }
  168. return cu
  169. }
  170. // SetSex sets the "sex" field.
  171. func (cu *ContactUpdate) SetSex(i int) *ContactUpdate {
  172. cu.mutation.ResetSex()
  173. cu.mutation.SetSex(i)
  174. return cu
  175. }
  176. // SetNillableSex sets the "sex" field if the given value is not nil.
  177. func (cu *ContactUpdate) SetNillableSex(i *int) *ContactUpdate {
  178. if i != nil {
  179. cu.SetSex(*i)
  180. }
  181. return cu
  182. }
  183. // AddSex adds i to the "sex" field.
  184. func (cu *ContactUpdate) AddSex(i int) *ContactUpdate {
  185. cu.mutation.AddSex(i)
  186. return cu
  187. }
  188. // SetStarrole sets the "starrole" field.
  189. func (cu *ContactUpdate) SetStarrole(s string) *ContactUpdate {
  190. cu.mutation.SetStarrole(s)
  191. return cu
  192. }
  193. // SetNillableStarrole sets the "starrole" field if the given value is not nil.
  194. func (cu *ContactUpdate) SetNillableStarrole(s *string) *ContactUpdate {
  195. if s != nil {
  196. cu.SetStarrole(*s)
  197. }
  198. return cu
  199. }
  200. // SetDontseeit sets the "dontseeit" field.
  201. func (cu *ContactUpdate) SetDontseeit(i int) *ContactUpdate {
  202. cu.mutation.ResetDontseeit()
  203. cu.mutation.SetDontseeit(i)
  204. return cu
  205. }
  206. // SetNillableDontseeit sets the "dontseeit" field if the given value is not nil.
  207. func (cu *ContactUpdate) SetNillableDontseeit(i *int) *ContactUpdate {
  208. if i != nil {
  209. cu.SetDontseeit(*i)
  210. }
  211. return cu
  212. }
  213. // AddDontseeit adds i to the "dontseeit" field.
  214. func (cu *ContactUpdate) AddDontseeit(i int) *ContactUpdate {
  215. cu.mutation.AddDontseeit(i)
  216. return cu
  217. }
  218. // SetDontseeme sets the "dontseeme" field.
  219. func (cu *ContactUpdate) SetDontseeme(i int) *ContactUpdate {
  220. cu.mutation.ResetDontseeme()
  221. cu.mutation.SetDontseeme(i)
  222. return cu
  223. }
  224. // SetNillableDontseeme sets the "dontseeme" field if the given value is not nil.
  225. func (cu *ContactUpdate) SetNillableDontseeme(i *int) *ContactUpdate {
  226. if i != nil {
  227. cu.SetDontseeme(*i)
  228. }
  229. return cu
  230. }
  231. // AddDontseeme adds i to the "dontseeme" field.
  232. func (cu *ContactUpdate) AddDontseeme(i int) *ContactUpdate {
  233. cu.mutation.AddDontseeme(i)
  234. return cu
  235. }
  236. // SetLag sets the "lag" field.
  237. func (cu *ContactUpdate) SetLag(s string) *ContactUpdate {
  238. cu.mutation.SetLag(s)
  239. return cu
  240. }
  241. // SetNillableLag sets the "lag" field if the given value is not nil.
  242. func (cu *ContactUpdate) SetNillableLag(s *string) *ContactUpdate {
  243. if s != nil {
  244. cu.SetLag(*s)
  245. }
  246. return cu
  247. }
  248. // SetGid sets the "gid" field.
  249. func (cu *ContactUpdate) SetGid(s string) *ContactUpdate {
  250. cu.mutation.SetGid(s)
  251. return cu
  252. }
  253. // SetNillableGid sets the "gid" field if the given value is not nil.
  254. func (cu *ContactUpdate) SetNillableGid(s *string) *ContactUpdate {
  255. if s != nil {
  256. cu.SetGid(*s)
  257. }
  258. return cu
  259. }
  260. // SetGname sets the "gname" field.
  261. func (cu *ContactUpdate) SetGname(s string) *ContactUpdate {
  262. cu.mutation.SetGname(s)
  263. return cu
  264. }
  265. // SetNillableGname sets the "gname" field if the given value is not nil.
  266. func (cu *ContactUpdate) SetNillableGname(s *string) *ContactUpdate {
  267. if s != nil {
  268. cu.SetGname(*s)
  269. }
  270. return cu
  271. }
  272. // SetV3 sets the "v3" field.
  273. func (cu *ContactUpdate) SetV3(s string) *ContactUpdate {
  274. cu.mutation.SetV3(s)
  275. return cu
  276. }
  277. // SetNillableV3 sets the "v3" field if the given value is not nil.
  278. func (cu *ContactUpdate) SetNillableV3(s *string) *ContactUpdate {
  279. if s != nil {
  280. cu.SetV3(*s)
  281. }
  282. return cu
  283. }
  284. // Mutation returns the ContactMutation object of the builder.
  285. func (cu *ContactUpdate) Mutation() *ContactMutation {
  286. return cu.mutation
  287. }
  288. // Save executes the query and returns the number of nodes affected by the update operation.
  289. func (cu *ContactUpdate) Save(ctx context.Context) (int, error) {
  290. if err := cu.defaults(); err != nil {
  291. return 0, err
  292. }
  293. return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks)
  294. }
  295. // SaveX is like Save, but panics if an error occurs.
  296. func (cu *ContactUpdate) SaveX(ctx context.Context) int {
  297. affected, err := cu.Save(ctx)
  298. if err != nil {
  299. panic(err)
  300. }
  301. return affected
  302. }
  303. // Exec executes the query.
  304. func (cu *ContactUpdate) Exec(ctx context.Context) error {
  305. _, err := cu.Save(ctx)
  306. return err
  307. }
  308. // ExecX is like Exec, but panics if an error occurs.
  309. func (cu *ContactUpdate) ExecX(ctx context.Context) {
  310. if err := cu.Exec(ctx); err != nil {
  311. panic(err)
  312. }
  313. }
  314. // defaults sets the default values of the builder before save.
  315. func (cu *ContactUpdate) defaults() error {
  316. if _, ok := cu.mutation.UpdatedAt(); !ok {
  317. if contact.UpdateDefaultUpdatedAt == nil {
  318. return fmt.Errorf("ent: uninitialized contact.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  319. }
  320. v := contact.UpdateDefaultUpdatedAt()
  321. cu.mutation.SetUpdatedAt(v)
  322. }
  323. return nil
  324. }
  325. func (cu *ContactUpdate) sqlSave(ctx context.Context) (n int, err error) {
  326. _spec := sqlgraph.NewUpdateSpec(contact.Table, contact.Columns, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64))
  327. if ps := cu.mutation.predicates; len(ps) > 0 {
  328. _spec.Predicate = func(selector *sql.Selector) {
  329. for i := range ps {
  330. ps[i](selector)
  331. }
  332. }
  333. }
  334. if value, ok := cu.mutation.UpdatedAt(); ok {
  335. _spec.SetField(contact.FieldUpdatedAt, field.TypeTime, value)
  336. }
  337. if value, ok := cu.mutation.Status(); ok {
  338. _spec.SetField(contact.FieldStatus, field.TypeUint8, value)
  339. }
  340. if value, ok := cu.mutation.AddedStatus(); ok {
  341. _spec.AddField(contact.FieldStatus, field.TypeUint8, value)
  342. }
  343. if cu.mutation.StatusCleared() {
  344. _spec.ClearField(contact.FieldStatus, field.TypeUint8)
  345. }
  346. if value, ok := cu.mutation.DeletedAt(); ok {
  347. _spec.SetField(contact.FieldDeletedAt, field.TypeTime, value)
  348. }
  349. if cu.mutation.DeletedAtCleared() {
  350. _spec.ClearField(contact.FieldDeletedAt, field.TypeTime)
  351. }
  352. if value, ok := cu.mutation.WxWxid(); ok {
  353. _spec.SetField(contact.FieldWxWxid, field.TypeString, value)
  354. }
  355. if cu.mutation.WxWxidCleared() {
  356. _spec.ClearField(contact.FieldWxWxid, field.TypeString)
  357. }
  358. if value, ok := cu.mutation.GetType(); ok {
  359. _spec.SetField(contact.FieldType, field.TypeInt, value)
  360. }
  361. if value, ok := cu.mutation.AddedType(); ok {
  362. _spec.AddField(contact.FieldType, field.TypeInt, value)
  363. }
  364. if cu.mutation.TypeCleared() {
  365. _spec.ClearField(contact.FieldType, field.TypeInt)
  366. }
  367. if value, ok := cu.mutation.Wxid(); ok {
  368. _spec.SetField(contact.FieldWxid, field.TypeString, value)
  369. }
  370. if value, ok := cu.mutation.Account(); ok {
  371. _spec.SetField(contact.FieldAccount, field.TypeString, value)
  372. }
  373. if value, ok := cu.mutation.Nickname(); ok {
  374. _spec.SetField(contact.FieldNickname, field.TypeString, value)
  375. }
  376. if value, ok := cu.mutation.Markname(); ok {
  377. _spec.SetField(contact.FieldMarkname, field.TypeString, value)
  378. }
  379. if value, ok := cu.mutation.Headimg(); ok {
  380. _spec.SetField(contact.FieldHeadimg, field.TypeString, value)
  381. }
  382. if value, ok := cu.mutation.Sex(); ok {
  383. _spec.SetField(contact.FieldSex, field.TypeInt, value)
  384. }
  385. if value, ok := cu.mutation.AddedSex(); ok {
  386. _spec.AddField(contact.FieldSex, field.TypeInt, value)
  387. }
  388. if value, ok := cu.mutation.Starrole(); ok {
  389. _spec.SetField(contact.FieldStarrole, field.TypeString, value)
  390. }
  391. if value, ok := cu.mutation.Dontseeit(); ok {
  392. _spec.SetField(contact.FieldDontseeit, field.TypeInt, value)
  393. }
  394. if value, ok := cu.mutation.AddedDontseeit(); ok {
  395. _spec.AddField(contact.FieldDontseeit, field.TypeInt, value)
  396. }
  397. if value, ok := cu.mutation.Dontseeme(); ok {
  398. _spec.SetField(contact.FieldDontseeme, field.TypeInt, value)
  399. }
  400. if value, ok := cu.mutation.AddedDontseeme(); ok {
  401. _spec.AddField(contact.FieldDontseeme, field.TypeInt, value)
  402. }
  403. if value, ok := cu.mutation.Lag(); ok {
  404. _spec.SetField(contact.FieldLag, field.TypeString, value)
  405. }
  406. if value, ok := cu.mutation.Gid(); ok {
  407. _spec.SetField(contact.FieldGid, field.TypeString, value)
  408. }
  409. if value, ok := cu.mutation.Gname(); ok {
  410. _spec.SetField(contact.FieldGname, field.TypeString, value)
  411. }
  412. if value, ok := cu.mutation.V3(); ok {
  413. _spec.SetField(contact.FieldV3, field.TypeString, value)
  414. }
  415. if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
  416. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  417. err = &NotFoundError{contact.Label}
  418. } else if sqlgraph.IsConstraintError(err) {
  419. err = &ConstraintError{msg: err.Error(), wrap: err}
  420. }
  421. return 0, err
  422. }
  423. cu.mutation.done = true
  424. return n, nil
  425. }
  426. // ContactUpdateOne is the builder for updating a single Contact entity.
  427. type ContactUpdateOne struct {
  428. config
  429. fields []string
  430. hooks []Hook
  431. mutation *ContactMutation
  432. }
  433. // SetUpdatedAt sets the "updated_at" field.
  434. func (cuo *ContactUpdateOne) SetUpdatedAt(t time.Time) *ContactUpdateOne {
  435. cuo.mutation.SetUpdatedAt(t)
  436. return cuo
  437. }
  438. // SetStatus sets the "status" field.
  439. func (cuo *ContactUpdateOne) SetStatus(u uint8) *ContactUpdateOne {
  440. cuo.mutation.ResetStatus()
  441. cuo.mutation.SetStatus(u)
  442. return cuo
  443. }
  444. // SetNillableStatus sets the "status" field if the given value is not nil.
  445. func (cuo *ContactUpdateOne) SetNillableStatus(u *uint8) *ContactUpdateOne {
  446. if u != nil {
  447. cuo.SetStatus(*u)
  448. }
  449. return cuo
  450. }
  451. // AddStatus adds u to the "status" field.
  452. func (cuo *ContactUpdateOne) AddStatus(u int8) *ContactUpdateOne {
  453. cuo.mutation.AddStatus(u)
  454. return cuo
  455. }
  456. // ClearStatus clears the value of the "status" field.
  457. func (cuo *ContactUpdateOne) ClearStatus() *ContactUpdateOne {
  458. cuo.mutation.ClearStatus()
  459. return cuo
  460. }
  461. // SetDeletedAt sets the "deleted_at" field.
  462. func (cuo *ContactUpdateOne) SetDeletedAt(t time.Time) *ContactUpdateOne {
  463. cuo.mutation.SetDeletedAt(t)
  464. return cuo
  465. }
  466. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  467. func (cuo *ContactUpdateOne) SetNillableDeletedAt(t *time.Time) *ContactUpdateOne {
  468. if t != nil {
  469. cuo.SetDeletedAt(*t)
  470. }
  471. return cuo
  472. }
  473. // ClearDeletedAt clears the value of the "deleted_at" field.
  474. func (cuo *ContactUpdateOne) ClearDeletedAt() *ContactUpdateOne {
  475. cuo.mutation.ClearDeletedAt()
  476. return cuo
  477. }
  478. // SetWxWxid sets the "wx_wxid" field.
  479. func (cuo *ContactUpdateOne) SetWxWxid(s string) *ContactUpdateOne {
  480. cuo.mutation.SetWxWxid(s)
  481. return cuo
  482. }
  483. // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
  484. func (cuo *ContactUpdateOne) SetNillableWxWxid(s *string) *ContactUpdateOne {
  485. if s != nil {
  486. cuo.SetWxWxid(*s)
  487. }
  488. return cuo
  489. }
  490. // ClearWxWxid clears the value of the "wx_wxid" field.
  491. func (cuo *ContactUpdateOne) ClearWxWxid() *ContactUpdateOne {
  492. cuo.mutation.ClearWxWxid()
  493. return cuo
  494. }
  495. // SetType sets the "type" field.
  496. func (cuo *ContactUpdateOne) SetType(i int) *ContactUpdateOne {
  497. cuo.mutation.ResetType()
  498. cuo.mutation.SetType(i)
  499. return cuo
  500. }
  501. // SetNillableType sets the "type" field if the given value is not nil.
  502. func (cuo *ContactUpdateOne) SetNillableType(i *int) *ContactUpdateOne {
  503. if i != nil {
  504. cuo.SetType(*i)
  505. }
  506. return cuo
  507. }
  508. // AddType adds i to the "type" field.
  509. func (cuo *ContactUpdateOne) AddType(i int) *ContactUpdateOne {
  510. cuo.mutation.AddType(i)
  511. return cuo
  512. }
  513. // ClearType clears the value of the "type" field.
  514. func (cuo *ContactUpdateOne) ClearType() *ContactUpdateOne {
  515. cuo.mutation.ClearType()
  516. return cuo
  517. }
  518. // SetWxid sets the "wxid" field.
  519. func (cuo *ContactUpdateOne) SetWxid(s string) *ContactUpdateOne {
  520. cuo.mutation.SetWxid(s)
  521. return cuo
  522. }
  523. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  524. func (cuo *ContactUpdateOne) SetNillableWxid(s *string) *ContactUpdateOne {
  525. if s != nil {
  526. cuo.SetWxid(*s)
  527. }
  528. return cuo
  529. }
  530. // SetAccount sets the "account" field.
  531. func (cuo *ContactUpdateOne) SetAccount(s string) *ContactUpdateOne {
  532. cuo.mutation.SetAccount(s)
  533. return cuo
  534. }
  535. // SetNillableAccount sets the "account" field if the given value is not nil.
  536. func (cuo *ContactUpdateOne) SetNillableAccount(s *string) *ContactUpdateOne {
  537. if s != nil {
  538. cuo.SetAccount(*s)
  539. }
  540. return cuo
  541. }
  542. // SetNickname sets the "nickname" field.
  543. func (cuo *ContactUpdateOne) SetNickname(s string) *ContactUpdateOne {
  544. cuo.mutation.SetNickname(s)
  545. return cuo
  546. }
  547. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  548. func (cuo *ContactUpdateOne) SetNillableNickname(s *string) *ContactUpdateOne {
  549. if s != nil {
  550. cuo.SetNickname(*s)
  551. }
  552. return cuo
  553. }
  554. // SetMarkname sets the "markname" field.
  555. func (cuo *ContactUpdateOne) SetMarkname(s string) *ContactUpdateOne {
  556. cuo.mutation.SetMarkname(s)
  557. return cuo
  558. }
  559. // SetNillableMarkname sets the "markname" field if the given value is not nil.
  560. func (cuo *ContactUpdateOne) SetNillableMarkname(s *string) *ContactUpdateOne {
  561. if s != nil {
  562. cuo.SetMarkname(*s)
  563. }
  564. return cuo
  565. }
  566. // SetHeadimg sets the "headimg" field.
  567. func (cuo *ContactUpdateOne) SetHeadimg(s string) *ContactUpdateOne {
  568. cuo.mutation.SetHeadimg(s)
  569. return cuo
  570. }
  571. // SetNillableHeadimg sets the "headimg" field if the given value is not nil.
  572. func (cuo *ContactUpdateOne) SetNillableHeadimg(s *string) *ContactUpdateOne {
  573. if s != nil {
  574. cuo.SetHeadimg(*s)
  575. }
  576. return cuo
  577. }
  578. // SetSex sets the "sex" field.
  579. func (cuo *ContactUpdateOne) SetSex(i int) *ContactUpdateOne {
  580. cuo.mutation.ResetSex()
  581. cuo.mutation.SetSex(i)
  582. return cuo
  583. }
  584. // SetNillableSex sets the "sex" field if the given value is not nil.
  585. func (cuo *ContactUpdateOne) SetNillableSex(i *int) *ContactUpdateOne {
  586. if i != nil {
  587. cuo.SetSex(*i)
  588. }
  589. return cuo
  590. }
  591. // AddSex adds i to the "sex" field.
  592. func (cuo *ContactUpdateOne) AddSex(i int) *ContactUpdateOne {
  593. cuo.mutation.AddSex(i)
  594. return cuo
  595. }
  596. // SetStarrole sets the "starrole" field.
  597. func (cuo *ContactUpdateOne) SetStarrole(s string) *ContactUpdateOne {
  598. cuo.mutation.SetStarrole(s)
  599. return cuo
  600. }
  601. // SetNillableStarrole sets the "starrole" field if the given value is not nil.
  602. func (cuo *ContactUpdateOne) SetNillableStarrole(s *string) *ContactUpdateOne {
  603. if s != nil {
  604. cuo.SetStarrole(*s)
  605. }
  606. return cuo
  607. }
  608. // SetDontseeit sets the "dontseeit" field.
  609. func (cuo *ContactUpdateOne) SetDontseeit(i int) *ContactUpdateOne {
  610. cuo.mutation.ResetDontseeit()
  611. cuo.mutation.SetDontseeit(i)
  612. return cuo
  613. }
  614. // SetNillableDontseeit sets the "dontseeit" field if the given value is not nil.
  615. func (cuo *ContactUpdateOne) SetNillableDontseeit(i *int) *ContactUpdateOne {
  616. if i != nil {
  617. cuo.SetDontseeit(*i)
  618. }
  619. return cuo
  620. }
  621. // AddDontseeit adds i to the "dontseeit" field.
  622. func (cuo *ContactUpdateOne) AddDontseeit(i int) *ContactUpdateOne {
  623. cuo.mutation.AddDontseeit(i)
  624. return cuo
  625. }
  626. // SetDontseeme sets the "dontseeme" field.
  627. func (cuo *ContactUpdateOne) SetDontseeme(i int) *ContactUpdateOne {
  628. cuo.mutation.ResetDontseeme()
  629. cuo.mutation.SetDontseeme(i)
  630. return cuo
  631. }
  632. // SetNillableDontseeme sets the "dontseeme" field if the given value is not nil.
  633. func (cuo *ContactUpdateOne) SetNillableDontseeme(i *int) *ContactUpdateOne {
  634. if i != nil {
  635. cuo.SetDontseeme(*i)
  636. }
  637. return cuo
  638. }
  639. // AddDontseeme adds i to the "dontseeme" field.
  640. func (cuo *ContactUpdateOne) AddDontseeme(i int) *ContactUpdateOne {
  641. cuo.mutation.AddDontseeme(i)
  642. return cuo
  643. }
  644. // SetLag sets the "lag" field.
  645. func (cuo *ContactUpdateOne) SetLag(s string) *ContactUpdateOne {
  646. cuo.mutation.SetLag(s)
  647. return cuo
  648. }
  649. // SetNillableLag sets the "lag" field if the given value is not nil.
  650. func (cuo *ContactUpdateOne) SetNillableLag(s *string) *ContactUpdateOne {
  651. if s != nil {
  652. cuo.SetLag(*s)
  653. }
  654. return cuo
  655. }
  656. // SetGid sets the "gid" field.
  657. func (cuo *ContactUpdateOne) SetGid(s string) *ContactUpdateOne {
  658. cuo.mutation.SetGid(s)
  659. return cuo
  660. }
  661. // SetNillableGid sets the "gid" field if the given value is not nil.
  662. func (cuo *ContactUpdateOne) SetNillableGid(s *string) *ContactUpdateOne {
  663. if s != nil {
  664. cuo.SetGid(*s)
  665. }
  666. return cuo
  667. }
  668. // SetGname sets the "gname" field.
  669. func (cuo *ContactUpdateOne) SetGname(s string) *ContactUpdateOne {
  670. cuo.mutation.SetGname(s)
  671. return cuo
  672. }
  673. // SetNillableGname sets the "gname" field if the given value is not nil.
  674. func (cuo *ContactUpdateOne) SetNillableGname(s *string) *ContactUpdateOne {
  675. if s != nil {
  676. cuo.SetGname(*s)
  677. }
  678. return cuo
  679. }
  680. // SetV3 sets the "v3" field.
  681. func (cuo *ContactUpdateOne) SetV3(s string) *ContactUpdateOne {
  682. cuo.mutation.SetV3(s)
  683. return cuo
  684. }
  685. // SetNillableV3 sets the "v3" field if the given value is not nil.
  686. func (cuo *ContactUpdateOne) SetNillableV3(s *string) *ContactUpdateOne {
  687. if s != nil {
  688. cuo.SetV3(*s)
  689. }
  690. return cuo
  691. }
  692. // Mutation returns the ContactMutation object of the builder.
  693. func (cuo *ContactUpdateOne) Mutation() *ContactMutation {
  694. return cuo.mutation
  695. }
  696. // Where appends a list predicates to the ContactUpdate builder.
  697. func (cuo *ContactUpdateOne) Where(ps ...predicate.Contact) *ContactUpdateOne {
  698. cuo.mutation.Where(ps...)
  699. return cuo
  700. }
  701. // Select allows selecting one or more fields (columns) of the returned entity.
  702. // The default is selecting all fields defined in the entity schema.
  703. func (cuo *ContactUpdateOne) Select(field string, fields ...string) *ContactUpdateOne {
  704. cuo.fields = append([]string{field}, fields...)
  705. return cuo
  706. }
  707. // Save executes the query and returns the updated Contact entity.
  708. func (cuo *ContactUpdateOne) Save(ctx context.Context) (*Contact, error) {
  709. if err := cuo.defaults(); err != nil {
  710. return nil, err
  711. }
  712. return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks)
  713. }
  714. // SaveX is like Save, but panics if an error occurs.
  715. func (cuo *ContactUpdateOne) SaveX(ctx context.Context) *Contact {
  716. node, err := cuo.Save(ctx)
  717. if err != nil {
  718. panic(err)
  719. }
  720. return node
  721. }
  722. // Exec executes the query on the entity.
  723. func (cuo *ContactUpdateOne) Exec(ctx context.Context) error {
  724. _, err := cuo.Save(ctx)
  725. return err
  726. }
  727. // ExecX is like Exec, but panics if an error occurs.
  728. func (cuo *ContactUpdateOne) ExecX(ctx context.Context) {
  729. if err := cuo.Exec(ctx); err != nil {
  730. panic(err)
  731. }
  732. }
  733. // defaults sets the default values of the builder before save.
  734. func (cuo *ContactUpdateOne) defaults() error {
  735. if _, ok := cuo.mutation.UpdatedAt(); !ok {
  736. if contact.UpdateDefaultUpdatedAt == nil {
  737. return fmt.Errorf("ent: uninitialized contact.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  738. }
  739. v := contact.UpdateDefaultUpdatedAt()
  740. cuo.mutation.SetUpdatedAt(v)
  741. }
  742. return nil
  743. }
  744. func (cuo *ContactUpdateOne) sqlSave(ctx context.Context) (_node *Contact, err error) {
  745. _spec := sqlgraph.NewUpdateSpec(contact.Table, contact.Columns, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64))
  746. id, ok := cuo.mutation.ID()
  747. if !ok {
  748. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Contact.id" for update`)}
  749. }
  750. _spec.Node.ID.Value = id
  751. if fields := cuo.fields; len(fields) > 0 {
  752. _spec.Node.Columns = make([]string, 0, len(fields))
  753. _spec.Node.Columns = append(_spec.Node.Columns, contact.FieldID)
  754. for _, f := range fields {
  755. if !contact.ValidColumn(f) {
  756. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  757. }
  758. if f != contact.FieldID {
  759. _spec.Node.Columns = append(_spec.Node.Columns, f)
  760. }
  761. }
  762. }
  763. if ps := cuo.mutation.predicates; len(ps) > 0 {
  764. _spec.Predicate = func(selector *sql.Selector) {
  765. for i := range ps {
  766. ps[i](selector)
  767. }
  768. }
  769. }
  770. if value, ok := cuo.mutation.UpdatedAt(); ok {
  771. _spec.SetField(contact.FieldUpdatedAt, field.TypeTime, value)
  772. }
  773. if value, ok := cuo.mutation.Status(); ok {
  774. _spec.SetField(contact.FieldStatus, field.TypeUint8, value)
  775. }
  776. if value, ok := cuo.mutation.AddedStatus(); ok {
  777. _spec.AddField(contact.FieldStatus, field.TypeUint8, value)
  778. }
  779. if cuo.mutation.StatusCleared() {
  780. _spec.ClearField(contact.FieldStatus, field.TypeUint8)
  781. }
  782. if value, ok := cuo.mutation.DeletedAt(); ok {
  783. _spec.SetField(contact.FieldDeletedAt, field.TypeTime, value)
  784. }
  785. if cuo.mutation.DeletedAtCleared() {
  786. _spec.ClearField(contact.FieldDeletedAt, field.TypeTime)
  787. }
  788. if value, ok := cuo.mutation.WxWxid(); ok {
  789. _spec.SetField(contact.FieldWxWxid, field.TypeString, value)
  790. }
  791. if cuo.mutation.WxWxidCleared() {
  792. _spec.ClearField(contact.FieldWxWxid, field.TypeString)
  793. }
  794. if value, ok := cuo.mutation.GetType(); ok {
  795. _spec.SetField(contact.FieldType, field.TypeInt, value)
  796. }
  797. if value, ok := cuo.mutation.AddedType(); ok {
  798. _spec.AddField(contact.FieldType, field.TypeInt, value)
  799. }
  800. if cuo.mutation.TypeCleared() {
  801. _spec.ClearField(contact.FieldType, field.TypeInt)
  802. }
  803. if value, ok := cuo.mutation.Wxid(); ok {
  804. _spec.SetField(contact.FieldWxid, field.TypeString, value)
  805. }
  806. if value, ok := cuo.mutation.Account(); ok {
  807. _spec.SetField(contact.FieldAccount, field.TypeString, value)
  808. }
  809. if value, ok := cuo.mutation.Nickname(); ok {
  810. _spec.SetField(contact.FieldNickname, field.TypeString, value)
  811. }
  812. if value, ok := cuo.mutation.Markname(); ok {
  813. _spec.SetField(contact.FieldMarkname, field.TypeString, value)
  814. }
  815. if value, ok := cuo.mutation.Headimg(); ok {
  816. _spec.SetField(contact.FieldHeadimg, field.TypeString, value)
  817. }
  818. if value, ok := cuo.mutation.Sex(); ok {
  819. _spec.SetField(contact.FieldSex, field.TypeInt, value)
  820. }
  821. if value, ok := cuo.mutation.AddedSex(); ok {
  822. _spec.AddField(contact.FieldSex, field.TypeInt, value)
  823. }
  824. if value, ok := cuo.mutation.Starrole(); ok {
  825. _spec.SetField(contact.FieldStarrole, field.TypeString, value)
  826. }
  827. if value, ok := cuo.mutation.Dontseeit(); ok {
  828. _spec.SetField(contact.FieldDontseeit, field.TypeInt, value)
  829. }
  830. if value, ok := cuo.mutation.AddedDontseeit(); ok {
  831. _spec.AddField(contact.FieldDontseeit, field.TypeInt, value)
  832. }
  833. if value, ok := cuo.mutation.Dontseeme(); ok {
  834. _spec.SetField(contact.FieldDontseeme, field.TypeInt, value)
  835. }
  836. if value, ok := cuo.mutation.AddedDontseeme(); ok {
  837. _spec.AddField(contact.FieldDontseeme, field.TypeInt, value)
  838. }
  839. if value, ok := cuo.mutation.Lag(); ok {
  840. _spec.SetField(contact.FieldLag, field.TypeString, value)
  841. }
  842. if value, ok := cuo.mutation.Gid(); ok {
  843. _spec.SetField(contact.FieldGid, field.TypeString, value)
  844. }
  845. if value, ok := cuo.mutation.Gname(); ok {
  846. _spec.SetField(contact.FieldGname, field.TypeString, value)
  847. }
  848. if value, ok := cuo.mutation.V3(); ok {
  849. _spec.SetField(contact.FieldV3, field.TypeString, value)
  850. }
  851. _node = &Contact{config: cuo.config}
  852. _spec.Assign = _node.assignValues
  853. _spec.ScanValues = _node.scanValues
  854. if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
  855. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  856. err = &NotFoundError{contact.Label}
  857. } else if sqlgraph.IsConstraintError(err) {
  858. err = &ConstraintError{msg: err.Error(), wrap: err}
  859. }
  860. return nil, err
  861. }
  862. cuo.mutation.done = true
  863. return _node, nil
  864. }