aliyunavatar_update.go 19 KB

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