wxcarduser_update.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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/predicate"
  9. "wechat-api/ent/wxcarduser"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // WxCardUserUpdate is the builder for updating WxCardUser entities.
  15. type WxCardUserUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *WxCardUserMutation
  19. }
  20. // Where appends a list predicates to the WxCardUserUpdate builder.
  21. func (wcuu *WxCardUserUpdate) Where(ps ...predicate.WxCardUser) *WxCardUserUpdate {
  22. wcuu.mutation.Where(ps...)
  23. return wcuu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (wcuu *WxCardUserUpdate) SetUpdatedAt(t time.Time) *WxCardUserUpdate {
  27. wcuu.mutation.SetUpdatedAt(t)
  28. return wcuu
  29. }
  30. // SetDeletedAt sets the "deleted_at" field.
  31. func (wcuu *WxCardUserUpdate) SetDeletedAt(t time.Time) *WxCardUserUpdate {
  32. wcuu.mutation.SetDeletedAt(t)
  33. return wcuu
  34. }
  35. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  36. func (wcuu *WxCardUserUpdate) SetNillableDeletedAt(t *time.Time) *WxCardUserUpdate {
  37. if t != nil {
  38. wcuu.SetDeletedAt(*t)
  39. }
  40. return wcuu
  41. }
  42. // ClearDeletedAt clears the value of the "deleted_at" field.
  43. func (wcuu *WxCardUserUpdate) ClearDeletedAt() *WxCardUserUpdate {
  44. wcuu.mutation.ClearDeletedAt()
  45. return wcuu
  46. }
  47. // SetWxid sets the "wxid" field.
  48. func (wcuu *WxCardUserUpdate) SetWxid(s string) *WxCardUserUpdate {
  49. wcuu.mutation.SetWxid(s)
  50. return wcuu
  51. }
  52. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  53. func (wcuu *WxCardUserUpdate) SetNillableWxid(s *string) *WxCardUserUpdate {
  54. if s != nil {
  55. wcuu.SetWxid(*s)
  56. }
  57. return wcuu
  58. }
  59. // SetAccount sets the "account" field.
  60. func (wcuu *WxCardUserUpdate) SetAccount(s string) *WxCardUserUpdate {
  61. wcuu.mutation.SetAccount(s)
  62. return wcuu
  63. }
  64. // SetNillableAccount sets the "account" field if the given value is not nil.
  65. func (wcuu *WxCardUserUpdate) SetNillableAccount(s *string) *WxCardUserUpdate {
  66. if s != nil {
  67. wcuu.SetAccount(*s)
  68. }
  69. return wcuu
  70. }
  71. // SetAvatar sets the "avatar" field.
  72. func (wcuu *WxCardUserUpdate) SetAvatar(s string) *WxCardUserUpdate {
  73. wcuu.mutation.SetAvatar(s)
  74. return wcuu
  75. }
  76. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  77. func (wcuu *WxCardUserUpdate) SetNillableAvatar(s *string) *WxCardUserUpdate {
  78. if s != nil {
  79. wcuu.SetAvatar(*s)
  80. }
  81. return wcuu
  82. }
  83. // SetNickname sets the "nickname" field.
  84. func (wcuu *WxCardUserUpdate) SetNickname(s string) *WxCardUserUpdate {
  85. wcuu.mutation.SetNickname(s)
  86. return wcuu
  87. }
  88. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  89. func (wcuu *WxCardUserUpdate) SetNillableNickname(s *string) *WxCardUserUpdate {
  90. if s != nil {
  91. wcuu.SetNickname(*s)
  92. }
  93. return wcuu
  94. }
  95. // SetRemark sets the "remark" field.
  96. func (wcuu *WxCardUserUpdate) SetRemark(s string) *WxCardUserUpdate {
  97. wcuu.mutation.SetRemark(s)
  98. return wcuu
  99. }
  100. // SetNillableRemark sets the "remark" field if the given value is not nil.
  101. func (wcuu *WxCardUserUpdate) SetNillableRemark(s *string) *WxCardUserUpdate {
  102. if s != nil {
  103. wcuu.SetRemark(*s)
  104. }
  105. return wcuu
  106. }
  107. // SetPhone sets the "phone" field.
  108. func (wcuu *WxCardUserUpdate) SetPhone(s string) *WxCardUserUpdate {
  109. wcuu.mutation.SetPhone(s)
  110. return wcuu
  111. }
  112. // SetNillablePhone sets the "phone" field if the given value is not nil.
  113. func (wcuu *WxCardUserUpdate) SetNillablePhone(s *string) *WxCardUserUpdate {
  114. if s != nil {
  115. wcuu.SetPhone(*s)
  116. }
  117. return wcuu
  118. }
  119. // SetOpenID sets the "open_id" field.
  120. func (wcuu *WxCardUserUpdate) SetOpenID(s string) *WxCardUserUpdate {
  121. wcuu.mutation.SetOpenID(s)
  122. return wcuu
  123. }
  124. // SetNillableOpenID sets the "open_id" field if the given value is not nil.
  125. func (wcuu *WxCardUserUpdate) SetNillableOpenID(s *string) *WxCardUserUpdate {
  126. if s != nil {
  127. wcuu.SetOpenID(*s)
  128. }
  129. return wcuu
  130. }
  131. // SetUnionID sets the "union_id" field.
  132. func (wcuu *WxCardUserUpdate) SetUnionID(s string) *WxCardUserUpdate {
  133. wcuu.mutation.SetUnionID(s)
  134. return wcuu
  135. }
  136. // SetNillableUnionID sets the "union_id" field if the given value is not nil.
  137. func (wcuu *WxCardUserUpdate) SetNillableUnionID(s *string) *WxCardUserUpdate {
  138. if s != nil {
  139. wcuu.SetUnionID(*s)
  140. }
  141. return wcuu
  142. }
  143. // SetSessionKey sets the "session_key" field.
  144. func (wcuu *WxCardUserUpdate) SetSessionKey(s string) *WxCardUserUpdate {
  145. wcuu.mutation.SetSessionKey(s)
  146. return wcuu
  147. }
  148. // SetNillableSessionKey sets the "session_key" field if the given value is not nil.
  149. func (wcuu *WxCardUserUpdate) SetNillableSessionKey(s *string) *WxCardUserUpdate {
  150. if s != nil {
  151. wcuu.SetSessionKey(*s)
  152. }
  153. return wcuu
  154. }
  155. // SetIsVip sets the "is_vip" field.
  156. func (wcuu *WxCardUserUpdate) SetIsVip(i int) *WxCardUserUpdate {
  157. wcuu.mutation.ResetIsVip()
  158. wcuu.mutation.SetIsVip(i)
  159. return wcuu
  160. }
  161. // SetNillableIsVip sets the "is_vip" field if the given value is not nil.
  162. func (wcuu *WxCardUserUpdate) SetNillableIsVip(i *int) *WxCardUserUpdate {
  163. if i != nil {
  164. wcuu.SetIsVip(*i)
  165. }
  166. return wcuu
  167. }
  168. // AddIsVip adds i to the "is_vip" field.
  169. func (wcuu *WxCardUserUpdate) AddIsVip(i int) *WxCardUserUpdate {
  170. wcuu.mutation.AddIsVip(i)
  171. return wcuu
  172. }
  173. // Mutation returns the WxCardUserMutation object of the builder.
  174. func (wcuu *WxCardUserUpdate) Mutation() *WxCardUserMutation {
  175. return wcuu.mutation
  176. }
  177. // Save executes the query and returns the number of nodes affected by the update operation.
  178. func (wcuu *WxCardUserUpdate) Save(ctx context.Context) (int, error) {
  179. if err := wcuu.defaults(); err != nil {
  180. return 0, err
  181. }
  182. return withHooks(ctx, wcuu.sqlSave, wcuu.mutation, wcuu.hooks)
  183. }
  184. // SaveX is like Save, but panics if an error occurs.
  185. func (wcuu *WxCardUserUpdate) SaveX(ctx context.Context) int {
  186. affected, err := wcuu.Save(ctx)
  187. if err != nil {
  188. panic(err)
  189. }
  190. return affected
  191. }
  192. // Exec executes the query.
  193. func (wcuu *WxCardUserUpdate) Exec(ctx context.Context) error {
  194. _, err := wcuu.Save(ctx)
  195. return err
  196. }
  197. // ExecX is like Exec, but panics if an error occurs.
  198. func (wcuu *WxCardUserUpdate) ExecX(ctx context.Context) {
  199. if err := wcuu.Exec(ctx); err != nil {
  200. panic(err)
  201. }
  202. }
  203. // defaults sets the default values of the builder before save.
  204. func (wcuu *WxCardUserUpdate) defaults() error {
  205. if _, ok := wcuu.mutation.UpdatedAt(); !ok {
  206. if wxcarduser.UpdateDefaultUpdatedAt == nil {
  207. return fmt.Errorf("ent: uninitialized wxcarduser.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  208. }
  209. v := wxcarduser.UpdateDefaultUpdatedAt()
  210. wcuu.mutation.SetUpdatedAt(v)
  211. }
  212. return nil
  213. }
  214. func (wcuu *WxCardUserUpdate) sqlSave(ctx context.Context) (n int, err error) {
  215. _spec := sqlgraph.NewUpdateSpec(wxcarduser.Table, wxcarduser.Columns, sqlgraph.NewFieldSpec(wxcarduser.FieldID, field.TypeUint64))
  216. if ps := wcuu.mutation.predicates; len(ps) > 0 {
  217. _spec.Predicate = func(selector *sql.Selector) {
  218. for i := range ps {
  219. ps[i](selector)
  220. }
  221. }
  222. }
  223. if value, ok := wcuu.mutation.UpdatedAt(); ok {
  224. _spec.SetField(wxcarduser.FieldUpdatedAt, field.TypeTime, value)
  225. }
  226. if value, ok := wcuu.mutation.DeletedAt(); ok {
  227. _spec.SetField(wxcarduser.FieldDeletedAt, field.TypeTime, value)
  228. }
  229. if wcuu.mutation.DeletedAtCleared() {
  230. _spec.ClearField(wxcarduser.FieldDeletedAt, field.TypeTime)
  231. }
  232. if value, ok := wcuu.mutation.Wxid(); ok {
  233. _spec.SetField(wxcarduser.FieldWxid, field.TypeString, value)
  234. }
  235. if value, ok := wcuu.mutation.Account(); ok {
  236. _spec.SetField(wxcarduser.FieldAccount, field.TypeString, value)
  237. }
  238. if value, ok := wcuu.mutation.Avatar(); ok {
  239. _spec.SetField(wxcarduser.FieldAvatar, field.TypeString, value)
  240. }
  241. if value, ok := wcuu.mutation.Nickname(); ok {
  242. _spec.SetField(wxcarduser.FieldNickname, field.TypeString, value)
  243. }
  244. if value, ok := wcuu.mutation.Remark(); ok {
  245. _spec.SetField(wxcarduser.FieldRemark, field.TypeString, value)
  246. }
  247. if value, ok := wcuu.mutation.Phone(); ok {
  248. _spec.SetField(wxcarduser.FieldPhone, field.TypeString, value)
  249. }
  250. if value, ok := wcuu.mutation.OpenID(); ok {
  251. _spec.SetField(wxcarduser.FieldOpenID, field.TypeString, value)
  252. }
  253. if value, ok := wcuu.mutation.UnionID(); ok {
  254. _spec.SetField(wxcarduser.FieldUnionID, field.TypeString, value)
  255. }
  256. if value, ok := wcuu.mutation.SessionKey(); ok {
  257. _spec.SetField(wxcarduser.FieldSessionKey, field.TypeString, value)
  258. }
  259. if value, ok := wcuu.mutation.IsVip(); ok {
  260. _spec.SetField(wxcarduser.FieldIsVip, field.TypeInt, value)
  261. }
  262. if value, ok := wcuu.mutation.AddedIsVip(); ok {
  263. _spec.AddField(wxcarduser.FieldIsVip, field.TypeInt, value)
  264. }
  265. if n, err = sqlgraph.UpdateNodes(ctx, wcuu.driver, _spec); err != nil {
  266. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  267. err = &NotFoundError{wxcarduser.Label}
  268. } else if sqlgraph.IsConstraintError(err) {
  269. err = &ConstraintError{msg: err.Error(), wrap: err}
  270. }
  271. return 0, err
  272. }
  273. wcuu.mutation.done = true
  274. return n, nil
  275. }
  276. // WxCardUserUpdateOne is the builder for updating a single WxCardUser entity.
  277. type WxCardUserUpdateOne struct {
  278. config
  279. fields []string
  280. hooks []Hook
  281. mutation *WxCardUserMutation
  282. }
  283. // SetUpdatedAt sets the "updated_at" field.
  284. func (wcuuo *WxCardUserUpdateOne) SetUpdatedAt(t time.Time) *WxCardUserUpdateOne {
  285. wcuuo.mutation.SetUpdatedAt(t)
  286. return wcuuo
  287. }
  288. // SetDeletedAt sets the "deleted_at" field.
  289. func (wcuuo *WxCardUserUpdateOne) SetDeletedAt(t time.Time) *WxCardUserUpdateOne {
  290. wcuuo.mutation.SetDeletedAt(t)
  291. return wcuuo
  292. }
  293. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  294. func (wcuuo *WxCardUserUpdateOne) SetNillableDeletedAt(t *time.Time) *WxCardUserUpdateOne {
  295. if t != nil {
  296. wcuuo.SetDeletedAt(*t)
  297. }
  298. return wcuuo
  299. }
  300. // ClearDeletedAt clears the value of the "deleted_at" field.
  301. func (wcuuo *WxCardUserUpdateOne) ClearDeletedAt() *WxCardUserUpdateOne {
  302. wcuuo.mutation.ClearDeletedAt()
  303. return wcuuo
  304. }
  305. // SetWxid sets the "wxid" field.
  306. func (wcuuo *WxCardUserUpdateOne) SetWxid(s string) *WxCardUserUpdateOne {
  307. wcuuo.mutation.SetWxid(s)
  308. return wcuuo
  309. }
  310. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  311. func (wcuuo *WxCardUserUpdateOne) SetNillableWxid(s *string) *WxCardUserUpdateOne {
  312. if s != nil {
  313. wcuuo.SetWxid(*s)
  314. }
  315. return wcuuo
  316. }
  317. // SetAccount sets the "account" field.
  318. func (wcuuo *WxCardUserUpdateOne) SetAccount(s string) *WxCardUserUpdateOne {
  319. wcuuo.mutation.SetAccount(s)
  320. return wcuuo
  321. }
  322. // SetNillableAccount sets the "account" field if the given value is not nil.
  323. func (wcuuo *WxCardUserUpdateOne) SetNillableAccount(s *string) *WxCardUserUpdateOne {
  324. if s != nil {
  325. wcuuo.SetAccount(*s)
  326. }
  327. return wcuuo
  328. }
  329. // SetAvatar sets the "avatar" field.
  330. func (wcuuo *WxCardUserUpdateOne) SetAvatar(s string) *WxCardUserUpdateOne {
  331. wcuuo.mutation.SetAvatar(s)
  332. return wcuuo
  333. }
  334. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  335. func (wcuuo *WxCardUserUpdateOne) SetNillableAvatar(s *string) *WxCardUserUpdateOne {
  336. if s != nil {
  337. wcuuo.SetAvatar(*s)
  338. }
  339. return wcuuo
  340. }
  341. // SetNickname sets the "nickname" field.
  342. func (wcuuo *WxCardUserUpdateOne) SetNickname(s string) *WxCardUserUpdateOne {
  343. wcuuo.mutation.SetNickname(s)
  344. return wcuuo
  345. }
  346. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  347. func (wcuuo *WxCardUserUpdateOne) SetNillableNickname(s *string) *WxCardUserUpdateOne {
  348. if s != nil {
  349. wcuuo.SetNickname(*s)
  350. }
  351. return wcuuo
  352. }
  353. // SetRemark sets the "remark" field.
  354. func (wcuuo *WxCardUserUpdateOne) SetRemark(s string) *WxCardUserUpdateOne {
  355. wcuuo.mutation.SetRemark(s)
  356. return wcuuo
  357. }
  358. // SetNillableRemark sets the "remark" field if the given value is not nil.
  359. func (wcuuo *WxCardUserUpdateOne) SetNillableRemark(s *string) *WxCardUserUpdateOne {
  360. if s != nil {
  361. wcuuo.SetRemark(*s)
  362. }
  363. return wcuuo
  364. }
  365. // SetPhone sets the "phone" field.
  366. func (wcuuo *WxCardUserUpdateOne) SetPhone(s string) *WxCardUserUpdateOne {
  367. wcuuo.mutation.SetPhone(s)
  368. return wcuuo
  369. }
  370. // SetNillablePhone sets the "phone" field if the given value is not nil.
  371. func (wcuuo *WxCardUserUpdateOne) SetNillablePhone(s *string) *WxCardUserUpdateOne {
  372. if s != nil {
  373. wcuuo.SetPhone(*s)
  374. }
  375. return wcuuo
  376. }
  377. // SetOpenID sets the "open_id" field.
  378. func (wcuuo *WxCardUserUpdateOne) SetOpenID(s string) *WxCardUserUpdateOne {
  379. wcuuo.mutation.SetOpenID(s)
  380. return wcuuo
  381. }
  382. // SetNillableOpenID sets the "open_id" field if the given value is not nil.
  383. func (wcuuo *WxCardUserUpdateOne) SetNillableOpenID(s *string) *WxCardUserUpdateOne {
  384. if s != nil {
  385. wcuuo.SetOpenID(*s)
  386. }
  387. return wcuuo
  388. }
  389. // SetUnionID sets the "union_id" field.
  390. func (wcuuo *WxCardUserUpdateOne) SetUnionID(s string) *WxCardUserUpdateOne {
  391. wcuuo.mutation.SetUnionID(s)
  392. return wcuuo
  393. }
  394. // SetNillableUnionID sets the "union_id" field if the given value is not nil.
  395. func (wcuuo *WxCardUserUpdateOne) SetNillableUnionID(s *string) *WxCardUserUpdateOne {
  396. if s != nil {
  397. wcuuo.SetUnionID(*s)
  398. }
  399. return wcuuo
  400. }
  401. // SetSessionKey sets the "session_key" field.
  402. func (wcuuo *WxCardUserUpdateOne) SetSessionKey(s string) *WxCardUserUpdateOne {
  403. wcuuo.mutation.SetSessionKey(s)
  404. return wcuuo
  405. }
  406. // SetNillableSessionKey sets the "session_key" field if the given value is not nil.
  407. func (wcuuo *WxCardUserUpdateOne) SetNillableSessionKey(s *string) *WxCardUserUpdateOne {
  408. if s != nil {
  409. wcuuo.SetSessionKey(*s)
  410. }
  411. return wcuuo
  412. }
  413. // SetIsVip sets the "is_vip" field.
  414. func (wcuuo *WxCardUserUpdateOne) SetIsVip(i int) *WxCardUserUpdateOne {
  415. wcuuo.mutation.ResetIsVip()
  416. wcuuo.mutation.SetIsVip(i)
  417. return wcuuo
  418. }
  419. // SetNillableIsVip sets the "is_vip" field if the given value is not nil.
  420. func (wcuuo *WxCardUserUpdateOne) SetNillableIsVip(i *int) *WxCardUserUpdateOne {
  421. if i != nil {
  422. wcuuo.SetIsVip(*i)
  423. }
  424. return wcuuo
  425. }
  426. // AddIsVip adds i to the "is_vip" field.
  427. func (wcuuo *WxCardUserUpdateOne) AddIsVip(i int) *WxCardUserUpdateOne {
  428. wcuuo.mutation.AddIsVip(i)
  429. return wcuuo
  430. }
  431. // Mutation returns the WxCardUserMutation object of the builder.
  432. func (wcuuo *WxCardUserUpdateOne) Mutation() *WxCardUserMutation {
  433. return wcuuo.mutation
  434. }
  435. // Where appends a list predicates to the WxCardUserUpdate builder.
  436. func (wcuuo *WxCardUserUpdateOne) Where(ps ...predicate.WxCardUser) *WxCardUserUpdateOne {
  437. wcuuo.mutation.Where(ps...)
  438. return wcuuo
  439. }
  440. // Select allows selecting one or more fields (columns) of the returned entity.
  441. // The default is selecting all fields defined in the entity schema.
  442. func (wcuuo *WxCardUserUpdateOne) Select(field string, fields ...string) *WxCardUserUpdateOne {
  443. wcuuo.fields = append([]string{field}, fields...)
  444. return wcuuo
  445. }
  446. // Save executes the query and returns the updated WxCardUser entity.
  447. func (wcuuo *WxCardUserUpdateOne) Save(ctx context.Context) (*WxCardUser, error) {
  448. if err := wcuuo.defaults(); err != nil {
  449. return nil, err
  450. }
  451. return withHooks(ctx, wcuuo.sqlSave, wcuuo.mutation, wcuuo.hooks)
  452. }
  453. // SaveX is like Save, but panics if an error occurs.
  454. func (wcuuo *WxCardUserUpdateOne) SaveX(ctx context.Context) *WxCardUser {
  455. node, err := wcuuo.Save(ctx)
  456. if err != nil {
  457. panic(err)
  458. }
  459. return node
  460. }
  461. // Exec executes the query on the entity.
  462. func (wcuuo *WxCardUserUpdateOne) Exec(ctx context.Context) error {
  463. _, err := wcuuo.Save(ctx)
  464. return err
  465. }
  466. // ExecX is like Exec, but panics if an error occurs.
  467. func (wcuuo *WxCardUserUpdateOne) ExecX(ctx context.Context) {
  468. if err := wcuuo.Exec(ctx); err != nil {
  469. panic(err)
  470. }
  471. }
  472. // defaults sets the default values of the builder before save.
  473. func (wcuuo *WxCardUserUpdateOne) defaults() error {
  474. if _, ok := wcuuo.mutation.UpdatedAt(); !ok {
  475. if wxcarduser.UpdateDefaultUpdatedAt == nil {
  476. return fmt.Errorf("ent: uninitialized wxcarduser.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  477. }
  478. v := wxcarduser.UpdateDefaultUpdatedAt()
  479. wcuuo.mutation.SetUpdatedAt(v)
  480. }
  481. return nil
  482. }
  483. func (wcuuo *WxCardUserUpdateOne) sqlSave(ctx context.Context) (_node *WxCardUser, err error) {
  484. _spec := sqlgraph.NewUpdateSpec(wxcarduser.Table, wxcarduser.Columns, sqlgraph.NewFieldSpec(wxcarduser.FieldID, field.TypeUint64))
  485. id, ok := wcuuo.mutation.ID()
  486. if !ok {
  487. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WxCardUser.id" for update`)}
  488. }
  489. _spec.Node.ID.Value = id
  490. if fields := wcuuo.fields; len(fields) > 0 {
  491. _spec.Node.Columns = make([]string, 0, len(fields))
  492. _spec.Node.Columns = append(_spec.Node.Columns, wxcarduser.FieldID)
  493. for _, f := range fields {
  494. if !wxcarduser.ValidColumn(f) {
  495. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  496. }
  497. if f != wxcarduser.FieldID {
  498. _spec.Node.Columns = append(_spec.Node.Columns, f)
  499. }
  500. }
  501. }
  502. if ps := wcuuo.mutation.predicates; len(ps) > 0 {
  503. _spec.Predicate = func(selector *sql.Selector) {
  504. for i := range ps {
  505. ps[i](selector)
  506. }
  507. }
  508. }
  509. if value, ok := wcuuo.mutation.UpdatedAt(); ok {
  510. _spec.SetField(wxcarduser.FieldUpdatedAt, field.TypeTime, value)
  511. }
  512. if value, ok := wcuuo.mutation.DeletedAt(); ok {
  513. _spec.SetField(wxcarduser.FieldDeletedAt, field.TypeTime, value)
  514. }
  515. if wcuuo.mutation.DeletedAtCleared() {
  516. _spec.ClearField(wxcarduser.FieldDeletedAt, field.TypeTime)
  517. }
  518. if value, ok := wcuuo.mutation.Wxid(); ok {
  519. _spec.SetField(wxcarduser.FieldWxid, field.TypeString, value)
  520. }
  521. if value, ok := wcuuo.mutation.Account(); ok {
  522. _spec.SetField(wxcarduser.FieldAccount, field.TypeString, value)
  523. }
  524. if value, ok := wcuuo.mutation.Avatar(); ok {
  525. _spec.SetField(wxcarduser.FieldAvatar, field.TypeString, value)
  526. }
  527. if value, ok := wcuuo.mutation.Nickname(); ok {
  528. _spec.SetField(wxcarduser.FieldNickname, field.TypeString, value)
  529. }
  530. if value, ok := wcuuo.mutation.Remark(); ok {
  531. _spec.SetField(wxcarduser.FieldRemark, field.TypeString, value)
  532. }
  533. if value, ok := wcuuo.mutation.Phone(); ok {
  534. _spec.SetField(wxcarduser.FieldPhone, field.TypeString, value)
  535. }
  536. if value, ok := wcuuo.mutation.OpenID(); ok {
  537. _spec.SetField(wxcarduser.FieldOpenID, field.TypeString, value)
  538. }
  539. if value, ok := wcuuo.mutation.UnionID(); ok {
  540. _spec.SetField(wxcarduser.FieldUnionID, field.TypeString, value)
  541. }
  542. if value, ok := wcuuo.mutation.SessionKey(); ok {
  543. _spec.SetField(wxcarduser.FieldSessionKey, field.TypeString, value)
  544. }
  545. if value, ok := wcuuo.mutation.IsVip(); ok {
  546. _spec.SetField(wxcarduser.FieldIsVip, field.TypeInt, value)
  547. }
  548. if value, ok := wcuuo.mutation.AddedIsVip(); ok {
  549. _spec.AddField(wxcarduser.FieldIsVip, field.TypeInt, value)
  550. }
  551. _node = &WxCardUser{config: wcuuo.config}
  552. _spec.Assign = _node.assignValues
  553. _spec.ScanValues = _node.scanValues
  554. if err = sqlgraph.UpdateNode(ctx, wcuuo.driver, _spec); err != nil {
  555. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  556. err = &NotFoundError{wxcarduser.Label}
  557. } else if sqlgraph.IsConstraintError(err) {
  558. err = &ConstraintError{msg: err.Error(), wrap: err}
  559. }
  560. return nil, err
  561. }
  562. wcuuo.mutation.done = true
  563. return _node, nil
  564. }