compapiasynctask_create.go 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  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. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // CompapiAsynctaskCreate is the builder for creating a CompapiAsynctask entity.
  14. type CompapiAsynctaskCreate struct {
  15. config
  16. mutation *CompapiAsynctaskMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (cac *CompapiAsynctaskCreate) SetCreatedAt(t time.Time) *CompapiAsynctaskCreate {
  22. cac.mutation.SetCreatedAt(t)
  23. return cac
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (cac *CompapiAsynctaskCreate) SetNillableCreatedAt(t *time.Time) *CompapiAsynctaskCreate {
  27. if t != nil {
  28. cac.SetCreatedAt(*t)
  29. }
  30. return cac
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (cac *CompapiAsynctaskCreate) SetUpdatedAt(t time.Time) *CompapiAsynctaskCreate {
  34. cac.mutation.SetUpdatedAt(t)
  35. return cac
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (cac *CompapiAsynctaskCreate) SetNillableUpdatedAt(t *time.Time) *CompapiAsynctaskCreate {
  39. if t != nil {
  40. cac.SetUpdatedAt(*t)
  41. }
  42. return cac
  43. }
  44. // SetAuthToken sets the "auth_token" field.
  45. func (cac *CompapiAsynctaskCreate) SetAuthToken(s string) *CompapiAsynctaskCreate {
  46. cac.mutation.SetAuthToken(s)
  47. return cac
  48. }
  49. // SetEventType sets the "event_type" field.
  50. func (cac *CompapiAsynctaskCreate) SetEventType(s string) *CompapiAsynctaskCreate {
  51. cac.mutation.SetEventType(s)
  52. return cac
  53. }
  54. // SetNillableEventType sets the "event_type" field if the given value is not nil.
  55. func (cac *CompapiAsynctaskCreate) SetNillableEventType(s *string) *CompapiAsynctaskCreate {
  56. if s != nil {
  57. cac.SetEventType(*s)
  58. }
  59. return cac
  60. }
  61. // SetChatID sets the "chat_id" field.
  62. func (cac *CompapiAsynctaskCreate) SetChatID(s string) *CompapiAsynctaskCreate {
  63. cac.mutation.SetChatID(s)
  64. return cac
  65. }
  66. // SetNillableChatID sets the "chat_id" field if the given value is not nil.
  67. func (cac *CompapiAsynctaskCreate) SetNillableChatID(s *string) *CompapiAsynctaskCreate {
  68. if s != nil {
  69. cac.SetChatID(*s)
  70. }
  71. return cac
  72. }
  73. // SetWorkidIdx sets the "workid_idx" field.
  74. func (cac *CompapiAsynctaskCreate) SetWorkidIdx(i int8) *CompapiAsynctaskCreate {
  75. cac.mutation.SetWorkidIdx(i)
  76. return cac
  77. }
  78. // SetNillableWorkidIdx sets the "workid_idx" field if the given value is not nil.
  79. func (cac *CompapiAsynctaskCreate) SetNillableWorkidIdx(i *int8) *CompapiAsynctaskCreate {
  80. if i != nil {
  81. cac.SetWorkidIdx(*i)
  82. }
  83. return cac
  84. }
  85. // SetOpenaiBase sets the "openai_base" field.
  86. func (cac *CompapiAsynctaskCreate) SetOpenaiBase(s string) *CompapiAsynctaskCreate {
  87. cac.mutation.SetOpenaiBase(s)
  88. return cac
  89. }
  90. // SetOpenaiKey sets the "openai_key" field.
  91. func (cac *CompapiAsynctaskCreate) SetOpenaiKey(s string) *CompapiAsynctaskCreate {
  92. cac.mutation.SetOpenaiKey(s)
  93. return cac
  94. }
  95. // SetRequestRaw sets the "request_raw" field.
  96. func (cac *CompapiAsynctaskCreate) SetRequestRaw(s string) *CompapiAsynctaskCreate {
  97. cac.mutation.SetRequestRaw(s)
  98. return cac
  99. }
  100. // SetResponseRaw sets the "response_raw" field.
  101. func (cac *CompapiAsynctaskCreate) SetResponseRaw(s string) *CompapiAsynctaskCreate {
  102. cac.mutation.SetResponseRaw(s)
  103. return cac
  104. }
  105. // SetNillableResponseRaw sets the "response_raw" field if the given value is not nil.
  106. func (cac *CompapiAsynctaskCreate) SetNillableResponseRaw(s *string) *CompapiAsynctaskCreate {
  107. if s != nil {
  108. cac.SetResponseRaw(*s)
  109. }
  110. return cac
  111. }
  112. // SetCallbackURL sets the "callback_url" field.
  113. func (cac *CompapiAsynctaskCreate) SetCallbackURL(s string) *CompapiAsynctaskCreate {
  114. cac.mutation.SetCallbackURL(s)
  115. return cac
  116. }
  117. // SetTaskStatus sets the "task_status" field.
  118. func (cac *CompapiAsynctaskCreate) SetTaskStatus(i int8) *CompapiAsynctaskCreate {
  119. cac.mutation.SetTaskStatus(i)
  120. return cac
  121. }
  122. // SetNillableTaskStatus sets the "task_status" field if the given value is not nil.
  123. func (cac *CompapiAsynctaskCreate) SetNillableTaskStatus(i *int8) *CompapiAsynctaskCreate {
  124. if i != nil {
  125. cac.SetTaskStatus(*i)
  126. }
  127. return cac
  128. }
  129. // SetRetryCount sets the "retry_count" field.
  130. func (cac *CompapiAsynctaskCreate) SetRetryCount(i int8) *CompapiAsynctaskCreate {
  131. cac.mutation.SetRetryCount(i)
  132. return cac
  133. }
  134. // SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
  135. func (cac *CompapiAsynctaskCreate) SetNillableRetryCount(i *int8) *CompapiAsynctaskCreate {
  136. if i != nil {
  137. cac.SetRetryCount(*i)
  138. }
  139. return cac
  140. }
  141. // SetLastError sets the "last_error" field.
  142. func (cac *CompapiAsynctaskCreate) SetLastError(s string) *CompapiAsynctaskCreate {
  143. cac.mutation.SetLastError(s)
  144. return cac
  145. }
  146. // SetNillableLastError sets the "last_error" field if the given value is not nil.
  147. func (cac *CompapiAsynctaskCreate) SetNillableLastError(s *string) *CompapiAsynctaskCreate {
  148. if s != nil {
  149. cac.SetLastError(*s)
  150. }
  151. return cac
  152. }
  153. // SetID sets the "id" field.
  154. func (cac *CompapiAsynctaskCreate) SetID(u uint64) *CompapiAsynctaskCreate {
  155. cac.mutation.SetID(u)
  156. return cac
  157. }
  158. // Mutation returns the CompapiAsynctaskMutation object of the builder.
  159. func (cac *CompapiAsynctaskCreate) Mutation() *CompapiAsynctaskMutation {
  160. return cac.mutation
  161. }
  162. // Save creates the CompapiAsynctask in the database.
  163. func (cac *CompapiAsynctaskCreate) Save(ctx context.Context) (*CompapiAsynctask, error) {
  164. cac.defaults()
  165. return withHooks(ctx, cac.sqlSave, cac.mutation, cac.hooks)
  166. }
  167. // SaveX calls Save and panics if Save returns an error.
  168. func (cac *CompapiAsynctaskCreate) SaveX(ctx context.Context) *CompapiAsynctask {
  169. v, err := cac.Save(ctx)
  170. if err != nil {
  171. panic(err)
  172. }
  173. return v
  174. }
  175. // Exec executes the query.
  176. func (cac *CompapiAsynctaskCreate) Exec(ctx context.Context) error {
  177. _, err := cac.Save(ctx)
  178. return err
  179. }
  180. // ExecX is like Exec, but panics if an error occurs.
  181. func (cac *CompapiAsynctaskCreate) ExecX(ctx context.Context) {
  182. if err := cac.Exec(ctx); err != nil {
  183. panic(err)
  184. }
  185. }
  186. // defaults sets the default values of the builder before save.
  187. func (cac *CompapiAsynctaskCreate) defaults() {
  188. if _, ok := cac.mutation.CreatedAt(); !ok {
  189. v := compapiasynctask.DefaultCreatedAt()
  190. cac.mutation.SetCreatedAt(v)
  191. }
  192. if _, ok := cac.mutation.UpdatedAt(); !ok {
  193. v := compapiasynctask.DefaultUpdatedAt()
  194. cac.mutation.SetUpdatedAt(v)
  195. }
  196. if _, ok := cac.mutation.EventType(); !ok {
  197. v := compapiasynctask.DefaultEventType
  198. cac.mutation.SetEventType(v)
  199. }
  200. if _, ok := cac.mutation.ChatID(); !ok {
  201. v := compapiasynctask.DefaultChatID
  202. cac.mutation.SetChatID(v)
  203. }
  204. if _, ok := cac.mutation.WorkidIdx(); !ok {
  205. v := compapiasynctask.DefaultWorkidIdx
  206. cac.mutation.SetWorkidIdx(v)
  207. }
  208. if _, ok := cac.mutation.ResponseRaw(); !ok {
  209. v := compapiasynctask.DefaultResponseRaw
  210. cac.mutation.SetResponseRaw(v)
  211. }
  212. if _, ok := cac.mutation.TaskStatus(); !ok {
  213. v := compapiasynctask.DefaultTaskStatus
  214. cac.mutation.SetTaskStatus(v)
  215. }
  216. if _, ok := cac.mutation.RetryCount(); !ok {
  217. v := compapiasynctask.DefaultRetryCount
  218. cac.mutation.SetRetryCount(v)
  219. }
  220. if _, ok := cac.mutation.LastError(); !ok {
  221. v := compapiasynctask.DefaultLastError
  222. cac.mutation.SetLastError(v)
  223. }
  224. }
  225. // check runs all checks and user-defined validators on the builder.
  226. func (cac *CompapiAsynctaskCreate) check() error {
  227. if _, ok := cac.mutation.CreatedAt(); !ok {
  228. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "CompapiAsynctask.created_at"`)}
  229. }
  230. if _, ok := cac.mutation.UpdatedAt(); !ok {
  231. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "CompapiAsynctask.updated_at"`)}
  232. }
  233. if _, ok := cac.mutation.AuthToken(); !ok {
  234. return &ValidationError{Name: "auth_token", err: errors.New(`ent: missing required field "CompapiAsynctask.auth_token"`)}
  235. }
  236. if _, ok := cac.mutation.EventType(); !ok {
  237. return &ValidationError{Name: "event_type", err: errors.New(`ent: missing required field "CompapiAsynctask.event_type"`)}
  238. }
  239. if _, ok := cac.mutation.OpenaiBase(); !ok {
  240. return &ValidationError{Name: "openai_base", err: errors.New(`ent: missing required field "CompapiAsynctask.openai_base"`)}
  241. }
  242. if _, ok := cac.mutation.OpenaiKey(); !ok {
  243. return &ValidationError{Name: "openai_key", err: errors.New(`ent: missing required field "CompapiAsynctask.openai_key"`)}
  244. }
  245. if _, ok := cac.mutation.RequestRaw(); !ok {
  246. return &ValidationError{Name: "request_raw", err: errors.New(`ent: missing required field "CompapiAsynctask.request_raw"`)}
  247. }
  248. if _, ok := cac.mutation.CallbackURL(); !ok {
  249. return &ValidationError{Name: "callback_url", err: errors.New(`ent: missing required field "CompapiAsynctask.callback_url"`)}
  250. }
  251. if v, ok := cac.mutation.CallbackURL(); ok {
  252. if err := compapiasynctask.CallbackURLValidator(v); err != nil {
  253. return &ValidationError{Name: "callback_url", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.callback_url": %w`, err)}
  254. }
  255. }
  256. return nil
  257. }
  258. func (cac *CompapiAsynctaskCreate) sqlSave(ctx context.Context) (*CompapiAsynctask, error) {
  259. if err := cac.check(); err != nil {
  260. return nil, err
  261. }
  262. _node, _spec := cac.createSpec()
  263. if err := sqlgraph.CreateNode(ctx, cac.driver, _spec); err != nil {
  264. if sqlgraph.IsConstraintError(err) {
  265. err = &ConstraintError{msg: err.Error(), wrap: err}
  266. }
  267. return nil, err
  268. }
  269. if _spec.ID.Value != _node.ID {
  270. id := _spec.ID.Value.(int64)
  271. _node.ID = uint64(id)
  272. }
  273. cac.mutation.id = &_node.ID
  274. cac.mutation.done = true
  275. return _node, nil
  276. }
  277. func (cac *CompapiAsynctaskCreate) createSpec() (*CompapiAsynctask, *sqlgraph.CreateSpec) {
  278. var (
  279. _node = &CompapiAsynctask{config: cac.config}
  280. _spec = sqlgraph.NewCreateSpec(compapiasynctask.Table, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
  281. )
  282. _spec.OnConflict = cac.conflict
  283. if id, ok := cac.mutation.ID(); ok {
  284. _node.ID = id
  285. _spec.ID.Value = id
  286. }
  287. if value, ok := cac.mutation.CreatedAt(); ok {
  288. _spec.SetField(compapiasynctask.FieldCreatedAt, field.TypeTime, value)
  289. _node.CreatedAt = value
  290. }
  291. if value, ok := cac.mutation.UpdatedAt(); ok {
  292. _spec.SetField(compapiasynctask.FieldUpdatedAt, field.TypeTime, value)
  293. _node.UpdatedAt = value
  294. }
  295. if value, ok := cac.mutation.AuthToken(); ok {
  296. _spec.SetField(compapiasynctask.FieldAuthToken, field.TypeString, value)
  297. _node.AuthToken = value
  298. }
  299. if value, ok := cac.mutation.EventType(); ok {
  300. _spec.SetField(compapiasynctask.FieldEventType, field.TypeString, value)
  301. _node.EventType = value
  302. }
  303. if value, ok := cac.mutation.ChatID(); ok {
  304. _spec.SetField(compapiasynctask.FieldChatID, field.TypeString, value)
  305. _node.ChatID = value
  306. }
  307. if value, ok := cac.mutation.WorkidIdx(); ok {
  308. _spec.SetField(compapiasynctask.FieldWorkidIdx, field.TypeInt8, value)
  309. _node.WorkidIdx = value
  310. }
  311. if value, ok := cac.mutation.OpenaiBase(); ok {
  312. _spec.SetField(compapiasynctask.FieldOpenaiBase, field.TypeString, value)
  313. _node.OpenaiBase = value
  314. }
  315. if value, ok := cac.mutation.OpenaiKey(); ok {
  316. _spec.SetField(compapiasynctask.FieldOpenaiKey, field.TypeString, value)
  317. _node.OpenaiKey = value
  318. }
  319. if value, ok := cac.mutation.RequestRaw(); ok {
  320. _spec.SetField(compapiasynctask.FieldRequestRaw, field.TypeString, value)
  321. _node.RequestRaw = value
  322. }
  323. if value, ok := cac.mutation.ResponseRaw(); ok {
  324. _spec.SetField(compapiasynctask.FieldResponseRaw, field.TypeString, value)
  325. _node.ResponseRaw = value
  326. }
  327. if value, ok := cac.mutation.CallbackURL(); ok {
  328. _spec.SetField(compapiasynctask.FieldCallbackURL, field.TypeString, value)
  329. _node.CallbackURL = value
  330. }
  331. if value, ok := cac.mutation.TaskStatus(); ok {
  332. _spec.SetField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
  333. _node.TaskStatus = value
  334. }
  335. if value, ok := cac.mutation.RetryCount(); ok {
  336. _spec.SetField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
  337. _node.RetryCount = value
  338. }
  339. if value, ok := cac.mutation.LastError(); ok {
  340. _spec.SetField(compapiasynctask.FieldLastError, field.TypeString, value)
  341. _node.LastError = value
  342. }
  343. return _node, _spec
  344. }
  345. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  346. // of the `INSERT` statement. For example:
  347. //
  348. // client.CompapiAsynctask.Create().
  349. // SetCreatedAt(v).
  350. // OnConflict(
  351. // // Update the row with the new values
  352. // // the was proposed for insertion.
  353. // sql.ResolveWithNewValues(),
  354. // ).
  355. // // Override some of the fields with custom
  356. // // update values.
  357. // Update(func(u *ent.CompapiAsynctaskUpsert) {
  358. // SetCreatedAt(v+v).
  359. // }).
  360. // Exec(ctx)
  361. func (cac *CompapiAsynctaskCreate) OnConflict(opts ...sql.ConflictOption) *CompapiAsynctaskUpsertOne {
  362. cac.conflict = opts
  363. return &CompapiAsynctaskUpsertOne{
  364. create: cac,
  365. }
  366. }
  367. // OnConflictColumns calls `OnConflict` and configures the columns
  368. // as conflict target. Using this option is equivalent to using:
  369. //
  370. // client.CompapiAsynctask.Create().
  371. // OnConflict(sql.ConflictColumns(columns...)).
  372. // Exec(ctx)
  373. func (cac *CompapiAsynctaskCreate) OnConflictColumns(columns ...string) *CompapiAsynctaskUpsertOne {
  374. cac.conflict = append(cac.conflict, sql.ConflictColumns(columns...))
  375. return &CompapiAsynctaskUpsertOne{
  376. create: cac,
  377. }
  378. }
  379. type (
  380. // CompapiAsynctaskUpsertOne is the builder for "upsert"-ing
  381. // one CompapiAsynctask node.
  382. CompapiAsynctaskUpsertOne struct {
  383. create *CompapiAsynctaskCreate
  384. }
  385. // CompapiAsynctaskUpsert is the "OnConflict" setter.
  386. CompapiAsynctaskUpsert struct {
  387. *sql.UpdateSet
  388. }
  389. )
  390. // SetUpdatedAt sets the "updated_at" field.
  391. func (u *CompapiAsynctaskUpsert) SetUpdatedAt(v time.Time) *CompapiAsynctaskUpsert {
  392. u.Set(compapiasynctask.FieldUpdatedAt, v)
  393. return u
  394. }
  395. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  396. func (u *CompapiAsynctaskUpsert) UpdateUpdatedAt() *CompapiAsynctaskUpsert {
  397. u.SetExcluded(compapiasynctask.FieldUpdatedAt)
  398. return u
  399. }
  400. // SetAuthToken sets the "auth_token" field.
  401. func (u *CompapiAsynctaskUpsert) SetAuthToken(v string) *CompapiAsynctaskUpsert {
  402. u.Set(compapiasynctask.FieldAuthToken, v)
  403. return u
  404. }
  405. // UpdateAuthToken sets the "auth_token" field to the value that was provided on create.
  406. func (u *CompapiAsynctaskUpsert) UpdateAuthToken() *CompapiAsynctaskUpsert {
  407. u.SetExcluded(compapiasynctask.FieldAuthToken)
  408. return u
  409. }
  410. // SetEventType sets the "event_type" field.
  411. func (u *CompapiAsynctaskUpsert) SetEventType(v string) *CompapiAsynctaskUpsert {
  412. u.Set(compapiasynctask.FieldEventType, v)
  413. return u
  414. }
  415. // UpdateEventType sets the "event_type" field to the value that was provided on create.
  416. func (u *CompapiAsynctaskUpsert) UpdateEventType() *CompapiAsynctaskUpsert {
  417. u.SetExcluded(compapiasynctask.FieldEventType)
  418. return u
  419. }
  420. // SetChatID sets the "chat_id" field.
  421. func (u *CompapiAsynctaskUpsert) SetChatID(v string) *CompapiAsynctaskUpsert {
  422. u.Set(compapiasynctask.FieldChatID, v)
  423. return u
  424. }
  425. // UpdateChatID sets the "chat_id" field to the value that was provided on create.
  426. func (u *CompapiAsynctaskUpsert) UpdateChatID() *CompapiAsynctaskUpsert {
  427. u.SetExcluded(compapiasynctask.FieldChatID)
  428. return u
  429. }
  430. // ClearChatID clears the value of the "chat_id" field.
  431. func (u *CompapiAsynctaskUpsert) ClearChatID() *CompapiAsynctaskUpsert {
  432. u.SetNull(compapiasynctask.FieldChatID)
  433. return u
  434. }
  435. // SetWorkidIdx sets the "workid_idx" field.
  436. func (u *CompapiAsynctaskUpsert) SetWorkidIdx(v int8) *CompapiAsynctaskUpsert {
  437. u.Set(compapiasynctask.FieldWorkidIdx, v)
  438. return u
  439. }
  440. // UpdateWorkidIdx sets the "workid_idx" field to the value that was provided on create.
  441. func (u *CompapiAsynctaskUpsert) UpdateWorkidIdx() *CompapiAsynctaskUpsert {
  442. u.SetExcluded(compapiasynctask.FieldWorkidIdx)
  443. return u
  444. }
  445. // AddWorkidIdx adds v to the "workid_idx" field.
  446. func (u *CompapiAsynctaskUpsert) AddWorkidIdx(v int8) *CompapiAsynctaskUpsert {
  447. u.Add(compapiasynctask.FieldWorkidIdx, v)
  448. return u
  449. }
  450. // ClearWorkidIdx clears the value of the "workid_idx" field.
  451. func (u *CompapiAsynctaskUpsert) ClearWorkidIdx() *CompapiAsynctaskUpsert {
  452. u.SetNull(compapiasynctask.FieldWorkidIdx)
  453. return u
  454. }
  455. // SetOpenaiBase sets the "openai_base" field.
  456. func (u *CompapiAsynctaskUpsert) SetOpenaiBase(v string) *CompapiAsynctaskUpsert {
  457. u.Set(compapiasynctask.FieldOpenaiBase, v)
  458. return u
  459. }
  460. // UpdateOpenaiBase sets the "openai_base" field to the value that was provided on create.
  461. func (u *CompapiAsynctaskUpsert) UpdateOpenaiBase() *CompapiAsynctaskUpsert {
  462. u.SetExcluded(compapiasynctask.FieldOpenaiBase)
  463. return u
  464. }
  465. // SetOpenaiKey sets the "openai_key" field.
  466. func (u *CompapiAsynctaskUpsert) SetOpenaiKey(v string) *CompapiAsynctaskUpsert {
  467. u.Set(compapiasynctask.FieldOpenaiKey, v)
  468. return u
  469. }
  470. // UpdateOpenaiKey sets the "openai_key" field to the value that was provided on create.
  471. func (u *CompapiAsynctaskUpsert) UpdateOpenaiKey() *CompapiAsynctaskUpsert {
  472. u.SetExcluded(compapiasynctask.FieldOpenaiKey)
  473. return u
  474. }
  475. // SetRequestRaw sets the "request_raw" field.
  476. func (u *CompapiAsynctaskUpsert) SetRequestRaw(v string) *CompapiAsynctaskUpsert {
  477. u.Set(compapiasynctask.FieldRequestRaw, v)
  478. return u
  479. }
  480. // UpdateRequestRaw sets the "request_raw" field to the value that was provided on create.
  481. func (u *CompapiAsynctaskUpsert) UpdateRequestRaw() *CompapiAsynctaskUpsert {
  482. u.SetExcluded(compapiasynctask.FieldRequestRaw)
  483. return u
  484. }
  485. // SetResponseRaw sets the "response_raw" field.
  486. func (u *CompapiAsynctaskUpsert) SetResponseRaw(v string) *CompapiAsynctaskUpsert {
  487. u.Set(compapiasynctask.FieldResponseRaw, v)
  488. return u
  489. }
  490. // UpdateResponseRaw sets the "response_raw" field to the value that was provided on create.
  491. func (u *CompapiAsynctaskUpsert) UpdateResponseRaw() *CompapiAsynctaskUpsert {
  492. u.SetExcluded(compapiasynctask.FieldResponseRaw)
  493. return u
  494. }
  495. // ClearResponseRaw clears the value of the "response_raw" field.
  496. func (u *CompapiAsynctaskUpsert) ClearResponseRaw() *CompapiAsynctaskUpsert {
  497. u.SetNull(compapiasynctask.FieldResponseRaw)
  498. return u
  499. }
  500. // SetCallbackURL sets the "callback_url" field.
  501. func (u *CompapiAsynctaskUpsert) SetCallbackURL(v string) *CompapiAsynctaskUpsert {
  502. u.Set(compapiasynctask.FieldCallbackURL, v)
  503. return u
  504. }
  505. // UpdateCallbackURL sets the "callback_url" field to the value that was provided on create.
  506. func (u *CompapiAsynctaskUpsert) UpdateCallbackURL() *CompapiAsynctaskUpsert {
  507. u.SetExcluded(compapiasynctask.FieldCallbackURL)
  508. return u
  509. }
  510. // SetTaskStatus sets the "task_status" field.
  511. func (u *CompapiAsynctaskUpsert) SetTaskStatus(v int8) *CompapiAsynctaskUpsert {
  512. u.Set(compapiasynctask.FieldTaskStatus, v)
  513. return u
  514. }
  515. // UpdateTaskStatus sets the "task_status" field to the value that was provided on create.
  516. func (u *CompapiAsynctaskUpsert) UpdateTaskStatus() *CompapiAsynctaskUpsert {
  517. u.SetExcluded(compapiasynctask.FieldTaskStatus)
  518. return u
  519. }
  520. // AddTaskStatus adds v to the "task_status" field.
  521. func (u *CompapiAsynctaskUpsert) AddTaskStatus(v int8) *CompapiAsynctaskUpsert {
  522. u.Add(compapiasynctask.FieldTaskStatus, v)
  523. return u
  524. }
  525. // ClearTaskStatus clears the value of the "task_status" field.
  526. func (u *CompapiAsynctaskUpsert) ClearTaskStatus() *CompapiAsynctaskUpsert {
  527. u.SetNull(compapiasynctask.FieldTaskStatus)
  528. return u
  529. }
  530. // SetRetryCount sets the "retry_count" field.
  531. func (u *CompapiAsynctaskUpsert) SetRetryCount(v int8) *CompapiAsynctaskUpsert {
  532. u.Set(compapiasynctask.FieldRetryCount, v)
  533. return u
  534. }
  535. // UpdateRetryCount sets the "retry_count" field to the value that was provided on create.
  536. func (u *CompapiAsynctaskUpsert) UpdateRetryCount() *CompapiAsynctaskUpsert {
  537. u.SetExcluded(compapiasynctask.FieldRetryCount)
  538. return u
  539. }
  540. // AddRetryCount adds v to the "retry_count" field.
  541. func (u *CompapiAsynctaskUpsert) AddRetryCount(v int8) *CompapiAsynctaskUpsert {
  542. u.Add(compapiasynctask.FieldRetryCount, v)
  543. return u
  544. }
  545. // ClearRetryCount clears the value of the "retry_count" field.
  546. func (u *CompapiAsynctaskUpsert) ClearRetryCount() *CompapiAsynctaskUpsert {
  547. u.SetNull(compapiasynctask.FieldRetryCount)
  548. return u
  549. }
  550. // SetLastError sets the "last_error" field.
  551. func (u *CompapiAsynctaskUpsert) SetLastError(v string) *CompapiAsynctaskUpsert {
  552. u.Set(compapiasynctask.FieldLastError, v)
  553. return u
  554. }
  555. // UpdateLastError sets the "last_error" field to the value that was provided on create.
  556. func (u *CompapiAsynctaskUpsert) UpdateLastError() *CompapiAsynctaskUpsert {
  557. u.SetExcluded(compapiasynctask.FieldLastError)
  558. return u
  559. }
  560. // ClearLastError clears the value of the "last_error" field.
  561. func (u *CompapiAsynctaskUpsert) ClearLastError() *CompapiAsynctaskUpsert {
  562. u.SetNull(compapiasynctask.FieldLastError)
  563. return u
  564. }
  565. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  566. // Using this option is equivalent to using:
  567. //
  568. // client.CompapiAsynctask.Create().
  569. // OnConflict(
  570. // sql.ResolveWithNewValues(),
  571. // sql.ResolveWith(func(u *sql.UpdateSet) {
  572. // u.SetIgnore(compapiasynctask.FieldID)
  573. // }),
  574. // ).
  575. // Exec(ctx)
  576. func (u *CompapiAsynctaskUpsertOne) UpdateNewValues() *CompapiAsynctaskUpsertOne {
  577. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  578. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  579. if _, exists := u.create.mutation.ID(); exists {
  580. s.SetIgnore(compapiasynctask.FieldID)
  581. }
  582. if _, exists := u.create.mutation.CreatedAt(); exists {
  583. s.SetIgnore(compapiasynctask.FieldCreatedAt)
  584. }
  585. }))
  586. return u
  587. }
  588. // Ignore sets each column to itself in case of conflict.
  589. // Using this option is equivalent to using:
  590. //
  591. // client.CompapiAsynctask.Create().
  592. // OnConflict(sql.ResolveWithIgnore()).
  593. // Exec(ctx)
  594. func (u *CompapiAsynctaskUpsertOne) Ignore() *CompapiAsynctaskUpsertOne {
  595. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  596. return u
  597. }
  598. // DoNothing configures the conflict_action to `DO NOTHING`.
  599. // Supported only by SQLite and PostgreSQL.
  600. func (u *CompapiAsynctaskUpsertOne) DoNothing() *CompapiAsynctaskUpsertOne {
  601. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  602. return u
  603. }
  604. // Update allows overriding fields `UPDATE` values. See the CompapiAsynctaskCreate.OnConflict
  605. // documentation for more info.
  606. func (u *CompapiAsynctaskUpsertOne) Update(set func(*CompapiAsynctaskUpsert)) *CompapiAsynctaskUpsertOne {
  607. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  608. set(&CompapiAsynctaskUpsert{UpdateSet: update})
  609. }))
  610. return u
  611. }
  612. // SetUpdatedAt sets the "updated_at" field.
  613. func (u *CompapiAsynctaskUpsertOne) SetUpdatedAt(v time.Time) *CompapiAsynctaskUpsertOne {
  614. return u.Update(func(s *CompapiAsynctaskUpsert) {
  615. s.SetUpdatedAt(v)
  616. })
  617. }
  618. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  619. func (u *CompapiAsynctaskUpsertOne) UpdateUpdatedAt() *CompapiAsynctaskUpsertOne {
  620. return u.Update(func(s *CompapiAsynctaskUpsert) {
  621. s.UpdateUpdatedAt()
  622. })
  623. }
  624. // SetAuthToken sets the "auth_token" field.
  625. func (u *CompapiAsynctaskUpsertOne) SetAuthToken(v string) *CompapiAsynctaskUpsertOne {
  626. return u.Update(func(s *CompapiAsynctaskUpsert) {
  627. s.SetAuthToken(v)
  628. })
  629. }
  630. // UpdateAuthToken sets the "auth_token" field to the value that was provided on create.
  631. func (u *CompapiAsynctaskUpsertOne) UpdateAuthToken() *CompapiAsynctaskUpsertOne {
  632. return u.Update(func(s *CompapiAsynctaskUpsert) {
  633. s.UpdateAuthToken()
  634. })
  635. }
  636. // SetEventType sets the "event_type" field.
  637. func (u *CompapiAsynctaskUpsertOne) SetEventType(v string) *CompapiAsynctaskUpsertOne {
  638. return u.Update(func(s *CompapiAsynctaskUpsert) {
  639. s.SetEventType(v)
  640. })
  641. }
  642. // UpdateEventType sets the "event_type" field to the value that was provided on create.
  643. func (u *CompapiAsynctaskUpsertOne) UpdateEventType() *CompapiAsynctaskUpsertOne {
  644. return u.Update(func(s *CompapiAsynctaskUpsert) {
  645. s.UpdateEventType()
  646. })
  647. }
  648. // SetChatID sets the "chat_id" field.
  649. func (u *CompapiAsynctaskUpsertOne) SetChatID(v string) *CompapiAsynctaskUpsertOne {
  650. return u.Update(func(s *CompapiAsynctaskUpsert) {
  651. s.SetChatID(v)
  652. })
  653. }
  654. // UpdateChatID sets the "chat_id" field to the value that was provided on create.
  655. func (u *CompapiAsynctaskUpsertOne) UpdateChatID() *CompapiAsynctaskUpsertOne {
  656. return u.Update(func(s *CompapiAsynctaskUpsert) {
  657. s.UpdateChatID()
  658. })
  659. }
  660. // ClearChatID clears the value of the "chat_id" field.
  661. func (u *CompapiAsynctaskUpsertOne) ClearChatID() *CompapiAsynctaskUpsertOne {
  662. return u.Update(func(s *CompapiAsynctaskUpsert) {
  663. s.ClearChatID()
  664. })
  665. }
  666. // SetWorkidIdx sets the "workid_idx" field.
  667. func (u *CompapiAsynctaskUpsertOne) SetWorkidIdx(v int8) *CompapiAsynctaskUpsertOne {
  668. return u.Update(func(s *CompapiAsynctaskUpsert) {
  669. s.SetWorkidIdx(v)
  670. })
  671. }
  672. // AddWorkidIdx adds v to the "workid_idx" field.
  673. func (u *CompapiAsynctaskUpsertOne) AddWorkidIdx(v int8) *CompapiAsynctaskUpsertOne {
  674. return u.Update(func(s *CompapiAsynctaskUpsert) {
  675. s.AddWorkidIdx(v)
  676. })
  677. }
  678. // UpdateWorkidIdx sets the "workid_idx" field to the value that was provided on create.
  679. func (u *CompapiAsynctaskUpsertOne) UpdateWorkidIdx() *CompapiAsynctaskUpsertOne {
  680. return u.Update(func(s *CompapiAsynctaskUpsert) {
  681. s.UpdateWorkidIdx()
  682. })
  683. }
  684. // ClearWorkidIdx clears the value of the "workid_idx" field.
  685. func (u *CompapiAsynctaskUpsertOne) ClearWorkidIdx() *CompapiAsynctaskUpsertOne {
  686. return u.Update(func(s *CompapiAsynctaskUpsert) {
  687. s.ClearWorkidIdx()
  688. })
  689. }
  690. // SetOpenaiBase sets the "openai_base" field.
  691. func (u *CompapiAsynctaskUpsertOne) SetOpenaiBase(v string) *CompapiAsynctaskUpsertOne {
  692. return u.Update(func(s *CompapiAsynctaskUpsert) {
  693. s.SetOpenaiBase(v)
  694. })
  695. }
  696. // UpdateOpenaiBase sets the "openai_base" field to the value that was provided on create.
  697. func (u *CompapiAsynctaskUpsertOne) UpdateOpenaiBase() *CompapiAsynctaskUpsertOne {
  698. return u.Update(func(s *CompapiAsynctaskUpsert) {
  699. s.UpdateOpenaiBase()
  700. })
  701. }
  702. // SetOpenaiKey sets the "openai_key" field.
  703. func (u *CompapiAsynctaskUpsertOne) SetOpenaiKey(v string) *CompapiAsynctaskUpsertOne {
  704. return u.Update(func(s *CompapiAsynctaskUpsert) {
  705. s.SetOpenaiKey(v)
  706. })
  707. }
  708. // UpdateOpenaiKey sets the "openai_key" field to the value that was provided on create.
  709. func (u *CompapiAsynctaskUpsertOne) UpdateOpenaiKey() *CompapiAsynctaskUpsertOne {
  710. return u.Update(func(s *CompapiAsynctaskUpsert) {
  711. s.UpdateOpenaiKey()
  712. })
  713. }
  714. // SetRequestRaw sets the "request_raw" field.
  715. func (u *CompapiAsynctaskUpsertOne) SetRequestRaw(v string) *CompapiAsynctaskUpsertOne {
  716. return u.Update(func(s *CompapiAsynctaskUpsert) {
  717. s.SetRequestRaw(v)
  718. })
  719. }
  720. // UpdateRequestRaw sets the "request_raw" field to the value that was provided on create.
  721. func (u *CompapiAsynctaskUpsertOne) UpdateRequestRaw() *CompapiAsynctaskUpsertOne {
  722. return u.Update(func(s *CompapiAsynctaskUpsert) {
  723. s.UpdateRequestRaw()
  724. })
  725. }
  726. // SetResponseRaw sets the "response_raw" field.
  727. func (u *CompapiAsynctaskUpsertOne) SetResponseRaw(v string) *CompapiAsynctaskUpsertOne {
  728. return u.Update(func(s *CompapiAsynctaskUpsert) {
  729. s.SetResponseRaw(v)
  730. })
  731. }
  732. // UpdateResponseRaw sets the "response_raw" field to the value that was provided on create.
  733. func (u *CompapiAsynctaskUpsertOne) UpdateResponseRaw() *CompapiAsynctaskUpsertOne {
  734. return u.Update(func(s *CompapiAsynctaskUpsert) {
  735. s.UpdateResponseRaw()
  736. })
  737. }
  738. // ClearResponseRaw clears the value of the "response_raw" field.
  739. func (u *CompapiAsynctaskUpsertOne) ClearResponseRaw() *CompapiAsynctaskUpsertOne {
  740. return u.Update(func(s *CompapiAsynctaskUpsert) {
  741. s.ClearResponseRaw()
  742. })
  743. }
  744. // SetCallbackURL sets the "callback_url" field.
  745. func (u *CompapiAsynctaskUpsertOne) SetCallbackURL(v string) *CompapiAsynctaskUpsertOne {
  746. return u.Update(func(s *CompapiAsynctaskUpsert) {
  747. s.SetCallbackURL(v)
  748. })
  749. }
  750. // UpdateCallbackURL sets the "callback_url" field to the value that was provided on create.
  751. func (u *CompapiAsynctaskUpsertOne) UpdateCallbackURL() *CompapiAsynctaskUpsertOne {
  752. return u.Update(func(s *CompapiAsynctaskUpsert) {
  753. s.UpdateCallbackURL()
  754. })
  755. }
  756. // SetTaskStatus sets the "task_status" field.
  757. func (u *CompapiAsynctaskUpsertOne) SetTaskStatus(v int8) *CompapiAsynctaskUpsertOne {
  758. return u.Update(func(s *CompapiAsynctaskUpsert) {
  759. s.SetTaskStatus(v)
  760. })
  761. }
  762. // AddTaskStatus adds v to the "task_status" field.
  763. func (u *CompapiAsynctaskUpsertOne) AddTaskStatus(v int8) *CompapiAsynctaskUpsertOne {
  764. return u.Update(func(s *CompapiAsynctaskUpsert) {
  765. s.AddTaskStatus(v)
  766. })
  767. }
  768. // UpdateTaskStatus sets the "task_status" field to the value that was provided on create.
  769. func (u *CompapiAsynctaskUpsertOne) UpdateTaskStatus() *CompapiAsynctaskUpsertOne {
  770. return u.Update(func(s *CompapiAsynctaskUpsert) {
  771. s.UpdateTaskStatus()
  772. })
  773. }
  774. // ClearTaskStatus clears the value of the "task_status" field.
  775. func (u *CompapiAsynctaskUpsertOne) ClearTaskStatus() *CompapiAsynctaskUpsertOne {
  776. return u.Update(func(s *CompapiAsynctaskUpsert) {
  777. s.ClearTaskStatus()
  778. })
  779. }
  780. // SetRetryCount sets the "retry_count" field.
  781. func (u *CompapiAsynctaskUpsertOne) SetRetryCount(v int8) *CompapiAsynctaskUpsertOne {
  782. return u.Update(func(s *CompapiAsynctaskUpsert) {
  783. s.SetRetryCount(v)
  784. })
  785. }
  786. // AddRetryCount adds v to the "retry_count" field.
  787. func (u *CompapiAsynctaskUpsertOne) AddRetryCount(v int8) *CompapiAsynctaskUpsertOne {
  788. return u.Update(func(s *CompapiAsynctaskUpsert) {
  789. s.AddRetryCount(v)
  790. })
  791. }
  792. // UpdateRetryCount sets the "retry_count" field to the value that was provided on create.
  793. func (u *CompapiAsynctaskUpsertOne) UpdateRetryCount() *CompapiAsynctaskUpsertOne {
  794. return u.Update(func(s *CompapiAsynctaskUpsert) {
  795. s.UpdateRetryCount()
  796. })
  797. }
  798. // ClearRetryCount clears the value of the "retry_count" field.
  799. func (u *CompapiAsynctaskUpsertOne) ClearRetryCount() *CompapiAsynctaskUpsertOne {
  800. return u.Update(func(s *CompapiAsynctaskUpsert) {
  801. s.ClearRetryCount()
  802. })
  803. }
  804. // SetLastError sets the "last_error" field.
  805. func (u *CompapiAsynctaskUpsertOne) SetLastError(v string) *CompapiAsynctaskUpsertOne {
  806. return u.Update(func(s *CompapiAsynctaskUpsert) {
  807. s.SetLastError(v)
  808. })
  809. }
  810. // UpdateLastError sets the "last_error" field to the value that was provided on create.
  811. func (u *CompapiAsynctaskUpsertOne) UpdateLastError() *CompapiAsynctaskUpsertOne {
  812. return u.Update(func(s *CompapiAsynctaskUpsert) {
  813. s.UpdateLastError()
  814. })
  815. }
  816. // ClearLastError clears the value of the "last_error" field.
  817. func (u *CompapiAsynctaskUpsertOne) ClearLastError() *CompapiAsynctaskUpsertOne {
  818. return u.Update(func(s *CompapiAsynctaskUpsert) {
  819. s.ClearLastError()
  820. })
  821. }
  822. // Exec executes the query.
  823. func (u *CompapiAsynctaskUpsertOne) Exec(ctx context.Context) error {
  824. if len(u.create.conflict) == 0 {
  825. return errors.New("ent: missing options for CompapiAsynctaskCreate.OnConflict")
  826. }
  827. return u.create.Exec(ctx)
  828. }
  829. // ExecX is like Exec, but panics if an error occurs.
  830. func (u *CompapiAsynctaskUpsertOne) ExecX(ctx context.Context) {
  831. if err := u.create.Exec(ctx); err != nil {
  832. panic(err)
  833. }
  834. }
  835. // Exec executes the UPSERT query and returns the inserted/updated ID.
  836. func (u *CompapiAsynctaskUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  837. node, err := u.create.Save(ctx)
  838. if err != nil {
  839. return id, err
  840. }
  841. return node.ID, nil
  842. }
  843. // IDX is like ID, but panics if an error occurs.
  844. func (u *CompapiAsynctaskUpsertOne) IDX(ctx context.Context) uint64 {
  845. id, err := u.ID(ctx)
  846. if err != nil {
  847. panic(err)
  848. }
  849. return id
  850. }
  851. // CompapiAsynctaskCreateBulk is the builder for creating many CompapiAsynctask entities in bulk.
  852. type CompapiAsynctaskCreateBulk struct {
  853. config
  854. err error
  855. builders []*CompapiAsynctaskCreate
  856. conflict []sql.ConflictOption
  857. }
  858. // Save creates the CompapiAsynctask entities in the database.
  859. func (cacb *CompapiAsynctaskCreateBulk) Save(ctx context.Context) ([]*CompapiAsynctask, error) {
  860. if cacb.err != nil {
  861. return nil, cacb.err
  862. }
  863. specs := make([]*sqlgraph.CreateSpec, len(cacb.builders))
  864. nodes := make([]*CompapiAsynctask, len(cacb.builders))
  865. mutators := make([]Mutator, len(cacb.builders))
  866. for i := range cacb.builders {
  867. func(i int, root context.Context) {
  868. builder := cacb.builders[i]
  869. builder.defaults()
  870. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  871. mutation, ok := m.(*CompapiAsynctaskMutation)
  872. if !ok {
  873. return nil, fmt.Errorf("unexpected mutation type %T", m)
  874. }
  875. if err := builder.check(); err != nil {
  876. return nil, err
  877. }
  878. builder.mutation = mutation
  879. var err error
  880. nodes[i], specs[i] = builder.createSpec()
  881. if i < len(mutators)-1 {
  882. _, err = mutators[i+1].Mutate(root, cacb.builders[i+1].mutation)
  883. } else {
  884. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  885. spec.OnConflict = cacb.conflict
  886. // Invoke the actual operation on the latest mutation in the chain.
  887. if err = sqlgraph.BatchCreate(ctx, cacb.driver, spec); err != nil {
  888. if sqlgraph.IsConstraintError(err) {
  889. err = &ConstraintError{msg: err.Error(), wrap: err}
  890. }
  891. }
  892. }
  893. if err != nil {
  894. return nil, err
  895. }
  896. mutation.id = &nodes[i].ID
  897. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  898. id := specs[i].ID.Value.(int64)
  899. nodes[i].ID = uint64(id)
  900. }
  901. mutation.done = true
  902. return nodes[i], nil
  903. })
  904. for i := len(builder.hooks) - 1; i >= 0; i-- {
  905. mut = builder.hooks[i](mut)
  906. }
  907. mutators[i] = mut
  908. }(i, ctx)
  909. }
  910. if len(mutators) > 0 {
  911. if _, err := mutators[0].Mutate(ctx, cacb.builders[0].mutation); err != nil {
  912. return nil, err
  913. }
  914. }
  915. return nodes, nil
  916. }
  917. // SaveX is like Save, but panics if an error occurs.
  918. func (cacb *CompapiAsynctaskCreateBulk) SaveX(ctx context.Context) []*CompapiAsynctask {
  919. v, err := cacb.Save(ctx)
  920. if err != nil {
  921. panic(err)
  922. }
  923. return v
  924. }
  925. // Exec executes the query.
  926. func (cacb *CompapiAsynctaskCreateBulk) Exec(ctx context.Context) error {
  927. _, err := cacb.Save(ctx)
  928. return err
  929. }
  930. // ExecX is like Exec, but panics if an error occurs.
  931. func (cacb *CompapiAsynctaskCreateBulk) ExecX(ctx context.Context) {
  932. if err := cacb.Exec(ctx); err != nil {
  933. panic(err)
  934. }
  935. }
  936. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  937. // of the `INSERT` statement. For example:
  938. //
  939. // client.CompapiAsynctask.CreateBulk(builders...).
  940. // OnConflict(
  941. // // Update the row with the new values
  942. // // the was proposed for insertion.
  943. // sql.ResolveWithNewValues(),
  944. // ).
  945. // // Override some of the fields with custom
  946. // // update values.
  947. // Update(func(u *ent.CompapiAsynctaskUpsert) {
  948. // SetCreatedAt(v+v).
  949. // }).
  950. // Exec(ctx)
  951. func (cacb *CompapiAsynctaskCreateBulk) OnConflict(opts ...sql.ConflictOption) *CompapiAsynctaskUpsertBulk {
  952. cacb.conflict = opts
  953. return &CompapiAsynctaskUpsertBulk{
  954. create: cacb,
  955. }
  956. }
  957. // OnConflictColumns calls `OnConflict` and configures the columns
  958. // as conflict target. Using this option is equivalent to using:
  959. //
  960. // client.CompapiAsynctask.Create().
  961. // OnConflict(sql.ConflictColumns(columns...)).
  962. // Exec(ctx)
  963. func (cacb *CompapiAsynctaskCreateBulk) OnConflictColumns(columns ...string) *CompapiAsynctaskUpsertBulk {
  964. cacb.conflict = append(cacb.conflict, sql.ConflictColumns(columns...))
  965. return &CompapiAsynctaskUpsertBulk{
  966. create: cacb,
  967. }
  968. }
  969. // CompapiAsynctaskUpsertBulk is the builder for "upsert"-ing
  970. // a bulk of CompapiAsynctask nodes.
  971. type CompapiAsynctaskUpsertBulk struct {
  972. create *CompapiAsynctaskCreateBulk
  973. }
  974. // UpdateNewValues updates the mutable fields using the new values that
  975. // were set on create. Using this option is equivalent to using:
  976. //
  977. // client.CompapiAsynctask.Create().
  978. // OnConflict(
  979. // sql.ResolveWithNewValues(),
  980. // sql.ResolveWith(func(u *sql.UpdateSet) {
  981. // u.SetIgnore(compapiasynctask.FieldID)
  982. // }),
  983. // ).
  984. // Exec(ctx)
  985. func (u *CompapiAsynctaskUpsertBulk) UpdateNewValues() *CompapiAsynctaskUpsertBulk {
  986. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  987. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  988. for _, b := range u.create.builders {
  989. if _, exists := b.mutation.ID(); exists {
  990. s.SetIgnore(compapiasynctask.FieldID)
  991. }
  992. if _, exists := b.mutation.CreatedAt(); exists {
  993. s.SetIgnore(compapiasynctask.FieldCreatedAt)
  994. }
  995. }
  996. }))
  997. return u
  998. }
  999. // Ignore sets each column to itself in case of conflict.
  1000. // Using this option is equivalent to using:
  1001. //
  1002. // client.CompapiAsynctask.Create().
  1003. // OnConflict(sql.ResolveWithIgnore()).
  1004. // Exec(ctx)
  1005. func (u *CompapiAsynctaskUpsertBulk) Ignore() *CompapiAsynctaskUpsertBulk {
  1006. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1007. return u
  1008. }
  1009. // DoNothing configures the conflict_action to `DO NOTHING`.
  1010. // Supported only by SQLite and PostgreSQL.
  1011. func (u *CompapiAsynctaskUpsertBulk) DoNothing() *CompapiAsynctaskUpsertBulk {
  1012. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1013. return u
  1014. }
  1015. // Update allows overriding fields `UPDATE` values. See the CompapiAsynctaskCreateBulk.OnConflict
  1016. // documentation for more info.
  1017. func (u *CompapiAsynctaskUpsertBulk) Update(set func(*CompapiAsynctaskUpsert)) *CompapiAsynctaskUpsertBulk {
  1018. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1019. set(&CompapiAsynctaskUpsert{UpdateSet: update})
  1020. }))
  1021. return u
  1022. }
  1023. // SetUpdatedAt sets the "updated_at" field.
  1024. func (u *CompapiAsynctaskUpsertBulk) SetUpdatedAt(v time.Time) *CompapiAsynctaskUpsertBulk {
  1025. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1026. s.SetUpdatedAt(v)
  1027. })
  1028. }
  1029. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1030. func (u *CompapiAsynctaskUpsertBulk) UpdateUpdatedAt() *CompapiAsynctaskUpsertBulk {
  1031. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1032. s.UpdateUpdatedAt()
  1033. })
  1034. }
  1035. // SetAuthToken sets the "auth_token" field.
  1036. func (u *CompapiAsynctaskUpsertBulk) SetAuthToken(v string) *CompapiAsynctaskUpsertBulk {
  1037. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1038. s.SetAuthToken(v)
  1039. })
  1040. }
  1041. // UpdateAuthToken sets the "auth_token" field to the value that was provided on create.
  1042. func (u *CompapiAsynctaskUpsertBulk) UpdateAuthToken() *CompapiAsynctaskUpsertBulk {
  1043. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1044. s.UpdateAuthToken()
  1045. })
  1046. }
  1047. // SetEventType sets the "event_type" field.
  1048. func (u *CompapiAsynctaskUpsertBulk) SetEventType(v string) *CompapiAsynctaskUpsertBulk {
  1049. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1050. s.SetEventType(v)
  1051. })
  1052. }
  1053. // UpdateEventType sets the "event_type" field to the value that was provided on create.
  1054. func (u *CompapiAsynctaskUpsertBulk) UpdateEventType() *CompapiAsynctaskUpsertBulk {
  1055. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1056. s.UpdateEventType()
  1057. })
  1058. }
  1059. // SetChatID sets the "chat_id" field.
  1060. func (u *CompapiAsynctaskUpsertBulk) SetChatID(v string) *CompapiAsynctaskUpsertBulk {
  1061. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1062. s.SetChatID(v)
  1063. })
  1064. }
  1065. // UpdateChatID sets the "chat_id" field to the value that was provided on create.
  1066. func (u *CompapiAsynctaskUpsertBulk) UpdateChatID() *CompapiAsynctaskUpsertBulk {
  1067. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1068. s.UpdateChatID()
  1069. })
  1070. }
  1071. // ClearChatID clears the value of the "chat_id" field.
  1072. func (u *CompapiAsynctaskUpsertBulk) ClearChatID() *CompapiAsynctaskUpsertBulk {
  1073. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1074. s.ClearChatID()
  1075. })
  1076. }
  1077. // SetWorkidIdx sets the "workid_idx" field.
  1078. func (u *CompapiAsynctaskUpsertBulk) SetWorkidIdx(v int8) *CompapiAsynctaskUpsertBulk {
  1079. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1080. s.SetWorkidIdx(v)
  1081. })
  1082. }
  1083. // AddWorkidIdx adds v to the "workid_idx" field.
  1084. func (u *CompapiAsynctaskUpsertBulk) AddWorkidIdx(v int8) *CompapiAsynctaskUpsertBulk {
  1085. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1086. s.AddWorkidIdx(v)
  1087. })
  1088. }
  1089. // UpdateWorkidIdx sets the "workid_idx" field to the value that was provided on create.
  1090. func (u *CompapiAsynctaskUpsertBulk) UpdateWorkidIdx() *CompapiAsynctaskUpsertBulk {
  1091. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1092. s.UpdateWorkidIdx()
  1093. })
  1094. }
  1095. // ClearWorkidIdx clears the value of the "workid_idx" field.
  1096. func (u *CompapiAsynctaskUpsertBulk) ClearWorkidIdx() *CompapiAsynctaskUpsertBulk {
  1097. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1098. s.ClearWorkidIdx()
  1099. })
  1100. }
  1101. // SetOpenaiBase sets the "openai_base" field.
  1102. func (u *CompapiAsynctaskUpsertBulk) SetOpenaiBase(v string) *CompapiAsynctaskUpsertBulk {
  1103. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1104. s.SetOpenaiBase(v)
  1105. })
  1106. }
  1107. // UpdateOpenaiBase sets the "openai_base" field to the value that was provided on create.
  1108. func (u *CompapiAsynctaskUpsertBulk) UpdateOpenaiBase() *CompapiAsynctaskUpsertBulk {
  1109. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1110. s.UpdateOpenaiBase()
  1111. })
  1112. }
  1113. // SetOpenaiKey sets the "openai_key" field.
  1114. func (u *CompapiAsynctaskUpsertBulk) SetOpenaiKey(v string) *CompapiAsynctaskUpsertBulk {
  1115. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1116. s.SetOpenaiKey(v)
  1117. })
  1118. }
  1119. // UpdateOpenaiKey sets the "openai_key" field to the value that was provided on create.
  1120. func (u *CompapiAsynctaskUpsertBulk) UpdateOpenaiKey() *CompapiAsynctaskUpsertBulk {
  1121. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1122. s.UpdateOpenaiKey()
  1123. })
  1124. }
  1125. // SetRequestRaw sets the "request_raw" field.
  1126. func (u *CompapiAsynctaskUpsertBulk) SetRequestRaw(v string) *CompapiAsynctaskUpsertBulk {
  1127. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1128. s.SetRequestRaw(v)
  1129. })
  1130. }
  1131. // UpdateRequestRaw sets the "request_raw" field to the value that was provided on create.
  1132. func (u *CompapiAsynctaskUpsertBulk) UpdateRequestRaw() *CompapiAsynctaskUpsertBulk {
  1133. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1134. s.UpdateRequestRaw()
  1135. })
  1136. }
  1137. // SetResponseRaw sets the "response_raw" field.
  1138. func (u *CompapiAsynctaskUpsertBulk) SetResponseRaw(v string) *CompapiAsynctaskUpsertBulk {
  1139. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1140. s.SetResponseRaw(v)
  1141. })
  1142. }
  1143. // UpdateResponseRaw sets the "response_raw" field to the value that was provided on create.
  1144. func (u *CompapiAsynctaskUpsertBulk) UpdateResponseRaw() *CompapiAsynctaskUpsertBulk {
  1145. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1146. s.UpdateResponseRaw()
  1147. })
  1148. }
  1149. // ClearResponseRaw clears the value of the "response_raw" field.
  1150. func (u *CompapiAsynctaskUpsertBulk) ClearResponseRaw() *CompapiAsynctaskUpsertBulk {
  1151. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1152. s.ClearResponseRaw()
  1153. })
  1154. }
  1155. // SetCallbackURL sets the "callback_url" field.
  1156. func (u *CompapiAsynctaskUpsertBulk) SetCallbackURL(v string) *CompapiAsynctaskUpsertBulk {
  1157. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1158. s.SetCallbackURL(v)
  1159. })
  1160. }
  1161. // UpdateCallbackURL sets the "callback_url" field to the value that was provided on create.
  1162. func (u *CompapiAsynctaskUpsertBulk) UpdateCallbackURL() *CompapiAsynctaskUpsertBulk {
  1163. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1164. s.UpdateCallbackURL()
  1165. })
  1166. }
  1167. // SetTaskStatus sets the "task_status" field.
  1168. func (u *CompapiAsynctaskUpsertBulk) SetTaskStatus(v int8) *CompapiAsynctaskUpsertBulk {
  1169. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1170. s.SetTaskStatus(v)
  1171. })
  1172. }
  1173. // AddTaskStatus adds v to the "task_status" field.
  1174. func (u *CompapiAsynctaskUpsertBulk) AddTaskStatus(v int8) *CompapiAsynctaskUpsertBulk {
  1175. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1176. s.AddTaskStatus(v)
  1177. })
  1178. }
  1179. // UpdateTaskStatus sets the "task_status" field to the value that was provided on create.
  1180. func (u *CompapiAsynctaskUpsertBulk) UpdateTaskStatus() *CompapiAsynctaskUpsertBulk {
  1181. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1182. s.UpdateTaskStatus()
  1183. })
  1184. }
  1185. // ClearTaskStatus clears the value of the "task_status" field.
  1186. func (u *CompapiAsynctaskUpsertBulk) ClearTaskStatus() *CompapiAsynctaskUpsertBulk {
  1187. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1188. s.ClearTaskStatus()
  1189. })
  1190. }
  1191. // SetRetryCount sets the "retry_count" field.
  1192. func (u *CompapiAsynctaskUpsertBulk) SetRetryCount(v int8) *CompapiAsynctaskUpsertBulk {
  1193. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1194. s.SetRetryCount(v)
  1195. })
  1196. }
  1197. // AddRetryCount adds v to the "retry_count" field.
  1198. func (u *CompapiAsynctaskUpsertBulk) AddRetryCount(v int8) *CompapiAsynctaskUpsertBulk {
  1199. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1200. s.AddRetryCount(v)
  1201. })
  1202. }
  1203. // UpdateRetryCount sets the "retry_count" field to the value that was provided on create.
  1204. func (u *CompapiAsynctaskUpsertBulk) UpdateRetryCount() *CompapiAsynctaskUpsertBulk {
  1205. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1206. s.UpdateRetryCount()
  1207. })
  1208. }
  1209. // ClearRetryCount clears the value of the "retry_count" field.
  1210. func (u *CompapiAsynctaskUpsertBulk) ClearRetryCount() *CompapiAsynctaskUpsertBulk {
  1211. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1212. s.ClearRetryCount()
  1213. })
  1214. }
  1215. // SetLastError sets the "last_error" field.
  1216. func (u *CompapiAsynctaskUpsertBulk) SetLastError(v string) *CompapiAsynctaskUpsertBulk {
  1217. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1218. s.SetLastError(v)
  1219. })
  1220. }
  1221. // UpdateLastError sets the "last_error" field to the value that was provided on create.
  1222. func (u *CompapiAsynctaskUpsertBulk) UpdateLastError() *CompapiAsynctaskUpsertBulk {
  1223. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1224. s.UpdateLastError()
  1225. })
  1226. }
  1227. // ClearLastError clears the value of the "last_error" field.
  1228. func (u *CompapiAsynctaskUpsertBulk) ClearLastError() *CompapiAsynctaskUpsertBulk {
  1229. return u.Update(func(s *CompapiAsynctaskUpsert) {
  1230. s.ClearLastError()
  1231. })
  1232. }
  1233. // Exec executes the query.
  1234. func (u *CompapiAsynctaskUpsertBulk) Exec(ctx context.Context) error {
  1235. if u.create.err != nil {
  1236. return u.create.err
  1237. }
  1238. for i, b := range u.create.builders {
  1239. if len(b.conflict) != 0 {
  1240. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the CompapiAsynctaskCreateBulk instead", i)
  1241. }
  1242. }
  1243. if len(u.create.conflict) == 0 {
  1244. return errors.New("ent: missing options for CompapiAsynctaskCreateBulk.OnConflict")
  1245. }
  1246. return u.create.Exec(ctx)
  1247. }
  1248. // ExecX is like Exec, but panics if an error occurs.
  1249. func (u *CompapiAsynctaskUpsertBulk) ExecX(ctx context.Context) {
  1250. if err := u.create.Exec(ctx); err != nil {
  1251. panic(err)
  1252. }
  1253. }