compapiasynctask_update.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  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. // SetResponseChatItemID sets the "response_chat_item_id" field.
  72. func (cau *CompapiAsynctaskUpdate) SetResponseChatItemID(s string) *CompapiAsynctaskUpdate {
  73. cau.mutation.SetResponseChatItemID(s)
  74. return cau
  75. }
  76. // SetNillableResponseChatItemID sets the "response_chat_item_id" field if the given value is not nil.
  77. func (cau *CompapiAsynctaskUpdate) SetNillableResponseChatItemID(s *string) *CompapiAsynctaskUpdate {
  78. if s != nil {
  79. cau.SetResponseChatItemID(*s)
  80. }
  81. return cau
  82. }
  83. // ClearResponseChatItemID clears the value of the "response_chat_item_id" field.
  84. func (cau *CompapiAsynctaskUpdate) ClearResponseChatItemID() *CompapiAsynctaskUpdate {
  85. cau.mutation.ClearResponseChatItemID()
  86. return cau
  87. }
  88. // SetOrganizationID sets the "organization_id" field.
  89. func (cau *CompapiAsynctaskUpdate) SetOrganizationID(u uint64) *CompapiAsynctaskUpdate {
  90. cau.mutation.ResetOrganizationID()
  91. cau.mutation.SetOrganizationID(u)
  92. return cau
  93. }
  94. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  95. func (cau *CompapiAsynctaskUpdate) SetNillableOrganizationID(u *uint64) *CompapiAsynctaskUpdate {
  96. if u != nil {
  97. cau.SetOrganizationID(*u)
  98. }
  99. return cau
  100. }
  101. // AddOrganizationID adds u to the "organization_id" field.
  102. func (cau *CompapiAsynctaskUpdate) AddOrganizationID(u int64) *CompapiAsynctaskUpdate {
  103. cau.mutation.AddOrganizationID(u)
  104. return cau
  105. }
  106. // SetOpenaiBase sets the "openai_base" field.
  107. func (cau *CompapiAsynctaskUpdate) SetOpenaiBase(s string) *CompapiAsynctaskUpdate {
  108. cau.mutation.SetOpenaiBase(s)
  109. return cau
  110. }
  111. // SetNillableOpenaiBase sets the "openai_base" field if the given value is not nil.
  112. func (cau *CompapiAsynctaskUpdate) SetNillableOpenaiBase(s *string) *CompapiAsynctaskUpdate {
  113. if s != nil {
  114. cau.SetOpenaiBase(*s)
  115. }
  116. return cau
  117. }
  118. // SetOpenaiKey sets the "openai_key" field.
  119. func (cau *CompapiAsynctaskUpdate) SetOpenaiKey(s string) *CompapiAsynctaskUpdate {
  120. cau.mutation.SetOpenaiKey(s)
  121. return cau
  122. }
  123. // SetNillableOpenaiKey sets the "openai_key" field if the given value is not nil.
  124. func (cau *CompapiAsynctaskUpdate) SetNillableOpenaiKey(s *string) *CompapiAsynctaskUpdate {
  125. if s != nil {
  126. cau.SetOpenaiKey(*s)
  127. }
  128. return cau
  129. }
  130. // SetRequestRaw sets the "request_raw" field.
  131. func (cau *CompapiAsynctaskUpdate) SetRequestRaw(s string) *CompapiAsynctaskUpdate {
  132. cau.mutation.SetRequestRaw(s)
  133. return cau
  134. }
  135. // SetNillableRequestRaw sets the "request_raw" field if the given value is not nil.
  136. func (cau *CompapiAsynctaskUpdate) SetNillableRequestRaw(s *string) *CompapiAsynctaskUpdate {
  137. if s != nil {
  138. cau.SetRequestRaw(*s)
  139. }
  140. return cau
  141. }
  142. // SetResponseRaw sets the "response_raw" field.
  143. func (cau *CompapiAsynctaskUpdate) SetResponseRaw(s string) *CompapiAsynctaskUpdate {
  144. cau.mutation.SetResponseRaw(s)
  145. return cau
  146. }
  147. // SetNillableResponseRaw sets the "response_raw" field if the given value is not nil.
  148. func (cau *CompapiAsynctaskUpdate) SetNillableResponseRaw(s *string) *CompapiAsynctaskUpdate {
  149. if s != nil {
  150. cau.SetResponseRaw(*s)
  151. }
  152. return cau
  153. }
  154. // ClearResponseRaw clears the value of the "response_raw" field.
  155. func (cau *CompapiAsynctaskUpdate) ClearResponseRaw() *CompapiAsynctaskUpdate {
  156. cau.mutation.ClearResponseRaw()
  157. return cau
  158. }
  159. // SetCallbackURL sets the "callback_url" field.
  160. func (cau *CompapiAsynctaskUpdate) SetCallbackURL(s string) *CompapiAsynctaskUpdate {
  161. cau.mutation.SetCallbackURL(s)
  162. return cau
  163. }
  164. // SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
  165. func (cau *CompapiAsynctaskUpdate) SetNillableCallbackURL(s *string) *CompapiAsynctaskUpdate {
  166. if s != nil {
  167. cau.SetCallbackURL(*s)
  168. }
  169. return cau
  170. }
  171. // SetCallbackResponseRaw sets the "callback_response_raw" field.
  172. func (cau *CompapiAsynctaskUpdate) SetCallbackResponseRaw(s string) *CompapiAsynctaskUpdate {
  173. cau.mutation.SetCallbackResponseRaw(s)
  174. return cau
  175. }
  176. // SetNillableCallbackResponseRaw sets the "callback_response_raw" field if the given value is not nil.
  177. func (cau *CompapiAsynctaskUpdate) SetNillableCallbackResponseRaw(s *string) *CompapiAsynctaskUpdate {
  178. if s != nil {
  179. cau.SetCallbackResponseRaw(*s)
  180. }
  181. return cau
  182. }
  183. // ClearCallbackResponseRaw clears the value of the "callback_response_raw" field.
  184. func (cau *CompapiAsynctaskUpdate) ClearCallbackResponseRaw() *CompapiAsynctaskUpdate {
  185. cau.mutation.ClearCallbackResponseRaw()
  186. return cau
  187. }
  188. // SetModel sets the "model" field.
  189. func (cau *CompapiAsynctaskUpdate) SetModel(s string) *CompapiAsynctaskUpdate {
  190. cau.mutation.SetModel(s)
  191. return cau
  192. }
  193. // SetNillableModel sets the "model" field if the given value is not nil.
  194. func (cau *CompapiAsynctaskUpdate) SetNillableModel(s *string) *CompapiAsynctaskUpdate {
  195. if s != nil {
  196. cau.SetModel(*s)
  197. }
  198. return cau
  199. }
  200. // ClearModel clears the value of the "model" field.
  201. func (cau *CompapiAsynctaskUpdate) ClearModel() *CompapiAsynctaskUpdate {
  202. cau.mutation.ClearModel()
  203. return cau
  204. }
  205. // SetTaskStatus sets the "task_status" field.
  206. func (cau *CompapiAsynctaskUpdate) SetTaskStatus(i int8) *CompapiAsynctaskUpdate {
  207. cau.mutation.ResetTaskStatus()
  208. cau.mutation.SetTaskStatus(i)
  209. return cau
  210. }
  211. // SetNillableTaskStatus sets the "task_status" field if the given value is not nil.
  212. func (cau *CompapiAsynctaskUpdate) SetNillableTaskStatus(i *int8) *CompapiAsynctaskUpdate {
  213. if i != nil {
  214. cau.SetTaskStatus(*i)
  215. }
  216. return cau
  217. }
  218. // AddTaskStatus adds i to the "task_status" field.
  219. func (cau *CompapiAsynctaskUpdate) AddTaskStatus(i int8) *CompapiAsynctaskUpdate {
  220. cau.mutation.AddTaskStatus(i)
  221. return cau
  222. }
  223. // ClearTaskStatus clears the value of the "task_status" field.
  224. func (cau *CompapiAsynctaskUpdate) ClearTaskStatus() *CompapiAsynctaskUpdate {
  225. cau.mutation.ClearTaskStatus()
  226. return cau
  227. }
  228. // SetRetryCount sets the "retry_count" field.
  229. func (cau *CompapiAsynctaskUpdate) SetRetryCount(i int8) *CompapiAsynctaskUpdate {
  230. cau.mutation.ResetRetryCount()
  231. cau.mutation.SetRetryCount(i)
  232. return cau
  233. }
  234. // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
  235. func (cau *CompapiAsynctaskUpdate) SetNillableRetryCount(i *int8) *CompapiAsynctaskUpdate {
  236. if i != nil {
  237. cau.SetRetryCount(*i)
  238. }
  239. return cau
  240. }
  241. // AddRetryCount adds i to the "retry_count" field.
  242. func (cau *CompapiAsynctaskUpdate) AddRetryCount(i int8) *CompapiAsynctaskUpdate {
  243. cau.mutation.AddRetryCount(i)
  244. return cau
  245. }
  246. // ClearRetryCount clears the value of the "retry_count" field.
  247. func (cau *CompapiAsynctaskUpdate) ClearRetryCount() *CompapiAsynctaskUpdate {
  248. cau.mutation.ClearRetryCount()
  249. return cau
  250. }
  251. // SetLastError sets the "last_error" field.
  252. func (cau *CompapiAsynctaskUpdate) SetLastError(s string) *CompapiAsynctaskUpdate {
  253. cau.mutation.SetLastError(s)
  254. return cau
  255. }
  256. // SetNillableLastError sets the "last_error" field if the given value is not nil.
  257. func (cau *CompapiAsynctaskUpdate) SetNillableLastError(s *string) *CompapiAsynctaskUpdate {
  258. if s != nil {
  259. cau.SetLastError(*s)
  260. }
  261. return cau
  262. }
  263. // ClearLastError clears the value of the "last_error" field.
  264. func (cau *CompapiAsynctaskUpdate) ClearLastError() *CompapiAsynctaskUpdate {
  265. cau.mutation.ClearLastError()
  266. return cau
  267. }
  268. // Mutation returns the CompapiAsynctaskMutation object of the builder.
  269. func (cau *CompapiAsynctaskUpdate) Mutation() *CompapiAsynctaskMutation {
  270. return cau.mutation
  271. }
  272. // Save executes the query and returns the number of nodes affected by the update operation.
  273. func (cau *CompapiAsynctaskUpdate) Save(ctx context.Context) (int, error) {
  274. cau.defaults()
  275. return withHooks(ctx, cau.sqlSave, cau.mutation, cau.hooks)
  276. }
  277. // SaveX is like Save, but panics if an error occurs.
  278. func (cau *CompapiAsynctaskUpdate) SaveX(ctx context.Context) int {
  279. affected, err := cau.Save(ctx)
  280. if err != nil {
  281. panic(err)
  282. }
  283. return affected
  284. }
  285. // Exec executes the query.
  286. func (cau *CompapiAsynctaskUpdate) Exec(ctx context.Context) error {
  287. _, err := cau.Save(ctx)
  288. return err
  289. }
  290. // ExecX is like Exec, but panics if an error occurs.
  291. func (cau *CompapiAsynctaskUpdate) ExecX(ctx context.Context) {
  292. if err := cau.Exec(ctx); err != nil {
  293. panic(err)
  294. }
  295. }
  296. // defaults sets the default values of the builder before save.
  297. func (cau *CompapiAsynctaskUpdate) defaults() {
  298. if _, ok := cau.mutation.UpdatedAt(); !ok {
  299. v := compapiasynctask.UpdateDefaultUpdatedAt()
  300. cau.mutation.SetUpdatedAt(v)
  301. }
  302. }
  303. // check runs all checks and user-defined validators on the builder.
  304. func (cau *CompapiAsynctaskUpdate) check() error {
  305. if v, ok := cau.mutation.OrganizationID(); ok {
  306. if err := compapiasynctask.OrganizationIDValidator(v); err != nil {
  307. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.organization_id": %w`, err)}
  308. }
  309. }
  310. if v, ok := cau.mutation.CallbackURL(); ok {
  311. if err := compapiasynctask.CallbackURLValidator(v); err != nil {
  312. return &ValidationError{Name: "callback_url", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.callback_url": %w`, err)}
  313. }
  314. }
  315. return nil
  316. }
  317. func (cau *CompapiAsynctaskUpdate) sqlSave(ctx context.Context) (n int, err error) {
  318. if err := cau.check(); err != nil {
  319. return n, err
  320. }
  321. _spec := sqlgraph.NewUpdateSpec(compapiasynctask.Table, compapiasynctask.Columns, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
  322. if ps := cau.mutation.predicates; len(ps) > 0 {
  323. _spec.Predicate = func(selector *sql.Selector) {
  324. for i := range ps {
  325. ps[i](selector)
  326. }
  327. }
  328. }
  329. if value, ok := cau.mutation.UpdatedAt(); ok {
  330. _spec.SetField(compapiasynctask.FieldUpdatedAt, field.TypeTime, value)
  331. }
  332. if value, ok := cau.mutation.AuthToken(); ok {
  333. _spec.SetField(compapiasynctask.FieldAuthToken, field.TypeString, value)
  334. }
  335. if value, ok := cau.mutation.EventType(); ok {
  336. _spec.SetField(compapiasynctask.FieldEventType, field.TypeString, value)
  337. }
  338. if value, ok := cau.mutation.ChatID(); ok {
  339. _spec.SetField(compapiasynctask.FieldChatID, field.TypeString, value)
  340. }
  341. if cau.mutation.ChatIDCleared() {
  342. _spec.ClearField(compapiasynctask.FieldChatID, field.TypeString)
  343. }
  344. if value, ok := cau.mutation.ResponseChatItemID(); ok {
  345. _spec.SetField(compapiasynctask.FieldResponseChatItemID, field.TypeString, value)
  346. }
  347. if cau.mutation.ResponseChatItemIDCleared() {
  348. _spec.ClearField(compapiasynctask.FieldResponseChatItemID, field.TypeString)
  349. }
  350. if value, ok := cau.mutation.OrganizationID(); ok {
  351. _spec.SetField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
  352. }
  353. if value, ok := cau.mutation.AddedOrganizationID(); ok {
  354. _spec.AddField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
  355. }
  356. if value, ok := cau.mutation.OpenaiBase(); ok {
  357. _spec.SetField(compapiasynctask.FieldOpenaiBase, field.TypeString, value)
  358. }
  359. if value, ok := cau.mutation.OpenaiKey(); ok {
  360. _spec.SetField(compapiasynctask.FieldOpenaiKey, field.TypeString, value)
  361. }
  362. if value, ok := cau.mutation.RequestRaw(); ok {
  363. _spec.SetField(compapiasynctask.FieldRequestRaw, field.TypeString, value)
  364. }
  365. if value, ok := cau.mutation.ResponseRaw(); ok {
  366. _spec.SetField(compapiasynctask.FieldResponseRaw, field.TypeString, value)
  367. }
  368. if cau.mutation.ResponseRawCleared() {
  369. _spec.ClearField(compapiasynctask.FieldResponseRaw, field.TypeString)
  370. }
  371. if value, ok := cau.mutation.CallbackURL(); ok {
  372. _spec.SetField(compapiasynctask.FieldCallbackURL, field.TypeString, value)
  373. }
  374. if value, ok := cau.mutation.CallbackResponseRaw(); ok {
  375. _spec.SetField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString, value)
  376. }
  377. if cau.mutation.CallbackResponseRawCleared() {
  378. _spec.ClearField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString)
  379. }
  380. if value, ok := cau.mutation.Model(); ok {
  381. _spec.SetField(compapiasynctask.FieldModel, field.TypeString, value)
  382. }
  383. if cau.mutation.ModelCleared() {
  384. _spec.ClearField(compapiasynctask.FieldModel, field.TypeString)
  385. }
  386. if value, ok := cau.mutation.TaskStatus(); ok {
  387. _spec.SetField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
  388. }
  389. if value, ok := cau.mutation.AddedTaskStatus(); ok {
  390. _spec.AddField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
  391. }
  392. if cau.mutation.TaskStatusCleared() {
  393. _spec.ClearField(compapiasynctask.FieldTaskStatus, field.TypeInt8)
  394. }
  395. if value, ok := cau.mutation.RetryCount(); ok {
  396. _spec.SetField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
  397. }
  398. if value, ok := cau.mutation.AddedRetryCount(); ok {
  399. _spec.AddField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
  400. }
  401. if cau.mutation.RetryCountCleared() {
  402. _spec.ClearField(compapiasynctask.FieldRetryCount, field.TypeInt8)
  403. }
  404. if value, ok := cau.mutation.LastError(); ok {
  405. _spec.SetField(compapiasynctask.FieldLastError, field.TypeString, value)
  406. }
  407. if cau.mutation.LastErrorCleared() {
  408. _spec.ClearField(compapiasynctask.FieldLastError, field.TypeString)
  409. }
  410. if n, err = sqlgraph.UpdateNodes(ctx, cau.driver, _spec); err != nil {
  411. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  412. err = &NotFoundError{compapiasynctask.Label}
  413. } else if sqlgraph.IsConstraintError(err) {
  414. err = &ConstraintError{msg: err.Error(), wrap: err}
  415. }
  416. return 0, err
  417. }
  418. cau.mutation.done = true
  419. return n, nil
  420. }
  421. // CompapiAsynctaskUpdateOne is the builder for updating a single CompapiAsynctask entity.
  422. type CompapiAsynctaskUpdateOne struct {
  423. config
  424. fields []string
  425. hooks []Hook
  426. mutation *CompapiAsynctaskMutation
  427. }
  428. // SetUpdatedAt sets the "updated_at" field.
  429. func (cauo *CompapiAsynctaskUpdateOne) SetUpdatedAt(t time.Time) *CompapiAsynctaskUpdateOne {
  430. cauo.mutation.SetUpdatedAt(t)
  431. return cauo
  432. }
  433. // SetAuthToken sets the "auth_token" field.
  434. func (cauo *CompapiAsynctaskUpdateOne) SetAuthToken(s string) *CompapiAsynctaskUpdateOne {
  435. cauo.mutation.SetAuthToken(s)
  436. return cauo
  437. }
  438. // SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
  439. func (cauo *CompapiAsynctaskUpdateOne) SetNillableAuthToken(s *string) *CompapiAsynctaskUpdateOne {
  440. if s != nil {
  441. cauo.SetAuthToken(*s)
  442. }
  443. return cauo
  444. }
  445. // SetEventType sets the "event_type" field.
  446. func (cauo *CompapiAsynctaskUpdateOne) SetEventType(s string) *CompapiAsynctaskUpdateOne {
  447. cauo.mutation.SetEventType(s)
  448. return cauo
  449. }
  450. // SetNillableEventType sets the "event_type" field if the given value is not nil.
  451. func (cauo *CompapiAsynctaskUpdateOne) SetNillableEventType(s *string) *CompapiAsynctaskUpdateOne {
  452. if s != nil {
  453. cauo.SetEventType(*s)
  454. }
  455. return cauo
  456. }
  457. // SetChatID sets the "chat_id" field.
  458. func (cauo *CompapiAsynctaskUpdateOne) SetChatID(s string) *CompapiAsynctaskUpdateOne {
  459. cauo.mutation.SetChatID(s)
  460. return cauo
  461. }
  462. // SetNillableChatID sets the "chat_id" field if the given value is not nil.
  463. func (cauo *CompapiAsynctaskUpdateOne) SetNillableChatID(s *string) *CompapiAsynctaskUpdateOne {
  464. if s != nil {
  465. cauo.SetChatID(*s)
  466. }
  467. return cauo
  468. }
  469. // ClearChatID clears the value of the "chat_id" field.
  470. func (cauo *CompapiAsynctaskUpdateOne) ClearChatID() *CompapiAsynctaskUpdateOne {
  471. cauo.mutation.ClearChatID()
  472. return cauo
  473. }
  474. // SetResponseChatItemID sets the "response_chat_item_id" field.
  475. func (cauo *CompapiAsynctaskUpdateOne) SetResponseChatItemID(s string) *CompapiAsynctaskUpdateOne {
  476. cauo.mutation.SetResponseChatItemID(s)
  477. return cauo
  478. }
  479. // SetNillableResponseChatItemID sets the "response_chat_item_id" field if the given value is not nil.
  480. func (cauo *CompapiAsynctaskUpdateOne) SetNillableResponseChatItemID(s *string) *CompapiAsynctaskUpdateOne {
  481. if s != nil {
  482. cauo.SetResponseChatItemID(*s)
  483. }
  484. return cauo
  485. }
  486. // ClearResponseChatItemID clears the value of the "response_chat_item_id" field.
  487. func (cauo *CompapiAsynctaskUpdateOne) ClearResponseChatItemID() *CompapiAsynctaskUpdateOne {
  488. cauo.mutation.ClearResponseChatItemID()
  489. return cauo
  490. }
  491. // SetOrganizationID sets the "organization_id" field.
  492. func (cauo *CompapiAsynctaskUpdateOne) SetOrganizationID(u uint64) *CompapiAsynctaskUpdateOne {
  493. cauo.mutation.ResetOrganizationID()
  494. cauo.mutation.SetOrganizationID(u)
  495. return cauo
  496. }
  497. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  498. func (cauo *CompapiAsynctaskUpdateOne) SetNillableOrganizationID(u *uint64) *CompapiAsynctaskUpdateOne {
  499. if u != nil {
  500. cauo.SetOrganizationID(*u)
  501. }
  502. return cauo
  503. }
  504. // AddOrganizationID adds u to the "organization_id" field.
  505. func (cauo *CompapiAsynctaskUpdateOne) AddOrganizationID(u int64) *CompapiAsynctaskUpdateOne {
  506. cauo.mutation.AddOrganizationID(u)
  507. return cauo
  508. }
  509. // SetOpenaiBase sets the "openai_base" field.
  510. func (cauo *CompapiAsynctaskUpdateOne) SetOpenaiBase(s string) *CompapiAsynctaskUpdateOne {
  511. cauo.mutation.SetOpenaiBase(s)
  512. return cauo
  513. }
  514. // SetNillableOpenaiBase sets the "openai_base" field if the given value is not nil.
  515. func (cauo *CompapiAsynctaskUpdateOne) SetNillableOpenaiBase(s *string) *CompapiAsynctaskUpdateOne {
  516. if s != nil {
  517. cauo.SetOpenaiBase(*s)
  518. }
  519. return cauo
  520. }
  521. // SetOpenaiKey sets the "openai_key" field.
  522. func (cauo *CompapiAsynctaskUpdateOne) SetOpenaiKey(s string) *CompapiAsynctaskUpdateOne {
  523. cauo.mutation.SetOpenaiKey(s)
  524. return cauo
  525. }
  526. // SetNillableOpenaiKey sets the "openai_key" field if the given value is not nil.
  527. func (cauo *CompapiAsynctaskUpdateOne) SetNillableOpenaiKey(s *string) *CompapiAsynctaskUpdateOne {
  528. if s != nil {
  529. cauo.SetOpenaiKey(*s)
  530. }
  531. return cauo
  532. }
  533. // SetRequestRaw sets the "request_raw" field.
  534. func (cauo *CompapiAsynctaskUpdateOne) SetRequestRaw(s string) *CompapiAsynctaskUpdateOne {
  535. cauo.mutation.SetRequestRaw(s)
  536. return cauo
  537. }
  538. // SetNillableRequestRaw sets the "request_raw" field if the given value is not nil.
  539. func (cauo *CompapiAsynctaskUpdateOne) SetNillableRequestRaw(s *string) *CompapiAsynctaskUpdateOne {
  540. if s != nil {
  541. cauo.SetRequestRaw(*s)
  542. }
  543. return cauo
  544. }
  545. // SetResponseRaw sets the "response_raw" field.
  546. func (cauo *CompapiAsynctaskUpdateOne) SetResponseRaw(s string) *CompapiAsynctaskUpdateOne {
  547. cauo.mutation.SetResponseRaw(s)
  548. return cauo
  549. }
  550. // SetNillableResponseRaw sets the "response_raw" field if the given value is not nil.
  551. func (cauo *CompapiAsynctaskUpdateOne) SetNillableResponseRaw(s *string) *CompapiAsynctaskUpdateOne {
  552. if s != nil {
  553. cauo.SetResponseRaw(*s)
  554. }
  555. return cauo
  556. }
  557. // ClearResponseRaw clears the value of the "response_raw" field.
  558. func (cauo *CompapiAsynctaskUpdateOne) ClearResponseRaw() *CompapiAsynctaskUpdateOne {
  559. cauo.mutation.ClearResponseRaw()
  560. return cauo
  561. }
  562. // SetCallbackURL sets the "callback_url" field.
  563. func (cauo *CompapiAsynctaskUpdateOne) SetCallbackURL(s string) *CompapiAsynctaskUpdateOne {
  564. cauo.mutation.SetCallbackURL(s)
  565. return cauo
  566. }
  567. // SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
  568. func (cauo *CompapiAsynctaskUpdateOne) SetNillableCallbackURL(s *string) *CompapiAsynctaskUpdateOne {
  569. if s != nil {
  570. cauo.SetCallbackURL(*s)
  571. }
  572. return cauo
  573. }
  574. // SetCallbackResponseRaw sets the "callback_response_raw" field.
  575. func (cauo *CompapiAsynctaskUpdateOne) SetCallbackResponseRaw(s string) *CompapiAsynctaskUpdateOne {
  576. cauo.mutation.SetCallbackResponseRaw(s)
  577. return cauo
  578. }
  579. // SetNillableCallbackResponseRaw sets the "callback_response_raw" field if the given value is not nil.
  580. func (cauo *CompapiAsynctaskUpdateOne) SetNillableCallbackResponseRaw(s *string) *CompapiAsynctaskUpdateOne {
  581. if s != nil {
  582. cauo.SetCallbackResponseRaw(*s)
  583. }
  584. return cauo
  585. }
  586. // ClearCallbackResponseRaw clears the value of the "callback_response_raw" field.
  587. func (cauo *CompapiAsynctaskUpdateOne) ClearCallbackResponseRaw() *CompapiAsynctaskUpdateOne {
  588. cauo.mutation.ClearCallbackResponseRaw()
  589. return cauo
  590. }
  591. // SetModel sets the "model" field.
  592. func (cauo *CompapiAsynctaskUpdateOne) SetModel(s string) *CompapiAsynctaskUpdateOne {
  593. cauo.mutation.SetModel(s)
  594. return cauo
  595. }
  596. // SetNillableModel sets the "model" field if the given value is not nil.
  597. func (cauo *CompapiAsynctaskUpdateOne) SetNillableModel(s *string) *CompapiAsynctaskUpdateOne {
  598. if s != nil {
  599. cauo.SetModel(*s)
  600. }
  601. return cauo
  602. }
  603. // ClearModel clears the value of the "model" field.
  604. func (cauo *CompapiAsynctaskUpdateOne) ClearModel() *CompapiAsynctaskUpdateOne {
  605. cauo.mutation.ClearModel()
  606. return cauo
  607. }
  608. // SetTaskStatus sets the "task_status" field.
  609. func (cauo *CompapiAsynctaskUpdateOne) SetTaskStatus(i int8) *CompapiAsynctaskUpdateOne {
  610. cauo.mutation.ResetTaskStatus()
  611. cauo.mutation.SetTaskStatus(i)
  612. return cauo
  613. }
  614. // SetNillableTaskStatus sets the "task_status" field if the given value is not nil.
  615. func (cauo *CompapiAsynctaskUpdateOne) SetNillableTaskStatus(i *int8) *CompapiAsynctaskUpdateOne {
  616. if i != nil {
  617. cauo.SetTaskStatus(*i)
  618. }
  619. return cauo
  620. }
  621. // AddTaskStatus adds i to the "task_status" field.
  622. func (cauo *CompapiAsynctaskUpdateOne) AddTaskStatus(i int8) *CompapiAsynctaskUpdateOne {
  623. cauo.mutation.AddTaskStatus(i)
  624. return cauo
  625. }
  626. // ClearTaskStatus clears the value of the "task_status" field.
  627. func (cauo *CompapiAsynctaskUpdateOne) ClearTaskStatus() *CompapiAsynctaskUpdateOne {
  628. cauo.mutation.ClearTaskStatus()
  629. return cauo
  630. }
  631. // SetRetryCount sets the "retry_count" field.
  632. func (cauo *CompapiAsynctaskUpdateOne) SetRetryCount(i int8) *CompapiAsynctaskUpdateOne {
  633. cauo.mutation.ResetRetryCount()
  634. cauo.mutation.SetRetryCount(i)
  635. return cauo
  636. }
  637. // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
  638. func (cauo *CompapiAsynctaskUpdateOne) SetNillableRetryCount(i *int8) *CompapiAsynctaskUpdateOne {
  639. if i != nil {
  640. cauo.SetRetryCount(*i)
  641. }
  642. return cauo
  643. }
  644. // AddRetryCount adds i to the "retry_count" field.
  645. func (cauo *CompapiAsynctaskUpdateOne) AddRetryCount(i int8) *CompapiAsynctaskUpdateOne {
  646. cauo.mutation.AddRetryCount(i)
  647. return cauo
  648. }
  649. // ClearRetryCount clears the value of the "retry_count" field.
  650. func (cauo *CompapiAsynctaskUpdateOne) ClearRetryCount() *CompapiAsynctaskUpdateOne {
  651. cauo.mutation.ClearRetryCount()
  652. return cauo
  653. }
  654. // SetLastError sets the "last_error" field.
  655. func (cauo *CompapiAsynctaskUpdateOne) SetLastError(s string) *CompapiAsynctaskUpdateOne {
  656. cauo.mutation.SetLastError(s)
  657. return cauo
  658. }
  659. // SetNillableLastError sets the "last_error" field if the given value is not nil.
  660. func (cauo *CompapiAsynctaskUpdateOne) SetNillableLastError(s *string) *CompapiAsynctaskUpdateOne {
  661. if s != nil {
  662. cauo.SetLastError(*s)
  663. }
  664. return cauo
  665. }
  666. // ClearLastError clears the value of the "last_error" field.
  667. func (cauo *CompapiAsynctaskUpdateOne) ClearLastError() *CompapiAsynctaskUpdateOne {
  668. cauo.mutation.ClearLastError()
  669. return cauo
  670. }
  671. // Mutation returns the CompapiAsynctaskMutation object of the builder.
  672. func (cauo *CompapiAsynctaskUpdateOne) Mutation() *CompapiAsynctaskMutation {
  673. return cauo.mutation
  674. }
  675. // Where appends a list predicates to the CompapiAsynctaskUpdate builder.
  676. func (cauo *CompapiAsynctaskUpdateOne) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskUpdateOne {
  677. cauo.mutation.Where(ps...)
  678. return cauo
  679. }
  680. // Select allows selecting one or more fields (columns) of the returned entity.
  681. // The default is selecting all fields defined in the entity schema.
  682. func (cauo *CompapiAsynctaskUpdateOne) Select(field string, fields ...string) *CompapiAsynctaskUpdateOne {
  683. cauo.fields = append([]string{field}, fields...)
  684. return cauo
  685. }
  686. // Save executes the query and returns the updated CompapiAsynctask entity.
  687. func (cauo *CompapiAsynctaskUpdateOne) Save(ctx context.Context) (*CompapiAsynctask, error) {
  688. cauo.defaults()
  689. return withHooks(ctx, cauo.sqlSave, cauo.mutation, cauo.hooks)
  690. }
  691. // SaveX is like Save, but panics if an error occurs.
  692. func (cauo *CompapiAsynctaskUpdateOne) SaveX(ctx context.Context) *CompapiAsynctask {
  693. node, err := cauo.Save(ctx)
  694. if err != nil {
  695. panic(err)
  696. }
  697. return node
  698. }
  699. // Exec executes the query on the entity.
  700. func (cauo *CompapiAsynctaskUpdateOne) Exec(ctx context.Context) error {
  701. _, err := cauo.Save(ctx)
  702. return err
  703. }
  704. // ExecX is like Exec, but panics if an error occurs.
  705. func (cauo *CompapiAsynctaskUpdateOne) ExecX(ctx context.Context) {
  706. if err := cauo.Exec(ctx); err != nil {
  707. panic(err)
  708. }
  709. }
  710. // defaults sets the default values of the builder before save.
  711. func (cauo *CompapiAsynctaskUpdateOne) defaults() {
  712. if _, ok := cauo.mutation.UpdatedAt(); !ok {
  713. v := compapiasynctask.UpdateDefaultUpdatedAt()
  714. cauo.mutation.SetUpdatedAt(v)
  715. }
  716. }
  717. // check runs all checks and user-defined validators on the builder.
  718. func (cauo *CompapiAsynctaskUpdateOne) check() error {
  719. if v, ok := cauo.mutation.OrganizationID(); ok {
  720. if err := compapiasynctask.OrganizationIDValidator(v); err != nil {
  721. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.organization_id": %w`, err)}
  722. }
  723. }
  724. if v, ok := cauo.mutation.CallbackURL(); ok {
  725. if err := compapiasynctask.CallbackURLValidator(v); err != nil {
  726. return &ValidationError{Name: "callback_url", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.callback_url": %w`, err)}
  727. }
  728. }
  729. return nil
  730. }
  731. func (cauo *CompapiAsynctaskUpdateOne) sqlSave(ctx context.Context) (_node *CompapiAsynctask, err error) {
  732. if err := cauo.check(); err != nil {
  733. return _node, err
  734. }
  735. _spec := sqlgraph.NewUpdateSpec(compapiasynctask.Table, compapiasynctask.Columns, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
  736. id, ok := cauo.mutation.ID()
  737. if !ok {
  738. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CompapiAsynctask.id" for update`)}
  739. }
  740. _spec.Node.ID.Value = id
  741. if fields := cauo.fields; len(fields) > 0 {
  742. _spec.Node.Columns = make([]string, 0, len(fields))
  743. _spec.Node.Columns = append(_spec.Node.Columns, compapiasynctask.FieldID)
  744. for _, f := range fields {
  745. if !compapiasynctask.ValidColumn(f) {
  746. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  747. }
  748. if f != compapiasynctask.FieldID {
  749. _spec.Node.Columns = append(_spec.Node.Columns, f)
  750. }
  751. }
  752. }
  753. if ps := cauo.mutation.predicates; len(ps) > 0 {
  754. _spec.Predicate = func(selector *sql.Selector) {
  755. for i := range ps {
  756. ps[i](selector)
  757. }
  758. }
  759. }
  760. if value, ok := cauo.mutation.UpdatedAt(); ok {
  761. _spec.SetField(compapiasynctask.FieldUpdatedAt, field.TypeTime, value)
  762. }
  763. if value, ok := cauo.mutation.AuthToken(); ok {
  764. _spec.SetField(compapiasynctask.FieldAuthToken, field.TypeString, value)
  765. }
  766. if value, ok := cauo.mutation.EventType(); ok {
  767. _spec.SetField(compapiasynctask.FieldEventType, field.TypeString, value)
  768. }
  769. if value, ok := cauo.mutation.ChatID(); ok {
  770. _spec.SetField(compapiasynctask.FieldChatID, field.TypeString, value)
  771. }
  772. if cauo.mutation.ChatIDCleared() {
  773. _spec.ClearField(compapiasynctask.FieldChatID, field.TypeString)
  774. }
  775. if value, ok := cauo.mutation.ResponseChatItemID(); ok {
  776. _spec.SetField(compapiasynctask.FieldResponseChatItemID, field.TypeString, value)
  777. }
  778. if cauo.mutation.ResponseChatItemIDCleared() {
  779. _spec.ClearField(compapiasynctask.FieldResponseChatItemID, field.TypeString)
  780. }
  781. if value, ok := cauo.mutation.OrganizationID(); ok {
  782. _spec.SetField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
  783. }
  784. if value, ok := cauo.mutation.AddedOrganizationID(); ok {
  785. _spec.AddField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
  786. }
  787. if value, ok := cauo.mutation.OpenaiBase(); ok {
  788. _spec.SetField(compapiasynctask.FieldOpenaiBase, field.TypeString, value)
  789. }
  790. if value, ok := cauo.mutation.OpenaiKey(); ok {
  791. _spec.SetField(compapiasynctask.FieldOpenaiKey, field.TypeString, value)
  792. }
  793. if value, ok := cauo.mutation.RequestRaw(); ok {
  794. _spec.SetField(compapiasynctask.FieldRequestRaw, field.TypeString, value)
  795. }
  796. if value, ok := cauo.mutation.ResponseRaw(); ok {
  797. _spec.SetField(compapiasynctask.FieldResponseRaw, field.TypeString, value)
  798. }
  799. if cauo.mutation.ResponseRawCleared() {
  800. _spec.ClearField(compapiasynctask.FieldResponseRaw, field.TypeString)
  801. }
  802. if value, ok := cauo.mutation.CallbackURL(); ok {
  803. _spec.SetField(compapiasynctask.FieldCallbackURL, field.TypeString, value)
  804. }
  805. if value, ok := cauo.mutation.CallbackResponseRaw(); ok {
  806. _spec.SetField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString, value)
  807. }
  808. if cauo.mutation.CallbackResponseRawCleared() {
  809. _spec.ClearField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString)
  810. }
  811. if value, ok := cauo.mutation.Model(); ok {
  812. _spec.SetField(compapiasynctask.FieldModel, field.TypeString, value)
  813. }
  814. if cauo.mutation.ModelCleared() {
  815. _spec.ClearField(compapiasynctask.FieldModel, field.TypeString)
  816. }
  817. if value, ok := cauo.mutation.TaskStatus(); ok {
  818. _spec.SetField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
  819. }
  820. if value, ok := cauo.mutation.AddedTaskStatus(); ok {
  821. _spec.AddField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
  822. }
  823. if cauo.mutation.TaskStatusCleared() {
  824. _spec.ClearField(compapiasynctask.FieldTaskStatus, field.TypeInt8)
  825. }
  826. if value, ok := cauo.mutation.RetryCount(); ok {
  827. _spec.SetField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
  828. }
  829. if value, ok := cauo.mutation.AddedRetryCount(); ok {
  830. _spec.AddField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
  831. }
  832. if cauo.mutation.RetryCountCleared() {
  833. _spec.ClearField(compapiasynctask.FieldRetryCount, field.TypeInt8)
  834. }
  835. if value, ok := cauo.mutation.LastError(); ok {
  836. _spec.SetField(compapiasynctask.FieldLastError, field.TypeString, value)
  837. }
  838. if cauo.mutation.LastErrorCleared() {
  839. _spec.ClearField(compapiasynctask.FieldLastError, field.TypeString)
  840. }
  841. _node = &CompapiAsynctask{config: cauo.config}
  842. _spec.Assign = _node.assignValues
  843. _spec.ScanValues = _node.scanValues
  844. if err = sqlgraph.UpdateNode(ctx, cauo.driver, _spec); err != nil {
  845. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  846. err = &NotFoundError{compapiasynctask.Label}
  847. } else if sqlgraph.IsConstraintError(err) {
  848. err = &ConstraintError{msg: err.Error(), wrap: err}
  849. }
  850. return nil, err
  851. }
  852. cauo.mutation.done = true
  853. return _node, nil
  854. }