idempotencyrecord_update.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
  12. "github.com/Wei-Shaw/sub2api/ent/predicate"
  13. )
  14. // IdempotencyRecordUpdate is the builder for updating IdempotencyRecord entities.
  15. type IdempotencyRecordUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *IdempotencyRecordMutation
  19. }
  20. // Where appends a list predicates to the IdempotencyRecordUpdate builder.
  21. func (_u *IdempotencyRecordUpdate) Where(ps ...predicate.IdempotencyRecord) *IdempotencyRecordUpdate {
  22. _u.mutation.Where(ps...)
  23. return _u
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (_u *IdempotencyRecordUpdate) SetUpdatedAt(v time.Time) *IdempotencyRecordUpdate {
  27. _u.mutation.SetUpdatedAt(v)
  28. return _u
  29. }
  30. // SetScope sets the "scope" field.
  31. func (_u *IdempotencyRecordUpdate) SetScope(v string) *IdempotencyRecordUpdate {
  32. _u.mutation.SetScope(v)
  33. return _u
  34. }
  35. // SetNillableScope sets the "scope" field if the given value is not nil.
  36. func (_u *IdempotencyRecordUpdate) SetNillableScope(v *string) *IdempotencyRecordUpdate {
  37. if v != nil {
  38. _u.SetScope(*v)
  39. }
  40. return _u
  41. }
  42. // SetIdempotencyKeyHash sets the "idempotency_key_hash" field.
  43. func (_u *IdempotencyRecordUpdate) SetIdempotencyKeyHash(v string) *IdempotencyRecordUpdate {
  44. _u.mutation.SetIdempotencyKeyHash(v)
  45. return _u
  46. }
  47. // SetNillableIdempotencyKeyHash sets the "idempotency_key_hash" field if the given value is not nil.
  48. func (_u *IdempotencyRecordUpdate) SetNillableIdempotencyKeyHash(v *string) *IdempotencyRecordUpdate {
  49. if v != nil {
  50. _u.SetIdempotencyKeyHash(*v)
  51. }
  52. return _u
  53. }
  54. // SetRequestFingerprint sets the "request_fingerprint" field.
  55. func (_u *IdempotencyRecordUpdate) SetRequestFingerprint(v string) *IdempotencyRecordUpdate {
  56. _u.mutation.SetRequestFingerprint(v)
  57. return _u
  58. }
  59. // SetNillableRequestFingerprint sets the "request_fingerprint" field if the given value is not nil.
  60. func (_u *IdempotencyRecordUpdate) SetNillableRequestFingerprint(v *string) *IdempotencyRecordUpdate {
  61. if v != nil {
  62. _u.SetRequestFingerprint(*v)
  63. }
  64. return _u
  65. }
  66. // SetStatus sets the "status" field.
  67. func (_u *IdempotencyRecordUpdate) SetStatus(v string) *IdempotencyRecordUpdate {
  68. _u.mutation.SetStatus(v)
  69. return _u
  70. }
  71. // SetNillableStatus sets the "status" field if the given value is not nil.
  72. func (_u *IdempotencyRecordUpdate) SetNillableStatus(v *string) *IdempotencyRecordUpdate {
  73. if v != nil {
  74. _u.SetStatus(*v)
  75. }
  76. return _u
  77. }
  78. // SetResponseStatus sets the "response_status" field.
  79. func (_u *IdempotencyRecordUpdate) SetResponseStatus(v int) *IdempotencyRecordUpdate {
  80. _u.mutation.ResetResponseStatus()
  81. _u.mutation.SetResponseStatus(v)
  82. return _u
  83. }
  84. // SetNillableResponseStatus sets the "response_status" field if the given value is not nil.
  85. func (_u *IdempotencyRecordUpdate) SetNillableResponseStatus(v *int) *IdempotencyRecordUpdate {
  86. if v != nil {
  87. _u.SetResponseStatus(*v)
  88. }
  89. return _u
  90. }
  91. // AddResponseStatus adds value to the "response_status" field.
  92. func (_u *IdempotencyRecordUpdate) AddResponseStatus(v int) *IdempotencyRecordUpdate {
  93. _u.mutation.AddResponseStatus(v)
  94. return _u
  95. }
  96. // ClearResponseStatus clears the value of the "response_status" field.
  97. func (_u *IdempotencyRecordUpdate) ClearResponseStatus() *IdempotencyRecordUpdate {
  98. _u.mutation.ClearResponseStatus()
  99. return _u
  100. }
  101. // SetResponseBody sets the "response_body" field.
  102. func (_u *IdempotencyRecordUpdate) SetResponseBody(v string) *IdempotencyRecordUpdate {
  103. _u.mutation.SetResponseBody(v)
  104. return _u
  105. }
  106. // SetNillableResponseBody sets the "response_body" field if the given value is not nil.
  107. func (_u *IdempotencyRecordUpdate) SetNillableResponseBody(v *string) *IdempotencyRecordUpdate {
  108. if v != nil {
  109. _u.SetResponseBody(*v)
  110. }
  111. return _u
  112. }
  113. // ClearResponseBody clears the value of the "response_body" field.
  114. func (_u *IdempotencyRecordUpdate) ClearResponseBody() *IdempotencyRecordUpdate {
  115. _u.mutation.ClearResponseBody()
  116. return _u
  117. }
  118. // SetErrorReason sets the "error_reason" field.
  119. func (_u *IdempotencyRecordUpdate) SetErrorReason(v string) *IdempotencyRecordUpdate {
  120. _u.mutation.SetErrorReason(v)
  121. return _u
  122. }
  123. // SetNillableErrorReason sets the "error_reason" field if the given value is not nil.
  124. func (_u *IdempotencyRecordUpdate) SetNillableErrorReason(v *string) *IdempotencyRecordUpdate {
  125. if v != nil {
  126. _u.SetErrorReason(*v)
  127. }
  128. return _u
  129. }
  130. // ClearErrorReason clears the value of the "error_reason" field.
  131. func (_u *IdempotencyRecordUpdate) ClearErrorReason() *IdempotencyRecordUpdate {
  132. _u.mutation.ClearErrorReason()
  133. return _u
  134. }
  135. // SetLockedUntil sets the "locked_until" field.
  136. func (_u *IdempotencyRecordUpdate) SetLockedUntil(v time.Time) *IdempotencyRecordUpdate {
  137. _u.mutation.SetLockedUntil(v)
  138. return _u
  139. }
  140. // SetNillableLockedUntil sets the "locked_until" field if the given value is not nil.
  141. func (_u *IdempotencyRecordUpdate) SetNillableLockedUntil(v *time.Time) *IdempotencyRecordUpdate {
  142. if v != nil {
  143. _u.SetLockedUntil(*v)
  144. }
  145. return _u
  146. }
  147. // ClearLockedUntil clears the value of the "locked_until" field.
  148. func (_u *IdempotencyRecordUpdate) ClearLockedUntil() *IdempotencyRecordUpdate {
  149. _u.mutation.ClearLockedUntil()
  150. return _u
  151. }
  152. // SetExpiresAt sets the "expires_at" field.
  153. func (_u *IdempotencyRecordUpdate) SetExpiresAt(v time.Time) *IdempotencyRecordUpdate {
  154. _u.mutation.SetExpiresAt(v)
  155. return _u
  156. }
  157. // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
  158. func (_u *IdempotencyRecordUpdate) SetNillableExpiresAt(v *time.Time) *IdempotencyRecordUpdate {
  159. if v != nil {
  160. _u.SetExpiresAt(*v)
  161. }
  162. return _u
  163. }
  164. // Mutation returns the IdempotencyRecordMutation object of the builder.
  165. func (_u *IdempotencyRecordUpdate) Mutation() *IdempotencyRecordMutation {
  166. return _u.mutation
  167. }
  168. // Save executes the query and returns the number of nodes affected by the update operation.
  169. func (_u *IdempotencyRecordUpdate) Save(ctx context.Context) (int, error) {
  170. _u.defaults()
  171. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  172. }
  173. // SaveX is like Save, but panics if an error occurs.
  174. func (_u *IdempotencyRecordUpdate) SaveX(ctx context.Context) int {
  175. affected, err := _u.Save(ctx)
  176. if err != nil {
  177. panic(err)
  178. }
  179. return affected
  180. }
  181. // Exec executes the query.
  182. func (_u *IdempotencyRecordUpdate) Exec(ctx context.Context) error {
  183. _, err := _u.Save(ctx)
  184. return err
  185. }
  186. // ExecX is like Exec, but panics if an error occurs.
  187. func (_u *IdempotencyRecordUpdate) ExecX(ctx context.Context) {
  188. if err := _u.Exec(ctx); err != nil {
  189. panic(err)
  190. }
  191. }
  192. // defaults sets the default values of the builder before save.
  193. func (_u *IdempotencyRecordUpdate) defaults() {
  194. if _, ok := _u.mutation.UpdatedAt(); !ok {
  195. v := idempotencyrecord.UpdateDefaultUpdatedAt()
  196. _u.mutation.SetUpdatedAt(v)
  197. }
  198. }
  199. // check runs all checks and user-defined validators on the builder.
  200. func (_u *IdempotencyRecordUpdate) check() error {
  201. if v, ok := _u.mutation.Scope(); ok {
  202. if err := idempotencyrecord.ScopeValidator(v); err != nil {
  203. return &ValidationError{Name: "scope", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.scope": %w`, err)}
  204. }
  205. }
  206. if v, ok := _u.mutation.IdempotencyKeyHash(); ok {
  207. if err := idempotencyrecord.IdempotencyKeyHashValidator(v); err != nil {
  208. return &ValidationError{Name: "idempotency_key_hash", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.idempotency_key_hash": %w`, err)}
  209. }
  210. }
  211. if v, ok := _u.mutation.RequestFingerprint(); ok {
  212. if err := idempotencyrecord.RequestFingerprintValidator(v); err != nil {
  213. return &ValidationError{Name: "request_fingerprint", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.request_fingerprint": %w`, err)}
  214. }
  215. }
  216. if v, ok := _u.mutation.Status(); ok {
  217. if err := idempotencyrecord.StatusValidator(v); err != nil {
  218. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.status": %w`, err)}
  219. }
  220. }
  221. if v, ok := _u.mutation.ErrorReason(); ok {
  222. if err := idempotencyrecord.ErrorReasonValidator(v); err != nil {
  223. return &ValidationError{Name: "error_reason", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.error_reason": %w`, err)}
  224. }
  225. }
  226. return nil
  227. }
  228. func (_u *IdempotencyRecordUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  229. if err := _u.check(); err != nil {
  230. return _node, err
  231. }
  232. _spec := sqlgraph.NewUpdateSpec(idempotencyrecord.Table, idempotencyrecord.Columns, sqlgraph.NewFieldSpec(idempotencyrecord.FieldID, field.TypeInt64))
  233. if ps := _u.mutation.predicates; len(ps) > 0 {
  234. _spec.Predicate = func(selector *sql.Selector) {
  235. for i := range ps {
  236. ps[i](selector)
  237. }
  238. }
  239. }
  240. if value, ok := _u.mutation.UpdatedAt(); ok {
  241. _spec.SetField(idempotencyrecord.FieldUpdatedAt, field.TypeTime, value)
  242. }
  243. if value, ok := _u.mutation.Scope(); ok {
  244. _spec.SetField(idempotencyrecord.FieldScope, field.TypeString, value)
  245. }
  246. if value, ok := _u.mutation.IdempotencyKeyHash(); ok {
  247. _spec.SetField(idempotencyrecord.FieldIdempotencyKeyHash, field.TypeString, value)
  248. }
  249. if value, ok := _u.mutation.RequestFingerprint(); ok {
  250. _spec.SetField(idempotencyrecord.FieldRequestFingerprint, field.TypeString, value)
  251. }
  252. if value, ok := _u.mutation.Status(); ok {
  253. _spec.SetField(idempotencyrecord.FieldStatus, field.TypeString, value)
  254. }
  255. if value, ok := _u.mutation.ResponseStatus(); ok {
  256. _spec.SetField(idempotencyrecord.FieldResponseStatus, field.TypeInt, value)
  257. }
  258. if value, ok := _u.mutation.AddedResponseStatus(); ok {
  259. _spec.AddField(idempotencyrecord.FieldResponseStatus, field.TypeInt, value)
  260. }
  261. if _u.mutation.ResponseStatusCleared() {
  262. _spec.ClearField(idempotencyrecord.FieldResponseStatus, field.TypeInt)
  263. }
  264. if value, ok := _u.mutation.ResponseBody(); ok {
  265. _spec.SetField(idempotencyrecord.FieldResponseBody, field.TypeString, value)
  266. }
  267. if _u.mutation.ResponseBodyCleared() {
  268. _spec.ClearField(idempotencyrecord.FieldResponseBody, field.TypeString)
  269. }
  270. if value, ok := _u.mutation.ErrorReason(); ok {
  271. _spec.SetField(idempotencyrecord.FieldErrorReason, field.TypeString, value)
  272. }
  273. if _u.mutation.ErrorReasonCleared() {
  274. _spec.ClearField(idempotencyrecord.FieldErrorReason, field.TypeString)
  275. }
  276. if value, ok := _u.mutation.LockedUntil(); ok {
  277. _spec.SetField(idempotencyrecord.FieldLockedUntil, field.TypeTime, value)
  278. }
  279. if _u.mutation.LockedUntilCleared() {
  280. _spec.ClearField(idempotencyrecord.FieldLockedUntil, field.TypeTime)
  281. }
  282. if value, ok := _u.mutation.ExpiresAt(); ok {
  283. _spec.SetField(idempotencyrecord.FieldExpiresAt, field.TypeTime, value)
  284. }
  285. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  286. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  287. err = &NotFoundError{idempotencyrecord.Label}
  288. } else if sqlgraph.IsConstraintError(err) {
  289. err = &ConstraintError{msg: err.Error(), wrap: err}
  290. }
  291. return 0, err
  292. }
  293. _u.mutation.done = true
  294. return _node, nil
  295. }
  296. // IdempotencyRecordUpdateOne is the builder for updating a single IdempotencyRecord entity.
  297. type IdempotencyRecordUpdateOne struct {
  298. config
  299. fields []string
  300. hooks []Hook
  301. mutation *IdempotencyRecordMutation
  302. }
  303. // SetUpdatedAt sets the "updated_at" field.
  304. func (_u *IdempotencyRecordUpdateOne) SetUpdatedAt(v time.Time) *IdempotencyRecordUpdateOne {
  305. _u.mutation.SetUpdatedAt(v)
  306. return _u
  307. }
  308. // SetScope sets the "scope" field.
  309. func (_u *IdempotencyRecordUpdateOne) SetScope(v string) *IdempotencyRecordUpdateOne {
  310. _u.mutation.SetScope(v)
  311. return _u
  312. }
  313. // SetNillableScope sets the "scope" field if the given value is not nil.
  314. func (_u *IdempotencyRecordUpdateOne) SetNillableScope(v *string) *IdempotencyRecordUpdateOne {
  315. if v != nil {
  316. _u.SetScope(*v)
  317. }
  318. return _u
  319. }
  320. // SetIdempotencyKeyHash sets the "idempotency_key_hash" field.
  321. func (_u *IdempotencyRecordUpdateOne) SetIdempotencyKeyHash(v string) *IdempotencyRecordUpdateOne {
  322. _u.mutation.SetIdempotencyKeyHash(v)
  323. return _u
  324. }
  325. // SetNillableIdempotencyKeyHash sets the "idempotency_key_hash" field if the given value is not nil.
  326. func (_u *IdempotencyRecordUpdateOne) SetNillableIdempotencyKeyHash(v *string) *IdempotencyRecordUpdateOne {
  327. if v != nil {
  328. _u.SetIdempotencyKeyHash(*v)
  329. }
  330. return _u
  331. }
  332. // SetRequestFingerprint sets the "request_fingerprint" field.
  333. func (_u *IdempotencyRecordUpdateOne) SetRequestFingerprint(v string) *IdempotencyRecordUpdateOne {
  334. _u.mutation.SetRequestFingerprint(v)
  335. return _u
  336. }
  337. // SetNillableRequestFingerprint sets the "request_fingerprint" field if the given value is not nil.
  338. func (_u *IdempotencyRecordUpdateOne) SetNillableRequestFingerprint(v *string) *IdempotencyRecordUpdateOne {
  339. if v != nil {
  340. _u.SetRequestFingerprint(*v)
  341. }
  342. return _u
  343. }
  344. // SetStatus sets the "status" field.
  345. func (_u *IdempotencyRecordUpdateOne) SetStatus(v string) *IdempotencyRecordUpdateOne {
  346. _u.mutation.SetStatus(v)
  347. return _u
  348. }
  349. // SetNillableStatus sets the "status" field if the given value is not nil.
  350. func (_u *IdempotencyRecordUpdateOne) SetNillableStatus(v *string) *IdempotencyRecordUpdateOne {
  351. if v != nil {
  352. _u.SetStatus(*v)
  353. }
  354. return _u
  355. }
  356. // SetResponseStatus sets the "response_status" field.
  357. func (_u *IdempotencyRecordUpdateOne) SetResponseStatus(v int) *IdempotencyRecordUpdateOne {
  358. _u.mutation.ResetResponseStatus()
  359. _u.mutation.SetResponseStatus(v)
  360. return _u
  361. }
  362. // SetNillableResponseStatus sets the "response_status" field if the given value is not nil.
  363. func (_u *IdempotencyRecordUpdateOne) SetNillableResponseStatus(v *int) *IdempotencyRecordUpdateOne {
  364. if v != nil {
  365. _u.SetResponseStatus(*v)
  366. }
  367. return _u
  368. }
  369. // AddResponseStatus adds value to the "response_status" field.
  370. func (_u *IdempotencyRecordUpdateOne) AddResponseStatus(v int) *IdempotencyRecordUpdateOne {
  371. _u.mutation.AddResponseStatus(v)
  372. return _u
  373. }
  374. // ClearResponseStatus clears the value of the "response_status" field.
  375. func (_u *IdempotencyRecordUpdateOne) ClearResponseStatus() *IdempotencyRecordUpdateOne {
  376. _u.mutation.ClearResponseStatus()
  377. return _u
  378. }
  379. // SetResponseBody sets the "response_body" field.
  380. func (_u *IdempotencyRecordUpdateOne) SetResponseBody(v string) *IdempotencyRecordUpdateOne {
  381. _u.mutation.SetResponseBody(v)
  382. return _u
  383. }
  384. // SetNillableResponseBody sets the "response_body" field if the given value is not nil.
  385. func (_u *IdempotencyRecordUpdateOne) SetNillableResponseBody(v *string) *IdempotencyRecordUpdateOne {
  386. if v != nil {
  387. _u.SetResponseBody(*v)
  388. }
  389. return _u
  390. }
  391. // ClearResponseBody clears the value of the "response_body" field.
  392. func (_u *IdempotencyRecordUpdateOne) ClearResponseBody() *IdempotencyRecordUpdateOne {
  393. _u.mutation.ClearResponseBody()
  394. return _u
  395. }
  396. // SetErrorReason sets the "error_reason" field.
  397. func (_u *IdempotencyRecordUpdateOne) SetErrorReason(v string) *IdempotencyRecordUpdateOne {
  398. _u.mutation.SetErrorReason(v)
  399. return _u
  400. }
  401. // SetNillableErrorReason sets the "error_reason" field if the given value is not nil.
  402. func (_u *IdempotencyRecordUpdateOne) SetNillableErrorReason(v *string) *IdempotencyRecordUpdateOne {
  403. if v != nil {
  404. _u.SetErrorReason(*v)
  405. }
  406. return _u
  407. }
  408. // ClearErrorReason clears the value of the "error_reason" field.
  409. func (_u *IdempotencyRecordUpdateOne) ClearErrorReason() *IdempotencyRecordUpdateOne {
  410. _u.mutation.ClearErrorReason()
  411. return _u
  412. }
  413. // SetLockedUntil sets the "locked_until" field.
  414. func (_u *IdempotencyRecordUpdateOne) SetLockedUntil(v time.Time) *IdempotencyRecordUpdateOne {
  415. _u.mutation.SetLockedUntil(v)
  416. return _u
  417. }
  418. // SetNillableLockedUntil sets the "locked_until" field if the given value is not nil.
  419. func (_u *IdempotencyRecordUpdateOne) SetNillableLockedUntil(v *time.Time) *IdempotencyRecordUpdateOne {
  420. if v != nil {
  421. _u.SetLockedUntil(*v)
  422. }
  423. return _u
  424. }
  425. // ClearLockedUntil clears the value of the "locked_until" field.
  426. func (_u *IdempotencyRecordUpdateOne) ClearLockedUntil() *IdempotencyRecordUpdateOne {
  427. _u.mutation.ClearLockedUntil()
  428. return _u
  429. }
  430. // SetExpiresAt sets the "expires_at" field.
  431. func (_u *IdempotencyRecordUpdateOne) SetExpiresAt(v time.Time) *IdempotencyRecordUpdateOne {
  432. _u.mutation.SetExpiresAt(v)
  433. return _u
  434. }
  435. // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
  436. func (_u *IdempotencyRecordUpdateOne) SetNillableExpiresAt(v *time.Time) *IdempotencyRecordUpdateOne {
  437. if v != nil {
  438. _u.SetExpiresAt(*v)
  439. }
  440. return _u
  441. }
  442. // Mutation returns the IdempotencyRecordMutation object of the builder.
  443. func (_u *IdempotencyRecordUpdateOne) Mutation() *IdempotencyRecordMutation {
  444. return _u.mutation
  445. }
  446. // Where appends a list predicates to the IdempotencyRecordUpdate builder.
  447. func (_u *IdempotencyRecordUpdateOne) Where(ps ...predicate.IdempotencyRecord) *IdempotencyRecordUpdateOne {
  448. _u.mutation.Where(ps...)
  449. return _u
  450. }
  451. // Select allows selecting one or more fields (columns) of the returned entity.
  452. // The default is selecting all fields defined in the entity schema.
  453. func (_u *IdempotencyRecordUpdateOne) Select(field string, fields ...string) *IdempotencyRecordUpdateOne {
  454. _u.fields = append([]string{field}, fields...)
  455. return _u
  456. }
  457. // Save executes the query and returns the updated IdempotencyRecord entity.
  458. func (_u *IdempotencyRecordUpdateOne) Save(ctx context.Context) (*IdempotencyRecord, error) {
  459. _u.defaults()
  460. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  461. }
  462. // SaveX is like Save, but panics if an error occurs.
  463. func (_u *IdempotencyRecordUpdateOne) SaveX(ctx context.Context) *IdempotencyRecord {
  464. node, err := _u.Save(ctx)
  465. if err != nil {
  466. panic(err)
  467. }
  468. return node
  469. }
  470. // Exec executes the query on the entity.
  471. func (_u *IdempotencyRecordUpdateOne) Exec(ctx context.Context) error {
  472. _, err := _u.Save(ctx)
  473. return err
  474. }
  475. // ExecX is like Exec, but panics if an error occurs.
  476. func (_u *IdempotencyRecordUpdateOne) ExecX(ctx context.Context) {
  477. if err := _u.Exec(ctx); err != nil {
  478. panic(err)
  479. }
  480. }
  481. // defaults sets the default values of the builder before save.
  482. func (_u *IdempotencyRecordUpdateOne) defaults() {
  483. if _, ok := _u.mutation.UpdatedAt(); !ok {
  484. v := idempotencyrecord.UpdateDefaultUpdatedAt()
  485. _u.mutation.SetUpdatedAt(v)
  486. }
  487. }
  488. // check runs all checks and user-defined validators on the builder.
  489. func (_u *IdempotencyRecordUpdateOne) check() error {
  490. if v, ok := _u.mutation.Scope(); ok {
  491. if err := idempotencyrecord.ScopeValidator(v); err != nil {
  492. return &ValidationError{Name: "scope", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.scope": %w`, err)}
  493. }
  494. }
  495. if v, ok := _u.mutation.IdempotencyKeyHash(); ok {
  496. if err := idempotencyrecord.IdempotencyKeyHashValidator(v); err != nil {
  497. return &ValidationError{Name: "idempotency_key_hash", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.idempotency_key_hash": %w`, err)}
  498. }
  499. }
  500. if v, ok := _u.mutation.RequestFingerprint(); ok {
  501. if err := idempotencyrecord.RequestFingerprintValidator(v); err != nil {
  502. return &ValidationError{Name: "request_fingerprint", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.request_fingerprint": %w`, err)}
  503. }
  504. }
  505. if v, ok := _u.mutation.Status(); ok {
  506. if err := idempotencyrecord.StatusValidator(v); err != nil {
  507. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.status": %w`, err)}
  508. }
  509. }
  510. if v, ok := _u.mutation.ErrorReason(); ok {
  511. if err := idempotencyrecord.ErrorReasonValidator(v); err != nil {
  512. return &ValidationError{Name: "error_reason", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.error_reason": %w`, err)}
  513. }
  514. }
  515. return nil
  516. }
  517. func (_u *IdempotencyRecordUpdateOne) sqlSave(ctx context.Context) (_node *IdempotencyRecord, err error) {
  518. if err := _u.check(); err != nil {
  519. return _node, err
  520. }
  521. _spec := sqlgraph.NewUpdateSpec(idempotencyrecord.Table, idempotencyrecord.Columns, sqlgraph.NewFieldSpec(idempotencyrecord.FieldID, field.TypeInt64))
  522. id, ok := _u.mutation.ID()
  523. if !ok {
  524. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "IdempotencyRecord.id" for update`)}
  525. }
  526. _spec.Node.ID.Value = id
  527. if fields := _u.fields; len(fields) > 0 {
  528. _spec.Node.Columns = make([]string, 0, len(fields))
  529. _spec.Node.Columns = append(_spec.Node.Columns, idempotencyrecord.FieldID)
  530. for _, f := range fields {
  531. if !idempotencyrecord.ValidColumn(f) {
  532. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  533. }
  534. if f != idempotencyrecord.FieldID {
  535. _spec.Node.Columns = append(_spec.Node.Columns, f)
  536. }
  537. }
  538. }
  539. if ps := _u.mutation.predicates; len(ps) > 0 {
  540. _spec.Predicate = func(selector *sql.Selector) {
  541. for i := range ps {
  542. ps[i](selector)
  543. }
  544. }
  545. }
  546. if value, ok := _u.mutation.UpdatedAt(); ok {
  547. _spec.SetField(idempotencyrecord.FieldUpdatedAt, field.TypeTime, value)
  548. }
  549. if value, ok := _u.mutation.Scope(); ok {
  550. _spec.SetField(idempotencyrecord.FieldScope, field.TypeString, value)
  551. }
  552. if value, ok := _u.mutation.IdempotencyKeyHash(); ok {
  553. _spec.SetField(idempotencyrecord.FieldIdempotencyKeyHash, field.TypeString, value)
  554. }
  555. if value, ok := _u.mutation.RequestFingerprint(); ok {
  556. _spec.SetField(idempotencyrecord.FieldRequestFingerprint, field.TypeString, value)
  557. }
  558. if value, ok := _u.mutation.Status(); ok {
  559. _spec.SetField(idempotencyrecord.FieldStatus, field.TypeString, value)
  560. }
  561. if value, ok := _u.mutation.ResponseStatus(); ok {
  562. _spec.SetField(idempotencyrecord.FieldResponseStatus, field.TypeInt, value)
  563. }
  564. if value, ok := _u.mutation.AddedResponseStatus(); ok {
  565. _spec.AddField(idempotencyrecord.FieldResponseStatus, field.TypeInt, value)
  566. }
  567. if _u.mutation.ResponseStatusCleared() {
  568. _spec.ClearField(idempotencyrecord.FieldResponseStatus, field.TypeInt)
  569. }
  570. if value, ok := _u.mutation.ResponseBody(); ok {
  571. _spec.SetField(idempotencyrecord.FieldResponseBody, field.TypeString, value)
  572. }
  573. if _u.mutation.ResponseBodyCleared() {
  574. _spec.ClearField(idempotencyrecord.FieldResponseBody, field.TypeString)
  575. }
  576. if value, ok := _u.mutation.ErrorReason(); ok {
  577. _spec.SetField(idempotencyrecord.FieldErrorReason, field.TypeString, value)
  578. }
  579. if _u.mutation.ErrorReasonCleared() {
  580. _spec.ClearField(idempotencyrecord.FieldErrorReason, field.TypeString)
  581. }
  582. if value, ok := _u.mutation.LockedUntil(); ok {
  583. _spec.SetField(idempotencyrecord.FieldLockedUntil, field.TypeTime, value)
  584. }
  585. if _u.mutation.LockedUntilCleared() {
  586. _spec.ClearField(idempotencyrecord.FieldLockedUntil, field.TypeTime)
  587. }
  588. if value, ok := _u.mutation.ExpiresAt(); ok {
  589. _spec.SetField(idempotencyrecord.FieldExpiresAt, field.TypeTime, value)
  590. }
  591. _node = &IdempotencyRecord{config: _u.config}
  592. _spec.Assign = _node.assignValues
  593. _spec.ScanValues = _node.scanValues
  594. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  595. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  596. err = &NotFoundError{idempotencyrecord.Label}
  597. } else if sqlgraph.IsConstraintError(err) {
  598. err = &ConstraintError{msg: err.Error(), wrap: err}
  599. }
  600. return nil, err
  601. }
  602. _u.mutation.done = true
  603. return _node, nil
  604. }