usagedetail_update.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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/custom_types"
  9. "wechat-api/ent/predicate"
  10. "wechat-api/ent/usagedetail"
  11. "entgo.io/ent/dialect/sql"
  12. "entgo.io/ent/dialect/sql/sqlgraph"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // UsageDetailUpdate is the builder for updating UsageDetail entities.
  16. type UsageDetailUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *UsageDetailMutation
  20. }
  21. // Where appends a list predicates to the UsageDetailUpdate builder.
  22. func (udu *UsageDetailUpdate) Where(ps ...predicate.UsageDetail) *UsageDetailUpdate {
  23. udu.mutation.Where(ps...)
  24. return udu
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (udu *UsageDetailUpdate) SetUpdatedAt(t time.Time) *UsageDetailUpdate {
  28. udu.mutation.SetUpdatedAt(t)
  29. return udu
  30. }
  31. // SetStatus sets the "status" field.
  32. func (udu *UsageDetailUpdate) SetStatus(u uint8) *UsageDetailUpdate {
  33. udu.mutation.ResetStatus()
  34. udu.mutation.SetStatus(u)
  35. return udu
  36. }
  37. // SetNillableStatus sets the "status" field if the given value is not nil.
  38. func (udu *UsageDetailUpdate) SetNillableStatus(u *uint8) *UsageDetailUpdate {
  39. if u != nil {
  40. udu.SetStatus(*u)
  41. }
  42. return udu
  43. }
  44. // AddStatus adds u to the "status" field.
  45. func (udu *UsageDetailUpdate) AddStatus(u int8) *UsageDetailUpdate {
  46. udu.mutation.AddStatus(u)
  47. return udu
  48. }
  49. // ClearStatus clears the value of the "status" field.
  50. func (udu *UsageDetailUpdate) ClearStatus() *UsageDetailUpdate {
  51. udu.mutation.ClearStatus()
  52. return udu
  53. }
  54. // SetType sets the "type" field.
  55. func (udu *UsageDetailUpdate) SetType(i int) *UsageDetailUpdate {
  56. udu.mutation.ResetType()
  57. udu.mutation.SetType(i)
  58. return udu
  59. }
  60. // SetNillableType sets the "type" field if the given value is not nil.
  61. func (udu *UsageDetailUpdate) SetNillableType(i *int) *UsageDetailUpdate {
  62. if i != nil {
  63. udu.SetType(*i)
  64. }
  65. return udu
  66. }
  67. // AddType adds i to the "type" field.
  68. func (udu *UsageDetailUpdate) AddType(i int) *UsageDetailUpdate {
  69. udu.mutation.AddType(i)
  70. return udu
  71. }
  72. // ClearType clears the value of the "type" field.
  73. func (udu *UsageDetailUpdate) ClearType() *UsageDetailUpdate {
  74. udu.mutation.ClearType()
  75. return udu
  76. }
  77. // SetBotID sets the "bot_id" field.
  78. func (udu *UsageDetailUpdate) SetBotID(s string) *UsageDetailUpdate {
  79. udu.mutation.SetBotID(s)
  80. return udu
  81. }
  82. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  83. func (udu *UsageDetailUpdate) SetNillableBotID(s *string) *UsageDetailUpdate {
  84. if s != nil {
  85. udu.SetBotID(*s)
  86. }
  87. return udu
  88. }
  89. // SetReceiverID sets the "receiver_id" field.
  90. func (udu *UsageDetailUpdate) SetReceiverID(s string) *UsageDetailUpdate {
  91. udu.mutation.SetReceiverID(s)
  92. return udu
  93. }
  94. // SetNillableReceiverID sets the "receiver_id" field if the given value is not nil.
  95. func (udu *UsageDetailUpdate) SetNillableReceiverID(s *string) *UsageDetailUpdate {
  96. if s != nil {
  97. udu.SetReceiverID(*s)
  98. }
  99. return udu
  100. }
  101. // SetApp sets the "app" field.
  102. func (udu *UsageDetailUpdate) SetApp(i int) *UsageDetailUpdate {
  103. udu.mutation.ResetApp()
  104. udu.mutation.SetApp(i)
  105. return udu
  106. }
  107. // SetNillableApp sets the "app" field if the given value is not nil.
  108. func (udu *UsageDetailUpdate) SetNillableApp(i *int) *UsageDetailUpdate {
  109. if i != nil {
  110. udu.SetApp(*i)
  111. }
  112. return udu
  113. }
  114. // AddApp adds i to the "app" field.
  115. func (udu *UsageDetailUpdate) AddApp(i int) *UsageDetailUpdate {
  116. udu.mutation.AddApp(i)
  117. return udu
  118. }
  119. // ClearApp clears the value of the "app" field.
  120. func (udu *UsageDetailUpdate) ClearApp() *UsageDetailUpdate {
  121. udu.mutation.ClearApp()
  122. return udu
  123. }
  124. // SetSessionID sets the "session_id" field.
  125. func (udu *UsageDetailUpdate) SetSessionID(u uint64) *UsageDetailUpdate {
  126. udu.mutation.ResetSessionID()
  127. udu.mutation.SetSessionID(u)
  128. return udu
  129. }
  130. // SetNillableSessionID sets the "session_id" field if the given value is not nil.
  131. func (udu *UsageDetailUpdate) SetNillableSessionID(u *uint64) *UsageDetailUpdate {
  132. if u != nil {
  133. udu.SetSessionID(*u)
  134. }
  135. return udu
  136. }
  137. // AddSessionID adds u to the "session_id" field.
  138. func (udu *UsageDetailUpdate) AddSessionID(u int64) *UsageDetailUpdate {
  139. udu.mutation.AddSessionID(u)
  140. return udu
  141. }
  142. // ClearSessionID clears the value of the "session_id" field.
  143. func (udu *UsageDetailUpdate) ClearSessionID() *UsageDetailUpdate {
  144. udu.mutation.ClearSessionID()
  145. return udu
  146. }
  147. // SetRequest sets the "request" field.
  148. func (udu *UsageDetailUpdate) SetRequest(s string) *UsageDetailUpdate {
  149. udu.mutation.SetRequest(s)
  150. return udu
  151. }
  152. // SetNillableRequest sets the "request" field if the given value is not nil.
  153. func (udu *UsageDetailUpdate) SetNillableRequest(s *string) *UsageDetailUpdate {
  154. if s != nil {
  155. udu.SetRequest(*s)
  156. }
  157. return udu
  158. }
  159. // SetResponse sets the "response" field.
  160. func (udu *UsageDetailUpdate) SetResponse(s string) *UsageDetailUpdate {
  161. udu.mutation.SetResponse(s)
  162. return udu
  163. }
  164. // SetNillableResponse sets the "response" field if the given value is not nil.
  165. func (udu *UsageDetailUpdate) SetNillableResponse(s *string) *UsageDetailUpdate {
  166. if s != nil {
  167. udu.SetResponse(*s)
  168. }
  169. return udu
  170. }
  171. // SetOriginalData sets the "original_data" field.
  172. func (udu *UsageDetailUpdate) SetOriginalData(ctd custom_types.OriginalData) *UsageDetailUpdate {
  173. udu.mutation.SetOriginalData(ctd)
  174. return udu
  175. }
  176. // SetNillableOriginalData sets the "original_data" field if the given value is not nil.
  177. func (udu *UsageDetailUpdate) SetNillableOriginalData(ctd *custom_types.OriginalData) *UsageDetailUpdate {
  178. if ctd != nil {
  179. udu.SetOriginalData(*ctd)
  180. }
  181. return udu
  182. }
  183. // SetTotalTokens sets the "total_tokens" field.
  184. func (udu *UsageDetailUpdate) SetTotalTokens(u uint64) *UsageDetailUpdate {
  185. udu.mutation.ResetTotalTokens()
  186. udu.mutation.SetTotalTokens(u)
  187. return udu
  188. }
  189. // SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil.
  190. func (udu *UsageDetailUpdate) SetNillableTotalTokens(u *uint64) *UsageDetailUpdate {
  191. if u != nil {
  192. udu.SetTotalTokens(*u)
  193. }
  194. return udu
  195. }
  196. // AddTotalTokens adds u to the "total_tokens" field.
  197. func (udu *UsageDetailUpdate) AddTotalTokens(u int64) *UsageDetailUpdate {
  198. udu.mutation.AddTotalTokens(u)
  199. return udu
  200. }
  201. // ClearTotalTokens clears the value of the "total_tokens" field.
  202. func (udu *UsageDetailUpdate) ClearTotalTokens() *UsageDetailUpdate {
  203. udu.mutation.ClearTotalTokens()
  204. return udu
  205. }
  206. // SetPromptTokens sets the "prompt_tokens" field.
  207. func (udu *UsageDetailUpdate) SetPromptTokens(u uint64) *UsageDetailUpdate {
  208. udu.mutation.ResetPromptTokens()
  209. udu.mutation.SetPromptTokens(u)
  210. return udu
  211. }
  212. // SetNillablePromptTokens sets the "prompt_tokens" field if the given value is not nil.
  213. func (udu *UsageDetailUpdate) SetNillablePromptTokens(u *uint64) *UsageDetailUpdate {
  214. if u != nil {
  215. udu.SetPromptTokens(*u)
  216. }
  217. return udu
  218. }
  219. // AddPromptTokens adds u to the "prompt_tokens" field.
  220. func (udu *UsageDetailUpdate) AddPromptTokens(u int64) *UsageDetailUpdate {
  221. udu.mutation.AddPromptTokens(u)
  222. return udu
  223. }
  224. // ClearPromptTokens clears the value of the "prompt_tokens" field.
  225. func (udu *UsageDetailUpdate) ClearPromptTokens() *UsageDetailUpdate {
  226. udu.mutation.ClearPromptTokens()
  227. return udu
  228. }
  229. // SetCompletionTokens sets the "completion_tokens" field.
  230. func (udu *UsageDetailUpdate) SetCompletionTokens(u uint64) *UsageDetailUpdate {
  231. udu.mutation.ResetCompletionTokens()
  232. udu.mutation.SetCompletionTokens(u)
  233. return udu
  234. }
  235. // SetNillableCompletionTokens sets the "completion_tokens" field if the given value is not nil.
  236. func (udu *UsageDetailUpdate) SetNillableCompletionTokens(u *uint64) *UsageDetailUpdate {
  237. if u != nil {
  238. udu.SetCompletionTokens(*u)
  239. }
  240. return udu
  241. }
  242. // AddCompletionTokens adds u to the "completion_tokens" field.
  243. func (udu *UsageDetailUpdate) AddCompletionTokens(u int64) *UsageDetailUpdate {
  244. udu.mutation.AddCompletionTokens(u)
  245. return udu
  246. }
  247. // ClearCompletionTokens clears the value of the "completion_tokens" field.
  248. func (udu *UsageDetailUpdate) ClearCompletionTokens() *UsageDetailUpdate {
  249. udu.mutation.ClearCompletionTokens()
  250. return udu
  251. }
  252. // SetOrganizationID sets the "organization_id" field.
  253. func (udu *UsageDetailUpdate) SetOrganizationID(u uint64) *UsageDetailUpdate {
  254. udu.mutation.ResetOrganizationID()
  255. udu.mutation.SetOrganizationID(u)
  256. return udu
  257. }
  258. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  259. func (udu *UsageDetailUpdate) SetNillableOrganizationID(u *uint64) *UsageDetailUpdate {
  260. if u != nil {
  261. udu.SetOrganizationID(*u)
  262. }
  263. return udu
  264. }
  265. // AddOrganizationID adds u to the "organization_id" field.
  266. func (udu *UsageDetailUpdate) AddOrganizationID(u int64) *UsageDetailUpdate {
  267. udu.mutation.AddOrganizationID(u)
  268. return udu
  269. }
  270. // ClearOrganizationID clears the value of the "organization_id" field.
  271. func (udu *UsageDetailUpdate) ClearOrganizationID() *UsageDetailUpdate {
  272. udu.mutation.ClearOrganizationID()
  273. return udu
  274. }
  275. // Mutation returns the UsageDetailMutation object of the builder.
  276. func (udu *UsageDetailUpdate) Mutation() *UsageDetailMutation {
  277. return udu.mutation
  278. }
  279. // Save executes the query and returns the number of nodes affected by the update operation.
  280. func (udu *UsageDetailUpdate) Save(ctx context.Context) (int, error) {
  281. udu.defaults()
  282. return withHooks(ctx, udu.sqlSave, udu.mutation, udu.hooks)
  283. }
  284. // SaveX is like Save, but panics if an error occurs.
  285. func (udu *UsageDetailUpdate) SaveX(ctx context.Context) int {
  286. affected, err := udu.Save(ctx)
  287. if err != nil {
  288. panic(err)
  289. }
  290. return affected
  291. }
  292. // Exec executes the query.
  293. func (udu *UsageDetailUpdate) Exec(ctx context.Context) error {
  294. _, err := udu.Save(ctx)
  295. return err
  296. }
  297. // ExecX is like Exec, but panics if an error occurs.
  298. func (udu *UsageDetailUpdate) ExecX(ctx context.Context) {
  299. if err := udu.Exec(ctx); err != nil {
  300. panic(err)
  301. }
  302. }
  303. // defaults sets the default values of the builder before save.
  304. func (udu *UsageDetailUpdate) defaults() {
  305. if _, ok := udu.mutation.UpdatedAt(); !ok {
  306. v := usagedetail.UpdateDefaultUpdatedAt()
  307. udu.mutation.SetUpdatedAt(v)
  308. }
  309. }
  310. func (udu *UsageDetailUpdate) sqlSave(ctx context.Context) (n int, err error) {
  311. _spec := sqlgraph.NewUpdateSpec(usagedetail.Table, usagedetail.Columns, sqlgraph.NewFieldSpec(usagedetail.FieldID, field.TypeUint64))
  312. if ps := udu.mutation.predicates; len(ps) > 0 {
  313. _spec.Predicate = func(selector *sql.Selector) {
  314. for i := range ps {
  315. ps[i](selector)
  316. }
  317. }
  318. }
  319. if value, ok := udu.mutation.UpdatedAt(); ok {
  320. _spec.SetField(usagedetail.FieldUpdatedAt, field.TypeTime, value)
  321. }
  322. if value, ok := udu.mutation.Status(); ok {
  323. _spec.SetField(usagedetail.FieldStatus, field.TypeUint8, value)
  324. }
  325. if value, ok := udu.mutation.AddedStatus(); ok {
  326. _spec.AddField(usagedetail.FieldStatus, field.TypeUint8, value)
  327. }
  328. if udu.mutation.StatusCleared() {
  329. _spec.ClearField(usagedetail.FieldStatus, field.TypeUint8)
  330. }
  331. if value, ok := udu.mutation.GetType(); ok {
  332. _spec.SetField(usagedetail.FieldType, field.TypeInt, value)
  333. }
  334. if value, ok := udu.mutation.AddedType(); ok {
  335. _spec.AddField(usagedetail.FieldType, field.TypeInt, value)
  336. }
  337. if udu.mutation.TypeCleared() {
  338. _spec.ClearField(usagedetail.FieldType, field.TypeInt)
  339. }
  340. if value, ok := udu.mutation.BotID(); ok {
  341. _spec.SetField(usagedetail.FieldBotID, field.TypeString, value)
  342. }
  343. if value, ok := udu.mutation.ReceiverID(); ok {
  344. _spec.SetField(usagedetail.FieldReceiverID, field.TypeString, value)
  345. }
  346. if value, ok := udu.mutation.App(); ok {
  347. _spec.SetField(usagedetail.FieldApp, field.TypeInt, value)
  348. }
  349. if value, ok := udu.mutation.AddedApp(); ok {
  350. _spec.AddField(usagedetail.FieldApp, field.TypeInt, value)
  351. }
  352. if udu.mutation.AppCleared() {
  353. _spec.ClearField(usagedetail.FieldApp, field.TypeInt)
  354. }
  355. if value, ok := udu.mutation.SessionID(); ok {
  356. _spec.SetField(usagedetail.FieldSessionID, field.TypeUint64, value)
  357. }
  358. if value, ok := udu.mutation.AddedSessionID(); ok {
  359. _spec.AddField(usagedetail.FieldSessionID, field.TypeUint64, value)
  360. }
  361. if udu.mutation.SessionIDCleared() {
  362. _spec.ClearField(usagedetail.FieldSessionID, field.TypeUint64)
  363. }
  364. if value, ok := udu.mutation.Request(); ok {
  365. _spec.SetField(usagedetail.FieldRequest, field.TypeString, value)
  366. }
  367. if value, ok := udu.mutation.Response(); ok {
  368. _spec.SetField(usagedetail.FieldResponse, field.TypeString, value)
  369. }
  370. if value, ok := udu.mutation.OriginalData(); ok {
  371. _spec.SetField(usagedetail.FieldOriginalData, field.TypeJSON, value)
  372. }
  373. if value, ok := udu.mutation.TotalTokens(); ok {
  374. _spec.SetField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
  375. }
  376. if value, ok := udu.mutation.AddedTotalTokens(); ok {
  377. _spec.AddField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
  378. }
  379. if udu.mutation.TotalTokensCleared() {
  380. _spec.ClearField(usagedetail.FieldTotalTokens, field.TypeUint64)
  381. }
  382. if value, ok := udu.mutation.PromptTokens(); ok {
  383. _spec.SetField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
  384. }
  385. if value, ok := udu.mutation.AddedPromptTokens(); ok {
  386. _spec.AddField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
  387. }
  388. if udu.mutation.PromptTokensCleared() {
  389. _spec.ClearField(usagedetail.FieldPromptTokens, field.TypeUint64)
  390. }
  391. if value, ok := udu.mutation.CompletionTokens(); ok {
  392. _spec.SetField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
  393. }
  394. if value, ok := udu.mutation.AddedCompletionTokens(); ok {
  395. _spec.AddField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
  396. }
  397. if udu.mutation.CompletionTokensCleared() {
  398. _spec.ClearField(usagedetail.FieldCompletionTokens, field.TypeUint64)
  399. }
  400. if value, ok := udu.mutation.OrganizationID(); ok {
  401. _spec.SetField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
  402. }
  403. if value, ok := udu.mutation.AddedOrganizationID(); ok {
  404. _spec.AddField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
  405. }
  406. if udu.mutation.OrganizationIDCleared() {
  407. _spec.ClearField(usagedetail.FieldOrganizationID, field.TypeUint64)
  408. }
  409. if n, err = sqlgraph.UpdateNodes(ctx, udu.driver, _spec); err != nil {
  410. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  411. err = &NotFoundError{usagedetail.Label}
  412. } else if sqlgraph.IsConstraintError(err) {
  413. err = &ConstraintError{msg: err.Error(), wrap: err}
  414. }
  415. return 0, err
  416. }
  417. udu.mutation.done = true
  418. return n, nil
  419. }
  420. // UsageDetailUpdateOne is the builder for updating a single UsageDetail entity.
  421. type UsageDetailUpdateOne struct {
  422. config
  423. fields []string
  424. hooks []Hook
  425. mutation *UsageDetailMutation
  426. }
  427. // SetUpdatedAt sets the "updated_at" field.
  428. func (uduo *UsageDetailUpdateOne) SetUpdatedAt(t time.Time) *UsageDetailUpdateOne {
  429. uduo.mutation.SetUpdatedAt(t)
  430. return uduo
  431. }
  432. // SetStatus sets the "status" field.
  433. func (uduo *UsageDetailUpdateOne) SetStatus(u uint8) *UsageDetailUpdateOne {
  434. uduo.mutation.ResetStatus()
  435. uduo.mutation.SetStatus(u)
  436. return uduo
  437. }
  438. // SetNillableStatus sets the "status" field if the given value is not nil.
  439. func (uduo *UsageDetailUpdateOne) SetNillableStatus(u *uint8) *UsageDetailUpdateOne {
  440. if u != nil {
  441. uduo.SetStatus(*u)
  442. }
  443. return uduo
  444. }
  445. // AddStatus adds u to the "status" field.
  446. func (uduo *UsageDetailUpdateOne) AddStatus(u int8) *UsageDetailUpdateOne {
  447. uduo.mutation.AddStatus(u)
  448. return uduo
  449. }
  450. // ClearStatus clears the value of the "status" field.
  451. func (uduo *UsageDetailUpdateOne) ClearStatus() *UsageDetailUpdateOne {
  452. uduo.mutation.ClearStatus()
  453. return uduo
  454. }
  455. // SetType sets the "type" field.
  456. func (uduo *UsageDetailUpdateOne) SetType(i int) *UsageDetailUpdateOne {
  457. uduo.mutation.ResetType()
  458. uduo.mutation.SetType(i)
  459. return uduo
  460. }
  461. // SetNillableType sets the "type" field if the given value is not nil.
  462. func (uduo *UsageDetailUpdateOne) SetNillableType(i *int) *UsageDetailUpdateOne {
  463. if i != nil {
  464. uduo.SetType(*i)
  465. }
  466. return uduo
  467. }
  468. // AddType adds i to the "type" field.
  469. func (uduo *UsageDetailUpdateOne) AddType(i int) *UsageDetailUpdateOne {
  470. uduo.mutation.AddType(i)
  471. return uduo
  472. }
  473. // ClearType clears the value of the "type" field.
  474. func (uduo *UsageDetailUpdateOne) ClearType() *UsageDetailUpdateOne {
  475. uduo.mutation.ClearType()
  476. return uduo
  477. }
  478. // SetBotID sets the "bot_id" field.
  479. func (uduo *UsageDetailUpdateOne) SetBotID(s string) *UsageDetailUpdateOne {
  480. uduo.mutation.SetBotID(s)
  481. return uduo
  482. }
  483. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  484. func (uduo *UsageDetailUpdateOne) SetNillableBotID(s *string) *UsageDetailUpdateOne {
  485. if s != nil {
  486. uduo.SetBotID(*s)
  487. }
  488. return uduo
  489. }
  490. // SetReceiverID sets the "receiver_id" field.
  491. func (uduo *UsageDetailUpdateOne) SetReceiverID(s string) *UsageDetailUpdateOne {
  492. uduo.mutation.SetReceiverID(s)
  493. return uduo
  494. }
  495. // SetNillableReceiverID sets the "receiver_id" field if the given value is not nil.
  496. func (uduo *UsageDetailUpdateOne) SetNillableReceiverID(s *string) *UsageDetailUpdateOne {
  497. if s != nil {
  498. uduo.SetReceiverID(*s)
  499. }
  500. return uduo
  501. }
  502. // SetApp sets the "app" field.
  503. func (uduo *UsageDetailUpdateOne) SetApp(i int) *UsageDetailUpdateOne {
  504. uduo.mutation.ResetApp()
  505. uduo.mutation.SetApp(i)
  506. return uduo
  507. }
  508. // SetNillableApp sets the "app" field if the given value is not nil.
  509. func (uduo *UsageDetailUpdateOne) SetNillableApp(i *int) *UsageDetailUpdateOne {
  510. if i != nil {
  511. uduo.SetApp(*i)
  512. }
  513. return uduo
  514. }
  515. // AddApp adds i to the "app" field.
  516. func (uduo *UsageDetailUpdateOne) AddApp(i int) *UsageDetailUpdateOne {
  517. uduo.mutation.AddApp(i)
  518. return uduo
  519. }
  520. // ClearApp clears the value of the "app" field.
  521. func (uduo *UsageDetailUpdateOne) ClearApp() *UsageDetailUpdateOne {
  522. uduo.mutation.ClearApp()
  523. return uduo
  524. }
  525. // SetSessionID sets the "session_id" field.
  526. func (uduo *UsageDetailUpdateOne) SetSessionID(u uint64) *UsageDetailUpdateOne {
  527. uduo.mutation.ResetSessionID()
  528. uduo.mutation.SetSessionID(u)
  529. return uduo
  530. }
  531. // SetNillableSessionID sets the "session_id" field if the given value is not nil.
  532. func (uduo *UsageDetailUpdateOne) SetNillableSessionID(u *uint64) *UsageDetailUpdateOne {
  533. if u != nil {
  534. uduo.SetSessionID(*u)
  535. }
  536. return uduo
  537. }
  538. // AddSessionID adds u to the "session_id" field.
  539. func (uduo *UsageDetailUpdateOne) AddSessionID(u int64) *UsageDetailUpdateOne {
  540. uduo.mutation.AddSessionID(u)
  541. return uduo
  542. }
  543. // ClearSessionID clears the value of the "session_id" field.
  544. func (uduo *UsageDetailUpdateOne) ClearSessionID() *UsageDetailUpdateOne {
  545. uduo.mutation.ClearSessionID()
  546. return uduo
  547. }
  548. // SetRequest sets the "request" field.
  549. func (uduo *UsageDetailUpdateOne) SetRequest(s string) *UsageDetailUpdateOne {
  550. uduo.mutation.SetRequest(s)
  551. return uduo
  552. }
  553. // SetNillableRequest sets the "request" field if the given value is not nil.
  554. func (uduo *UsageDetailUpdateOne) SetNillableRequest(s *string) *UsageDetailUpdateOne {
  555. if s != nil {
  556. uduo.SetRequest(*s)
  557. }
  558. return uduo
  559. }
  560. // SetResponse sets the "response" field.
  561. func (uduo *UsageDetailUpdateOne) SetResponse(s string) *UsageDetailUpdateOne {
  562. uduo.mutation.SetResponse(s)
  563. return uduo
  564. }
  565. // SetNillableResponse sets the "response" field if the given value is not nil.
  566. func (uduo *UsageDetailUpdateOne) SetNillableResponse(s *string) *UsageDetailUpdateOne {
  567. if s != nil {
  568. uduo.SetResponse(*s)
  569. }
  570. return uduo
  571. }
  572. // SetOriginalData sets the "original_data" field.
  573. func (uduo *UsageDetailUpdateOne) SetOriginalData(ctd custom_types.OriginalData) *UsageDetailUpdateOne {
  574. uduo.mutation.SetOriginalData(ctd)
  575. return uduo
  576. }
  577. // SetNillableOriginalData sets the "original_data" field if the given value is not nil.
  578. func (uduo *UsageDetailUpdateOne) SetNillableOriginalData(ctd *custom_types.OriginalData) *UsageDetailUpdateOne {
  579. if ctd != nil {
  580. uduo.SetOriginalData(*ctd)
  581. }
  582. return uduo
  583. }
  584. // SetTotalTokens sets the "total_tokens" field.
  585. func (uduo *UsageDetailUpdateOne) SetTotalTokens(u uint64) *UsageDetailUpdateOne {
  586. uduo.mutation.ResetTotalTokens()
  587. uduo.mutation.SetTotalTokens(u)
  588. return uduo
  589. }
  590. // SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil.
  591. func (uduo *UsageDetailUpdateOne) SetNillableTotalTokens(u *uint64) *UsageDetailUpdateOne {
  592. if u != nil {
  593. uduo.SetTotalTokens(*u)
  594. }
  595. return uduo
  596. }
  597. // AddTotalTokens adds u to the "total_tokens" field.
  598. func (uduo *UsageDetailUpdateOne) AddTotalTokens(u int64) *UsageDetailUpdateOne {
  599. uduo.mutation.AddTotalTokens(u)
  600. return uduo
  601. }
  602. // ClearTotalTokens clears the value of the "total_tokens" field.
  603. func (uduo *UsageDetailUpdateOne) ClearTotalTokens() *UsageDetailUpdateOne {
  604. uduo.mutation.ClearTotalTokens()
  605. return uduo
  606. }
  607. // SetPromptTokens sets the "prompt_tokens" field.
  608. func (uduo *UsageDetailUpdateOne) SetPromptTokens(u uint64) *UsageDetailUpdateOne {
  609. uduo.mutation.ResetPromptTokens()
  610. uduo.mutation.SetPromptTokens(u)
  611. return uduo
  612. }
  613. // SetNillablePromptTokens sets the "prompt_tokens" field if the given value is not nil.
  614. func (uduo *UsageDetailUpdateOne) SetNillablePromptTokens(u *uint64) *UsageDetailUpdateOne {
  615. if u != nil {
  616. uduo.SetPromptTokens(*u)
  617. }
  618. return uduo
  619. }
  620. // AddPromptTokens adds u to the "prompt_tokens" field.
  621. func (uduo *UsageDetailUpdateOne) AddPromptTokens(u int64) *UsageDetailUpdateOne {
  622. uduo.mutation.AddPromptTokens(u)
  623. return uduo
  624. }
  625. // ClearPromptTokens clears the value of the "prompt_tokens" field.
  626. func (uduo *UsageDetailUpdateOne) ClearPromptTokens() *UsageDetailUpdateOne {
  627. uduo.mutation.ClearPromptTokens()
  628. return uduo
  629. }
  630. // SetCompletionTokens sets the "completion_tokens" field.
  631. func (uduo *UsageDetailUpdateOne) SetCompletionTokens(u uint64) *UsageDetailUpdateOne {
  632. uduo.mutation.ResetCompletionTokens()
  633. uduo.mutation.SetCompletionTokens(u)
  634. return uduo
  635. }
  636. // SetNillableCompletionTokens sets the "completion_tokens" field if the given value is not nil.
  637. func (uduo *UsageDetailUpdateOne) SetNillableCompletionTokens(u *uint64) *UsageDetailUpdateOne {
  638. if u != nil {
  639. uduo.SetCompletionTokens(*u)
  640. }
  641. return uduo
  642. }
  643. // AddCompletionTokens adds u to the "completion_tokens" field.
  644. func (uduo *UsageDetailUpdateOne) AddCompletionTokens(u int64) *UsageDetailUpdateOne {
  645. uduo.mutation.AddCompletionTokens(u)
  646. return uduo
  647. }
  648. // ClearCompletionTokens clears the value of the "completion_tokens" field.
  649. func (uduo *UsageDetailUpdateOne) ClearCompletionTokens() *UsageDetailUpdateOne {
  650. uduo.mutation.ClearCompletionTokens()
  651. return uduo
  652. }
  653. // SetOrganizationID sets the "organization_id" field.
  654. func (uduo *UsageDetailUpdateOne) SetOrganizationID(u uint64) *UsageDetailUpdateOne {
  655. uduo.mutation.ResetOrganizationID()
  656. uduo.mutation.SetOrganizationID(u)
  657. return uduo
  658. }
  659. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  660. func (uduo *UsageDetailUpdateOne) SetNillableOrganizationID(u *uint64) *UsageDetailUpdateOne {
  661. if u != nil {
  662. uduo.SetOrganizationID(*u)
  663. }
  664. return uduo
  665. }
  666. // AddOrganizationID adds u to the "organization_id" field.
  667. func (uduo *UsageDetailUpdateOne) AddOrganizationID(u int64) *UsageDetailUpdateOne {
  668. uduo.mutation.AddOrganizationID(u)
  669. return uduo
  670. }
  671. // ClearOrganizationID clears the value of the "organization_id" field.
  672. func (uduo *UsageDetailUpdateOne) ClearOrganizationID() *UsageDetailUpdateOne {
  673. uduo.mutation.ClearOrganizationID()
  674. return uduo
  675. }
  676. // Mutation returns the UsageDetailMutation object of the builder.
  677. func (uduo *UsageDetailUpdateOne) Mutation() *UsageDetailMutation {
  678. return uduo.mutation
  679. }
  680. // Where appends a list predicates to the UsageDetailUpdate builder.
  681. func (uduo *UsageDetailUpdateOne) Where(ps ...predicate.UsageDetail) *UsageDetailUpdateOne {
  682. uduo.mutation.Where(ps...)
  683. return uduo
  684. }
  685. // Select allows selecting one or more fields (columns) of the returned entity.
  686. // The default is selecting all fields defined in the entity schema.
  687. func (uduo *UsageDetailUpdateOne) Select(field string, fields ...string) *UsageDetailUpdateOne {
  688. uduo.fields = append([]string{field}, fields...)
  689. return uduo
  690. }
  691. // Save executes the query and returns the updated UsageDetail entity.
  692. func (uduo *UsageDetailUpdateOne) Save(ctx context.Context) (*UsageDetail, error) {
  693. uduo.defaults()
  694. return withHooks(ctx, uduo.sqlSave, uduo.mutation, uduo.hooks)
  695. }
  696. // SaveX is like Save, but panics if an error occurs.
  697. func (uduo *UsageDetailUpdateOne) SaveX(ctx context.Context) *UsageDetail {
  698. node, err := uduo.Save(ctx)
  699. if err != nil {
  700. panic(err)
  701. }
  702. return node
  703. }
  704. // Exec executes the query on the entity.
  705. func (uduo *UsageDetailUpdateOne) Exec(ctx context.Context) error {
  706. _, err := uduo.Save(ctx)
  707. return err
  708. }
  709. // ExecX is like Exec, but panics if an error occurs.
  710. func (uduo *UsageDetailUpdateOne) ExecX(ctx context.Context) {
  711. if err := uduo.Exec(ctx); err != nil {
  712. panic(err)
  713. }
  714. }
  715. // defaults sets the default values of the builder before save.
  716. func (uduo *UsageDetailUpdateOne) defaults() {
  717. if _, ok := uduo.mutation.UpdatedAt(); !ok {
  718. v := usagedetail.UpdateDefaultUpdatedAt()
  719. uduo.mutation.SetUpdatedAt(v)
  720. }
  721. }
  722. func (uduo *UsageDetailUpdateOne) sqlSave(ctx context.Context) (_node *UsageDetail, err error) {
  723. _spec := sqlgraph.NewUpdateSpec(usagedetail.Table, usagedetail.Columns, sqlgraph.NewFieldSpec(usagedetail.FieldID, field.TypeUint64))
  724. id, ok := uduo.mutation.ID()
  725. if !ok {
  726. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageDetail.id" for update`)}
  727. }
  728. _spec.Node.ID.Value = id
  729. if fields := uduo.fields; len(fields) > 0 {
  730. _spec.Node.Columns = make([]string, 0, len(fields))
  731. _spec.Node.Columns = append(_spec.Node.Columns, usagedetail.FieldID)
  732. for _, f := range fields {
  733. if !usagedetail.ValidColumn(f) {
  734. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  735. }
  736. if f != usagedetail.FieldID {
  737. _spec.Node.Columns = append(_spec.Node.Columns, f)
  738. }
  739. }
  740. }
  741. if ps := uduo.mutation.predicates; len(ps) > 0 {
  742. _spec.Predicate = func(selector *sql.Selector) {
  743. for i := range ps {
  744. ps[i](selector)
  745. }
  746. }
  747. }
  748. if value, ok := uduo.mutation.UpdatedAt(); ok {
  749. _spec.SetField(usagedetail.FieldUpdatedAt, field.TypeTime, value)
  750. }
  751. if value, ok := uduo.mutation.Status(); ok {
  752. _spec.SetField(usagedetail.FieldStatus, field.TypeUint8, value)
  753. }
  754. if value, ok := uduo.mutation.AddedStatus(); ok {
  755. _spec.AddField(usagedetail.FieldStatus, field.TypeUint8, value)
  756. }
  757. if uduo.mutation.StatusCleared() {
  758. _spec.ClearField(usagedetail.FieldStatus, field.TypeUint8)
  759. }
  760. if value, ok := uduo.mutation.GetType(); ok {
  761. _spec.SetField(usagedetail.FieldType, field.TypeInt, value)
  762. }
  763. if value, ok := uduo.mutation.AddedType(); ok {
  764. _spec.AddField(usagedetail.FieldType, field.TypeInt, value)
  765. }
  766. if uduo.mutation.TypeCleared() {
  767. _spec.ClearField(usagedetail.FieldType, field.TypeInt)
  768. }
  769. if value, ok := uduo.mutation.BotID(); ok {
  770. _spec.SetField(usagedetail.FieldBotID, field.TypeString, value)
  771. }
  772. if value, ok := uduo.mutation.ReceiverID(); ok {
  773. _spec.SetField(usagedetail.FieldReceiverID, field.TypeString, value)
  774. }
  775. if value, ok := uduo.mutation.App(); ok {
  776. _spec.SetField(usagedetail.FieldApp, field.TypeInt, value)
  777. }
  778. if value, ok := uduo.mutation.AddedApp(); ok {
  779. _spec.AddField(usagedetail.FieldApp, field.TypeInt, value)
  780. }
  781. if uduo.mutation.AppCleared() {
  782. _spec.ClearField(usagedetail.FieldApp, field.TypeInt)
  783. }
  784. if value, ok := uduo.mutation.SessionID(); ok {
  785. _spec.SetField(usagedetail.FieldSessionID, field.TypeUint64, value)
  786. }
  787. if value, ok := uduo.mutation.AddedSessionID(); ok {
  788. _spec.AddField(usagedetail.FieldSessionID, field.TypeUint64, value)
  789. }
  790. if uduo.mutation.SessionIDCleared() {
  791. _spec.ClearField(usagedetail.FieldSessionID, field.TypeUint64)
  792. }
  793. if value, ok := uduo.mutation.Request(); ok {
  794. _spec.SetField(usagedetail.FieldRequest, field.TypeString, value)
  795. }
  796. if value, ok := uduo.mutation.Response(); ok {
  797. _spec.SetField(usagedetail.FieldResponse, field.TypeString, value)
  798. }
  799. if value, ok := uduo.mutation.OriginalData(); ok {
  800. _spec.SetField(usagedetail.FieldOriginalData, field.TypeJSON, value)
  801. }
  802. if value, ok := uduo.mutation.TotalTokens(); ok {
  803. _spec.SetField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
  804. }
  805. if value, ok := uduo.mutation.AddedTotalTokens(); ok {
  806. _spec.AddField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
  807. }
  808. if uduo.mutation.TotalTokensCleared() {
  809. _spec.ClearField(usagedetail.FieldTotalTokens, field.TypeUint64)
  810. }
  811. if value, ok := uduo.mutation.PromptTokens(); ok {
  812. _spec.SetField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
  813. }
  814. if value, ok := uduo.mutation.AddedPromptTokens(); ok {
  815. _spec.AddField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
  816. }
  817. if uduo.mutation.PromptTokensCleared() {
  818. _spec.ClearField(usagedetail.FieldPromptTokens, field.TypeUint64)
  819. }
  820. if value, ok := uduo.mutation.CompletionTokens(); ok {
  821. _spec.SetField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
  822. }
  823. if value, ok := uduo.mutation.AddedCompletionTokens(); ok {
  824. _spec.AddField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
  825. }
  826. if uduo.mutation.CompletionTokensCleared() {
  827. _spec.ClearField(usagedetail.FieldCompletionTokens, field.TypeUint64)
  828. }
  829. if value, ok := uduo.mutation.OrganizationID(); ok {
  830. _spec.SetField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
  831. }
  832. if value, ok := uduo.mutation.AddedOrganizationID(); ok {
  833. _spec.AddField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
  834. }
  835. if uduo.mutation.OrganizationIDCleared() {
  836. _spec.ClearField(usagedetail.FieldOrganizationID, field.TypeUint64)
  837. }
  838. _node = &UsageDetail{config: uduo.config}
  839. _spec.Assign = _node.assignValues
  840. _spec.ScanValues = _node.scanValues
  841. if err = sqlgraph.UpdateNode(ctx, uduo.driver, _spec); err != nil {
  842. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  843. err = &NotFoundError{usagedetail.Label}
  844. } else if sqlgraph.IsConstraintError(err) {
  845. err = &ConstraintError{msg: err.Error(), wrap: err}
  846. }
  847. return nil, err
  848. }
  849. uduo.mutation.done = true
  850. return _node, nil
  851. }