compapiasynctask_update.go 29 KB

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