compapiasynctask_update.go 26 KB

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