compapijob_update.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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/compapijob"
  9. "wechat-api/ent/custom_types"
  10. "wechat-api/ent/predicate"
  11. "entgo.io/ent/dialect/sql"
  12. "entgo.io/ent/dialect/sql/sqlgraph"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // CompapiJobUpdate is the builder for updating CompapiJob entities.
  16. type CompapiJobUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *CompapiJobMutation
  20. }
  21. // Where appends a list predicates to the CompapiJobUpdate builder.
  22. func (cju *CompapiJobUpdate) Where(ps ...predicate.CompapiJob) *CompapiJobUpdate {
  23. cju.mutation.Where(ps...)
  24. return cju
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (cju *CompapiJobUpdate) SetUpdatedAt(t time.Time) *CompapiJobUpdate {
  28. cju.mutation.SetUpdatedAt(t)
  29. return cju
  30. }
  31. // SetDistAt sets the "dist_at" field.
  32. func (cju *CompapiJobUpdate) SetDistAt(t time.Time) *CompapiJobUpdate {
  33. cju.mutation.SetDistAt(t)
  34. return cju
  35. }
  36. // SetNillableDistAt sets the "dist_at" field if the given value is not nil.
  37. func (cju *CompapiJobUpdate) SetNillableDistAt(t *time.Time) *CompapiJobUpdate {
  38. if t != nil {
  39. cju.SetDistAt(*t)
  40. }
  41. return cju
  42. }
  43. // ClearDistAt clears the value of the "dist_at" field.
  44. func (cju *CompapiJobUpdate) ClearDistAt() *CompapiJobUpdate {
  45. cju.mutation.ClearDistAt()
  46. return cju
  47. }
  48. // SetDistStatus sets the "dist_status" field.
  49. func (cju *CompapiJobUpdate) SetDistStatus(i int8) *CompapiJobUpdate {
  50. cju.mutation.ResetDistStatus()
  51. cju.mutation.SetDistStatus(i)
  52. return cju
  53. }
  54. // SetNillableDistStatus sets the "dist_status" field if the given value is not nil.
  55. func (cju *CompapiJobUpdate) SetNillableDistStatus(i *int8) *CompapiJobUpdate {
  56. if i != nil {
  57. cju.SetDistStatus(*i)
  58. }
  59. return cju
  60. }
  61. // AddDistStatus adds i to the "dist_status" field.
  62. func (cju *CompapiJobUpdate) AddDistStatus(i int8) *CompapiJobUpdate {
  63. cju.mutation.AddDistStatus(i)
  64. return cju
  65. }
  66. // ClearDistStatus clears the value of the "dist_status" field.
  67. func (cju *CompapiJobUpdate) ClearDistStatus() *CompapiJobUpdate {
  68. cju.mutation.ClearDistStatus()
  69. return cju
  70. }
  71. // SetCallbackStatus sets the "callback_status" field.
  72. func (cju *CompapiJobUpdate) SetCallbackStatus(i int8) *CompapiJobUpdate {
  73. cju.mutation.ResetCallbackStatus()
  74. cju.mutation.SetCallbackStatus(i)
  75. return cju
  76. }
  77. // SetNillableCallbackStatus sets the "callback_status" field if the given value is not nil.
  78. func (cju *CompapiJobUpdate) SetNillableCallbackStatus(i *int8) *CompapiJobUpdate {
  79. if i != nil {
  80. cju.SetCallbackStatus(*i)
  81. }
  82. return cju
  83. }
  84. // AddCallbackStatus adds i to the "callback_status" field.
  85. func (cju *CompapiJobUpdate) AddCallbackStatus(i int8) *CompapiJobUpdate {
  86. cju.mutation.AddCallbackStatus(i)
  87. return cju
  88. }
  89. // ClearCallbackStatus clears the value of the "callback_status" field.
  90. func (cju *CompapiJobUpdate) ClearCallbackStatus() *CompapiJobUpdate {
  91. cju.mutation.ClearCallbackStatus()
  92. return cju
  93. }
  94. // SetCallbackURL sets the "callback_url" field.
  95. func (cju *CompapiJobUpdate) SetCallbackURL(s string) *CompapiJobUpdate {
  96. cju.mutation.SetCallbackURL(s)
  97. return cju
  98. }
  99. // SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
  100. func (cju *CompapiJobUpdate) SetNillableCallbackURL(s *string) *CompapiJobUpdate {
  101. if s != nil {
  102. cju.SetCallbackURL(*s)
  103. }
  104. return cju
  105. }
  106. // SetRequestJSON sets the "request_json" field.
  107. func (cju *CompapiJobUpdate) SetRequestJSON(ctd custom_types.OriginalData) *CompapiJobUpdate {
  108. cju.mutation.SetRequestJSON(ctd)
  109. return cju
  110. }
  111. // SetNillableRequestJSON sets the "request_json" field if the given value is not nil.
  112. func (cju *CompapiJobUpdate) SetNillableRequestJSON(ctd *custom_types.OriginalData) *CompapiJobUpdate {
  113. if ctd != nil {
  114. cju.SetRequestJSON(*ctd)
  115. }
  116. return cju
  117. }
  118. // SetAuthToken sets the "auth_token" field.
  119. func (cju *CompapiJobUpdate) SetAuthToken(s string) *CompapiJobUpdate {
  120. cju.mutation.SetAuthToken(s)
  121. return cju
  122. }
  123. // SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
  124. func (cju *CompapiJobUpdate) SetNillableAuthToken(s *string) *CompapiJobUpdate {
  125. if s != nil {
  126. cju.SetAuthToken(*s)
  127. }
  128. return cju
  129. }
  130. // SetEventType sets the "event_type" field.
  131. func (cju *CompapiJobUpdate) SetEventType(s string) *CompapiJobUpdate {
  132. cju.mutation.SetEventType(s)
  133. return cju
  134. }
  135. // SetNillableEventType sets the "event_type" field if the given value is not nil.
  136. func (cju *CompapiJobUpdate) SetNillableEventType(s *string) *CompapiJobUpdate {
  137. if s != nil {
  138. cju.SetEventType(*s)
  139. }
  140. return cju
  141. }
  142. // SetWorkidIdx sets the "workid_idx" field.
  143. func (cju *CompapiJobUpdate) SetWorkidIdx(i int8) *CompapiJobUpdate {
  144. cju.mutation.ResetWorkidIdx()
  145. cju.mutation.SetWorkidIdx(i)
  146. return cju
  147. }
  148. // SetNillableWorkidIdx sets the "workid_idx" field if the given value is not nil.
  149. func (cju *CompapiJobUpdate) SetNillableWorkidIdx(i *int8) *CompapiJobUpdate {
  150. if i != nil {
  151. cju.SetWorkidIdx(*i)
  152. }
  153. return cju
  154. }
  155. // AddWorkidIdx adds i to the "workid_idx" field.
  156. func (cju *CompapiJobUpdate) AddWorkidIdx(i int8) *CompapiJobUpdate {
  157. cju.mutation.AddWorkidIdx(i)
  158. return cju
  159. }
  160. // ClearWorkidIdx clears the value of the "workid_idx" field.
  161. func (cju *CompapiJobUpdate) ClearWorkidIdx() *CompapiJobUpdate {
  162. cju.mutation.ClearWorkidIdx()
  163. return cju
  164. }
  165. // SetChatID sets the "chat_id" field.
  166. func (cju *CompapiJobUpdate) SetChatID(s string) *CompapiJobUpdate {
  167. cju.mutation.SetChatID(s)
  168. return cju
  169. }
  170. // SetNillableChatID sets the "chat_id" field if the given value is not nil.
  171. func (cju *CompapiJobUpdate) SetNillableChatID(s *string) *CompapiJobUpdate {
  172. if s != nil {
  173. cju.SetChatID(*s)
  174. }
  175. return cju
  176. }
  177. // ClearChatID clears the value of the "chat_id" field.
  178. func (cju *CompapiJobUpdate) ClearChatID() *CompapiJobUpdate {
  179. cju.mutation.ClearChatID()
  180. return cju
  181. }
  182. // SetRetryCount sets the "retry_count" field.
  183. func (cju *CompapiJobUpdate) SetRetryCount(i int8) *CompapiJobUpdate {
  184. cju.mutation.ResetRetryCount()
  185. cju.mutation.SetRetryCount(i)
  186. return cju
  187. }
  188. // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
  189. func (cju *CompapiJobUpdate) SetNillableRetryCount(i *int8) *CompapiJobUpdate {
  190. if i != nil {
  191. cju.SetRetryCount(*i)
  192. }
  193. return cju
  194. }
  195. // AddRetryCount adds i to the "retry_count" field.
  196. func (cju *CompapiJobUpdate) AddRetryCount(i int8) *CompapiJobUpdate {
  197. cju.mutation.AddRetryCount(i)
  198. return cju
  199. }
  200. // ClearRetryCount clears the value of the "retry_count" field.
  201. func (cju *CompapiJobUpdate) ClearRetryCount() *CompapiJobUpdate {
  202. cju.mutation.ClearRetryCount()
  203. return cju
  204. }
  205. // Mutation returns the CompapiJobMutation object of the builder.
  206. func (cju *CompapiJobUpdate) Mutation() *CompapiJobMutation {
  207. return cju.mutation
  208. }
  209. // Save executes the query and returns the number of nodes affected by the update operation.
  210. func (cju *CompapiJobUpdate) Save(ctx context.Context) (int, error) {
  211. cju.defaults()
  212. return withHooks(ctx, cju.sqlSave, cju.mutation, cju.hooks)
  213. }
  214. // SaveX is like Save, but panics if an error occurs.
  215. func (cju *CompapiJobUpdate) SaveX(ctx context.Context) int {
  216. affected, err := cju.Save(ctx)
  217. if err != nil {
  218. panic(err)
  219. }
  220. return affected
  221. }
  222. // Exec executes the query.
  223. func (cju *CompapiJobUpdate) Exec(ctx context.Context) error {
  224. _, err := cju.Save(ctx)
  225. return err
  226. }
  227. // ExecX is like Exec, but panics if an error occurs.
  228. func (cju *CompapiJobUpdate) ExecX(ctx context.Context) {
  229. if err := cju.Exec(ctx); err != nil {
  230. panic(err)
  231. }
  232. }
  233. // defaults sets the default values of the builder before save.
  234. func (cju *CompapiJobUpdate) defaults() {
  235. if _, ok := cju.mutation.UpdatedAt(); !ok {
  236. v := compapijob.UpdateDefaultUpdatedAt()
  237. cju.mutation.SetUpdatedAt(v)
  238. }
  239. }
  240. func (cju *CompapiJobUpdate) sqlSave(ctx context.Context) (n int, err error) {
  241. _spec := sqlgraph.NewUpdateSpec(compapijob.Table, compapijob.Columns, sqlgraph.NewFieldSpec(compapijob.FieldID, field.TypeUint64))
  242. if ps := cju.mutation.predicates; len(ps) > 0 {
  243. _spec.Predicate = func(selector *sql.Selector) {
  244. for i := range ps {
  245. ps[i](selector)
  246. }
  247. }
  248. }
  249. if value, ok := cju.mutation.UpdatedAt(); ok {
  250. _spec.SetField(compapijob.FieldUpdatedAt, field.TypeTime, value)
  251. }
  252. if value, ok := cju.mutation.DistAt(); ok {
  253. _spec.SetField(compapijob.FieldDistAt, field.TypeTime, value)
  254. }
  255. if cju.mutation.DistAtCleared() {
  256. _spec.ClearField(compapijob.FieldDistAt, field.TypeTime)
  257. }
  258. if value, ok := cju.mutation.DistStatus(); ok {
  259. _spec.SetField(compapijob.FieldDistStatus, field.TypeInt8, value)
  260. }
  261. if value, ok := cju.mutation.AddedDistStatus(); ok {
  262. _spec.AddField(compapijob.FieldDistStatus, field.TypeInt8, value)
  263. }
  264. if cju.mutation.DistStatusCleared() {
  265. _spec.ClearField(compapijob.FieldDistStatus, field.TypeInt8)
  266. }
  267. if value, ok := cju.mutation.CallbackStatus(); ok {
  268. _spec.SetField(compapijob.FieldCallbackStatus, field.TypeInt8, value)
  269. }
  270. if value, ok := cju.mutation.AddedCallbackStatus(); ok {
  271. _spec.AddField(compapijob.FieldCallbackStatus, field.TypeInt8, value)
  272. }
  273. if cju.mutation.CallbackStatusCleared() {
  274. _spec.ClearField(compapijob.FieldCallbackStatus, field.TypeInt8)
  275. }
  276. if value, ok := cju.mutation.CallbackURL(); ok {
  277. _spec.SetField(compapijob.FieldCallbackURL, field.TypeString, value)
  278. }
  279. if value, ok := cju.mutation.RequestJSON(); ok {
  280. _spec.SetField(compapijob.FieldRequestJSON, field.TypeJSON, value)
  281. }
  282. if value, ok := cju.mutation.AuthToken(); ok {
  283. _spec.SetField(compapijob.FieldAuthToken, field.TypeString, value)
  284. }
  285. if value, ok := cju.mutation.EventType(); ok {
  286. _spec.SetField(compapijob.FieldEventType, field.TypeString, value)
  287. }
  288. if value, ok := cju.mutation.WorkidIdx(); ok {
  289. _spec.SetField(compapijob.FieldWorkidIdx, field.TypeInt8, value)
  290. }
  291. if value, ok := cju.mutation.AddedWorkidIdx(); ok {
  292. _spec.AddField(compapijob.FieldWorkidIdx, field.TypeInt8, value)
  293. }
  294. if cju.mutation.WorkidIdxCleared() {
  295. _spec.ClearField(compapijob.FieldWorkidIdx, field.TypeInt8)
  296. }
  297. if value, ok := cju.mutation.ChatID(); ok {
  298. _spec.SetField(compapijob.FieldChatID, field.TypeString, value)
  299. }
  300. if cju.mutation.ChatIDCleared() {
  301. _spec.ClearField(compapijob.FieldChatID, field.TypeString)
  302. }
  303. if value, ok := cju.mutation.RetryCount(); ok {
  304. _spec.SetField(compapijob.FieldRetryCount, field.TypeInt8, value)
  305. }
  306. if value, ok := cju.mutation.AddedRetryCount(); ok {
  307. _spec.AddField(compapijob.FieldRetryCount, field.TypeInt8, value)
  308. }
  309. if cju.mutation.RetryCountCleared() {
  310. _spec.ClearField(compapijob.FieldRetryCount, field.TypeInt8)
  311. }
  312. if n, err = sqlgraph.UpdateNodes(ctx, cju.driver, _spec); err != nil {
  313. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  314. err = &NotFoundError{compapijob.Label}
  315. } else if sqlgraph.IsConstraintError(err) {
  316. err = &ConstraintError{msg: err.Error(), wrap: err}
  317. }
  318. return 0, err
  319. }
  320. cju.mutation.done = true
  321. return n, nil
  322. }
  323. // CompapiJobUpdateOne is the builder for updating a single CompapiJob entity.
  324. type CompapiJobUpdateOne struct {
  325. config
  326. fields []string
  327. hooks []Hook
  328. mutation *CompapiJobMutation
  329. }
  330. // SetUpdatedAt sets the "updated_at" field.
  331. func (cjuo *CompapiJobUpdateOne) SetUpdatedAt(t time.Time) *CompapiJobUpdateOne {
  332. cjuo.mutation.SetUpdatedAt(t)
  333. return cjuo
  334. }
  335. // SetDistAt sets the "dist_at" field.
  336. func (cjuo *CompapiJobUpdateOne) SetDistAt(t time.Time) *CompapiJobUpdateOne {
  337. cjuo.mutation.SetDistAt(t)
  338. return cjuo
  339. }
  340. // SetNillableDistAt sets the "dist_at" field if the given value is not nil.
  341. func (cjuo *CompapiJobUpdateOne) SetNillableDistAt(t *time.Time) *CompapiJobUpdateOne {
  342. if t != nil {
  343. cjuo.SetDistAt(*t)
  344. }
  345. return cjuo
  346. }
  347. // ClearDistAt clears the value of the "dist_at" field.
  348. func (cjuo *CompapiJobUpdateOne) ClearDistAt() *CompapiJobUpdateOne {
  349. cjuo.mutation.ClearDistAt()
  350. return cjuo
  351. }
  352. // SetDistStatus sets the "dist_status" field.
  353. func (cjuo *CompapiJobUpdateOne) SetDistStatus(i int8) *CompapiJobUpdateOne {
  354. cjuo.mutation.ResetDistStatus()
  355. cjuo.mutation.SetDistStatus(i)
  356. return cjuo
  357. }
  358. // SetNillableDistStatus sets the "dist_status" field if the given value is not nil.
  359. func (cjuo *CompapiJobUpdateOne) SetNillableDistStatus(i *int8) *CompapiJobUpdateOne {
  360. if i != nil {
  361. cjuo.SetDistStatus(*i)
  362. }
  363. return cjuo
  364. }
  365. // AddDistStatus adds i to the "dist_status" field.
  366. func (cjuo *CompapiJobUpdateOne) AddDistStatus(i int8) *CompapiJobUpdateOne {
  367. cjuo.mutation.AddDistStatus(i)
  368. return cjuo
  369. }
  370. // ClearDistStatus clears the value of the "dist_status" field.
  371. func (cjuo *CompapiJobUpdateOne) ClearDistStatus() *CompapiJobUpdateOne {
  372. cjuo.mutation.ClearDistStatus()
  373. return cjuo
  374. }
  375. // SetCallbackStatus sets the "callback_status" field.
  376. func (cjuo *CompapiJobUpdateOne) SetCallbackStatus(i int8) *CompapiJobUpdateOne {
  377. cjuo.mutation.ResetCallbackStatus()
  378. cjuo.mutation.SetCallbackStatus(i)
  379. return cjuo
  380. }
  381. // SetNillableCallbackStatus sets the "callback_status" field if the given value is not nil.
  382. func (cjuo *CompapiJobUpdateOne) SetNillableCallbackStatus(i *int8) *CompapiJobUpdateOne {
  383. if i != nil {
  384. cjuo.SetCallbackStatus(*i)
  385. }
  386. return cjuo
  387. }
  388. // AddCallbackStatus adds i to the "callback_status" field.
  389. func (cjuo *CompapiJobUpdateOne) AddCallbackStatus(i int8) *CompapiJobUpdateOne {
  390. cjuo.mutation.AddCallbackStatus(i)
  391. return cjuo
  392. }
  393. // ClearCallbackStatus clears the value of the "callback_status" field.
  394. func (cjuo *CompapiJobUpdateOne) ClearCallbackStatus() *CompapiJobUpdateOne {
  395. cjuo.mutation.ClearCallbackStatus()
  396. return cjuo
  397. }
  398. // SetCallbackURL sets the "callback_url" field.
  399. func (cjuo *CompapiJobUpdateOne) SetCallbackURL(s string) *CompapiJobUpdateOne {
  400. cjuo.mutation.SetCallbackURL(s)
  401. return cjuo
  402. }
  403. // SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
  404. func (cjuo *CompapiJobUpdateOne) SetNillableCallbackURL(s *string) *CompapiJobUpdateOne {
  405. if s != nil {
  406. cjuo.SetCallbackURL(*s)
  407. }
  408. return cjuo
  409. }
  410. // SetRequestJSON sets the "request_json" field.
  411. func (cjuo *CompapiJobUpdateOne) SetRequestJSON(ctd custom_types.OriginalData) *CompapiJobUpdateOne {
  412. cjuo.mutation.SetRequestJSON(ctd)
  413. return cjuo
  414. }
  415. // SetNillableRequestJSON sets the "request_json" field if the given value is not nil.
  416. func (cjuo *CompapiJobUpdateOne) SetNillableRequestJSON(ctd *custom_types.OriginalData) *CompapiJobUpdateOne {
  417. if ctd != nil {
  418. cjuo.SetRequestJSON(*ctd)
  419. }
  420. return cjuo
  421. }
  422. // SetAuthToken sets the "auth_token" field.
  423. func (cjuo *CompapiJobUpdateOne) SetAuthToken(s string) *CompapiJobUpdateOne {
  424. cjuo.mutation.SetAuthToken(s)
  425. return cjuo
  426. }
  427. // SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
  428. func (cjuo *CompapiJobUpdateOne) SetNillableAuthToken(s *string) *CompapiJobUpdateOne {
  429. if s != nil {
  430. cjuo.SetAuthToken(*s)
  431. }
  432. return cjuo
  433. }
  434. // SetEventType sets the "event_type" field.
  435. func (cjuo *CompapiJobUpdateOne) SetEventType(s string) *CompapiJobUpdateOne {
  436. cjuo.mutation.SetEventType(s)
  437. return cjuo
  438. }
  439. // SetNillableEventType sets the "event_type" field if the given value is not nil.
  440. func (cjuo *CompapiJobUpdateOne) SetNillableEventType(s *string) *CompapiJobUpdateOne {
  441. if s != nil {
  442. cjuo.SetEventType(*s)
  443. }
  444. return cjuo
  445. }
  446. // SetWorkidIdx sets the "workid_idx" field.
  447. func (cjuo *CompapiJobUpdateOne) SetWorkidIdx(i int8) *CompapiJobUpdateOne {
  448. cjuo.mutation.ResetWorkidIdx()
  449. cjuo.mutation.SetWorkidIdx(i)
  450. return cjuo
  451. }
  452. // SetNillableWorkidIdx sets the "workid_idx" field if the given value is not nil.
  453. func (cjuo *CompapiJobUpdateOne) SetNillableWorkidIdx(i *int8) *CompapiJobUpdateOne {
  454. if i != nil {
  455. cjuo.SetWorkidIdx(*i)
  456. }
  457. return cjuo
  458. }
  459. // AddWorkidIdx adds i to the "workid_idx" field.
  460. func (cjuo *CompapiJobUpdateOne) AddWorkidIdx(i int8) *CompapiJobUpdateOne {
  461. cjuo.mutation.AddWorkidIdx(i)
  462. return cjuo
  463. }
  464. // ClearWorkidIdx clears the value of the "workid_idx" field.
  465. func (cjuo *CompapiJobUpdateOne) ClearWorkidIdx() *CompapiJobUpdateOne {
  466. cjuo.mutation.ClearWorkidIdx()
  467. return cjuo
  468. }
  469. // SetChatID sets the "chat_id" field.
  470. func (cjuo *CompapiJobUpdateOne) SetChatID(s string) *CompapiJobUpdateOne {
  471. cjuo.mutation.SetChatID(s)
  472. return cjuo
  473. }
  474. // SetNillableChatID sets the "chat_id" field if the given value is not nil.
  475. func (cjuo *CompapiJobUpdateOne) SetNillableChatID(s *string) *CompapiJobUpdateOne {
  476. if s != nil {
  477. cjuo.SetChatID(*s)
  478. }
  479. return cjuo
  480. }
  481. // ClearChatID clears the value of the "chat_id" field.
  482. func (cjuo *CompapiJobUpdateOne) ClearChatID() *CompapiJobUpdateOne {
  483. cjuo.mutation.ClearChatID()
  484. return cjuo
  485. }
  486. // SetRetryCount sets the "retry_count" field.
  487. func (cjuo *CompapiJobUpdateOne) SetRetryCount(i int8) *CompapiJobUpdateOne {
  488. cjuo.mutation.ResetRetryCount()
  489. cjuo.mutation.SetRetryCount(i)
  490. return cjuo
  491. }
  492. // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
  493. func (cjuo *CompapiJobUpdateOne) SetNillableRetryCount(i *int8) *CompapiJobUpdateOne {
  494. if i != nil {
  495. cjuo.SetRetryCount(*i)
  496. }
  497. return cjuo
  498. }
  499. // AddRetryCount adds i to the "retry_count" field.
  500. func (cjuo *CompapiJobUpdateOne) AddRetryCount(i int8) *CompapiJobUpdateOne {
  501. cjuo.mutation.AddRetryCount(i)
  502. return cjuo
  503. }
  504. // ClearRetryCount clears the value of the "retry_count" field.
  505. func (cjuo *CompapiJobUpdateOne) ClearRetryCount() *CompapiJobUpdateOne {
  506. cjuo.mutation.ClearRetryCount()
  507. return cjuo
  508. }
  509. // Mutation returns the CompapiJobMutation object of the builder.
  510. func (cjuo *CompapiJobUpdateOne) Mutation() *CompapiJobMutation {
  511. return cjuo.mutation
  512. }
  513. // Where appends a list predicates to the CompapiJobUpdate builder.
  514. func (cjuo *CompapiJobUpdateOne) Where(ps ...predicate.CompapiJob) *CompapiJobUpdateOne {
  515. cjuo.mutation.Where(ps...)
  516. return cjuo
  517. }
  518. // Select allows selecting one or more fields (columns) of the returned entity.
  519. // The default is selecting all fields defined in the entity schema.
  520. func (cjuo *CompapiJobUpdateOne) Select(field string, fields ...string) *CompapiJobUpdateOne {
  521. cjuo.fields = append([]string{field}, fields...)
  522. return cjuo
  523. }
  524. // Save executes the query and returns the updated CompapiJob entity.
  525. func (cjuo *CompapiJobUpdateOne) Save(ctx context.Context) (*CompapiJob, error) {
  526. cjuo.defaults()
  527. return withHooks(ctx, cjuo.sqlSave, cjuo.mutation, cjuo.hooks)
  528. }
  529. // SaveX is like Save, but panics if an error occurs.
  530. func (cjuo *CompapiJobUpdateOne) SaveX(ctx context.Context) *CompapiJob {
  531. node, err := cjuo.Save(ctx)
  532. if err != nil {
  533. panic(err)
  534. }
  535. return node
  536. }
  537. // Exec executes the query on the entity.
  538. func (cjuo *CompapiJobUpdateOne) Exec(ctx context.Context) error {
  539. _, err := cjuo.Save(ctx)
  540. return err
  541. }
  542. // ExecX is like Exec, but panics if an error occurs.
  543. func (cjuo *CompapiJobUpdateOne) ExecX(ctx context.Context) {
  544. if err := cjuo.Exec(ctx); err != nil {
  545. panic(err)
  546. }
  547. }
  548. // defaults sets the default values of the builder before save.
  549. func (cjuo *CompapiJobUpdateOne) defaults() {
  550. if _, ok := cjuo.mutation.UpdatedAt(); !ok {
  551. v := compapijob.UpdateDefaultUpdatedAt()
  552. cjuo.mutation.SetUpdatedAt(v)
  553. }
  554. }
  555. func (cjuo *CompapiJobUpdateOne) sqlSave(ctx context.Context) (_node *CompapiJob, err error) {
  556. _spec := sqlgraph.NewUpdateSpec(compapijob.Table, compapijob.Columns, sqlgraph.NewFieldSpec(compapijob.FieldID, field.TypeUint64))
  557. id, ok := cjuo.mutation.ID()
  558. if !ok {
  559. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CompapiJob.id" for update`)}
  560. }
  561. _spec.Node.ID.Value = id
  562. if fields := cjuo.fields; len(fields) > 0 {
  563. _spec.Node.Columns = make([]string, 0, len(fields))
  564. _spec.Node.Columns = append(_spec.Node.Columns, compapijob.FieldID)
  565. for _, f := range fields {
  566. if !compapijob.ValidColumn(f) {
  567. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  568. }
  569. if f != compapijob.FieldID {
  570. _spec.Node.Columns = append(_spec.Node.Columns, f)
  571. }
  572. }
  573. }
  574. if ps := cjuo.mutation.predicates; len(ps) > 0 {
  575. _spec.Predicate = func(selector *sql.Selector) {
  576. for i := range ps {
  577. ps[i](selector)
  578. }
  579. }
  580. }
  581. if value, ok := cjuo.mutation.UpdatedAt(); ok {
  582. _spec.SetField(compapijob.FieldUpdatedAt, field.TypeTime, value)
  583. }
  584. if value, ok := cjuo.mutation.DistAt(); ok {
  585. _spec.SetField(compapijob.FieldDistAt, field.TypeTime, value)
  586. }
  587. if cjuo.mutation.DistAtCleared() {
  588. _spec.ClearField(compapijob.FieldDistAt, field.TypeTime)
  589. }
  590. if value, ok := cjuo.mutation.DistStatus(); ok {
  591. _spec.SetField(compapijob.FieldDistStatus, field.TypeInt8, value)
  592. }
  593. if value, ok := cjuo.mutation.AddedDistStatus(); ok {
  594. _spec.AddField(compapijob.FieldDistStatus, field.TypeInt8, value)
  595. }
  596. if cjuo.mutation.DistStatusCleared() {
  597. _spec.ClearField(compapijob.FieldDistStatus, field.TypeInt8)
  598. }
  599. if value, ok := cjuo.mutation.CallbackStatus(); ok {
  600. _spec.SetField(compapijob.FieldCallbackStatus, field.TypeInt8, value)
  601. }
  602. if value, ok := cjuo.mutation.AddedCallbackStatus(); ok {
  603. _spec.AddField(compapijob.FieldCallbackStatus, field.TypeInt8, value)
  604. }
  605. if cjuo.mutation.CallbackStatusCleared() {
  606. _spec.ClearField(compapijob.FieldCallbackStatus, field.TypeInt8)
  607. }
  608. if value, ok := cjuo.mutation.CallbackURL(); ok {
  609. _spec.SetField(compapijob.FieldCallbackURL, field.TypeString, value)
  610. }
  611. if value, ok := cjuo.mutation.RequestJSON(); ok {
  612. _spec.SetField(compapijob.FieldRequestJSON, field.TypeJSON, value)
  613. }
  614. if value, ok := cjuo.mutation.AuthToken(); ok {
  615. _spec.SetField(compapijob.FieldAuthToken, field.TypeString, value)
  616. }
  617. if value, ok := cjuo.mutation.EventType(); ok {
  618. _spec.SetField(compapijob.FieldEventType, field.TypeString, value)
  619. }
  620. if value, ok := cjuo.mutation.WorkidIdx(); ok {
  621. _spec.SetField(compapijob.FieldWorkidIdx, field.TypeInt8, value)
  622. }
  623. if value, ok := cjuo.mutation.AddedWorkidIdx(); ok {
  624. _spec.AddField(compapijob.FieldWorkidIdx, field.TypeInt8, value)
  625. }
  626. if cjuo.mutation.WorkidIdxCleared() {
  627. _spec.ClearField(compapijob.FieldWorkidIdx, field.TypeInt8)
  628. }
  629. if value, ok := cjuo.mutation.ChatID(); ok {
  630. _spec.SetField(compapijob.FieldChatID, field.TypeString, value)
  631. }
  632. if cjuo.mutation.ChatIDCleared() {
  633. _spec.ClearField(compapijob.FieldChatID, field.TypeString)
  634. }
  635. if value, ok := cjuo.mutation.RetryCount(); ok {
  636. _spec.SetField(compapijob.FieldRetryCount, field.TypeInt8, value)
  637. }
  638. if value, ok := cjuo.mutation.AddedRetryCount(); ok {
  639. _spec.AddField(compapijob.FieldRetryCount, field.TypeInt8, value)
  640. }
  641. if cjuo.mutation.RetryCountCleared() {
  642. _spec.ClearField(compapijob.FieldRetryCount, field.TypeInt8)
  643. }
  644. _node = &CompapiJob{config: cjuo.config}
  645. _spec.Assign = _node.assignValues
  646. _spec.ScanValues = _node.scanValues
  647. if err = sqlgraph.UpdateNode(ctx, cjuo.driver, _spec); err != nil {
  648. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  649. err = &NotFoundError{compapijob.Label}
  650. } else if sqlgraph.IsConstraintError(err) {
  651. err = &ConstraintError{msg: err.Error(), wrap: err}
  652. }
  653. return nil, err
  654. }
  655. cjuo.mutation.done = true
  656. return _node, nil
  657. }