usagedetail_update.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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. // SetModel sets the "model" field.
  276. func (udu *UsageDetailUpdate) SetModel(s string) *UsageDetailUpdate {
  277. udu.mutation.SetModel(s)
  278. return udu
  279. }
  280. // SetNillableModel sets the "model" field if the given value is not nil.
  281. func (udu *UsageDetailUpdate) SetNillableModel(s *string) *UsageDetailUpdate {
  282. if s != nil {
  283. udu.SetModel(*s)
  284. }
  285. return udu
  286. }
  287. // ClearModel clears the value of the "model" field.
  288. func (udu *UsageDetailUpdate) ClearModel() *UsageDetailUpdate {
  289. udu.mutation.ClearModel()
  290. return udu
  291. }
  292. // SetCredits sets the "credits" field.
  293. func (udu *UsageDetailUpdate) SetCredits(f float64) *UsageDetailUpdate {
  294. udu.mutation.ResetCredits()
  295. udu.mutation.SetCredits(f)
  296. return udu
  297. }
  298. // SetNillableCredits sets the "credits" field if the given value is not nil.
  299. func (udu *UsageDetailUpdate) SetNillableCredits(f *float64) *UsageDetailUpdate {
  300. if f != nil {
  301. udu.SetCredits(*f)
  302. }
  303. return udu
  304. }
  305. // AddCredits adds f to the "credits" field.
  306. func (udu *UsageDetailUpdate) AddCredits(f float64) *UsageDetailUpdate {
  307. udu.mutation.AddCredits(f)
  308. return udu
  309. }
  310. // ClearCredits clears the value of the "credits" field.
  311. func (udu *UsageDetailUpdate) ClearCredits() *UsageDetailUpdate {
  312. udu.mutation.ClearCredits()
  313. return udu
  314. }
  315. // Mutation returns the UsageDetailMutation object of the builder.
  316. func (udu *UsageDetailUpdate) Mutation() *UsageDetailMutation {
  317. return udu.mutation
  318. }
  319. // Save executes the query and returns the number of nodes affected by the update operation.
  320. func (udu *UsageDetailUpdate) Save(ctx context.Context) (int, error) {
  321. udu.defaults()
  322. return withHooks(ctx, udu.sqlSave, udu.mutation, udu.hooks)
  323. }
  324. // SaveX is like Save, but panics if an error occurs.
  325. func (udu *UsageDetailUpdate) SaveX(ctx context.Context) int {
  326. affected, err := udu.Save(ctx)
  327. if err != nil {
  328. panic(err)
  329. }
  330. return affected
  331. }
  332. // Exec executes the query.
  333. func (udu *UsageDetailUpdate) Exec(ctx context.Context) error {
  334. _, err := udu.Save(ctx)
  335. return err
  336. }
  337. // ExecX is like Exec, but panics if an error occurs.
  338. func (udu *UsageDetailUpdate) ExecX(ctx context.Context) {
  339. if err := udu.Exec(ctx); err != nil {
  340. panic(err)
  341. }
  342. }
  343. // defaults sets the default values of the builder before save.
  344. func (udu *UsageDetailUpdate) defaults() {
  345. if _, ok := udu.mutation.UpdatedAt(); !ok {
  346. v := usagedetail.UpdateDefaultUpdatedAt()
  347. udu.mutation.SetUpdatedAt(v)
  348. }
  349. }
  350. func (udu *UsageDetailUpdate) sqlSave(ctx context.Context) (n int, err error) {
  351. _spec := sqlgraph.NewUpdateSpec(usagedetail.Table, usagedetail.Columns, sqlgraph.NewFieldSpec(usagedetail.FieldID, field.TypeUint64))
  352. if ps := udu.mutation.predicates; len(ps) > 0 {
  353. _spec.Predicate = func(selector *sql.Selector) {
  354. for i := range ps {
  355. ps[i](selector)
  356. }
  357. }
  358. }
  359. if value, ok := udu.mutation.UpdatedAt(); ok {
  360. _spec.SetField(usagedetail.FieldUpdatedAt, field.TypeTime, value)
  361. }
  362. if value, ok := udu.mutation.Status(); ok {
  363. _spec.SetField(usagedetail.FieldStatus, field.TypeUint8, value)
  364. }
  365. if value, ok := udu.mutation.AddedStatus(); ok {
  366. _spec.AddField(usagedetail.FieldStatus, field.TypeUint8, value)
  367. }
  368. if udu.mutation.StatusCleared() {
  369. _spec.ClearField(usagedetail.FieldStatus, field.TypeUint8)
  370. }
  371. if value, ok := udu.mutation.GetType(); ok {
  372. _spec.SetField(usagedetail.FieldType, field.TypeInt, value)
  373. }
  374. if value, ok := udu.mutation.AddedType(); ok {
  375. _spec.AddField(usagedetail.FieldType, field.TypeInt, value)
  376. }
  377. if udu.mutation.TypeCleared() {
  378. _spec.ClearField(usagedetail.FieldType, field.TypeInt)
  379. }
  380. if value, ok := udu.mutation.BotID(); ok {
  381. _spec.SetField(usagedetail.FieldBotID, field.TypeString, value)
  382. }
  383. if value, ok := udu.mutation.ReceiverID(); ok {
  384. _spec.SetField(usagedetail.FieldReceiverID, field.TypeString, value)
  385. }
  386. if value, ok := udu.mutation.App(); ok {
  387. _spec.SetField(usagedetail.FieldApp, field.TypeInt, value)
  388. }
  389. if value, ok := udu.mutation.AddedApp(); ok {
  390. _spec.AddField(usagedetail.FieldApp, field.TypeInt, value)
  391. }
  392. if udu.mutation.AppCleared() {
  393. _spec.ClearField(usagedetail.FieldApp, field.TypeInt)
  394. }
  395. if value, ok := udu.mutation.SessionID(); ok {
  396. _spec.SetField(usagedetail.FieldSessionID, field.TypeUint64, value)
  397. }
  398. if value, ok := udu.mutation.AddedSessionID(); ok {
  399. _spec.AddField(usagedetail.FieldSessionID, field.TypeUint64, value)
  400. }
  401. if udu.mutation.SessionIDCleared() {
  402. _spec.ClearField(usagedetail.FieldSessionID, field.TypeUint64)
  403. }
  404. if value, ok := udu.mutation.Request(); ok {
  405. _spec.SetField(usagedetail.FieldRequest, field.TypeString, value)
  406. }
  407. if value, ok := udu.mutation.Response(); ok {
  408. _spec.SetField(usagedetail.FieldResponse, field.TypeString, value)
  409. }
  410. if value, ok := udu.mutation.OriginalData(); ok {
  411. _spec.SetField(usagedetail.FieldOriginalData, field.TypeJSON, value)
  412. }
  413. if value, ok := udu.mutation.TotalTokens(); ok {
  414. _spec.SetField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
  415. }
  416. if value, ok := udu.mutation.AddedTotalTokens(); ok {
  417. _spec.AddField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
  418. }
  419. if udu.mutation.TotalTokensCleared() {
  420. _spec.ClearField(usagedetail.FieldTotalTokens, field.TypeUint64)
  421. }
  422. if value, ok := udu.mutation.PromptTokens(); ok {
  423. _spec.SetField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
  424. }
  425. if value, ok := udu.mutation.AddedPromptTokens(); ok {
  426. _spec.AddField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
  427. }
  428. if udu.mutation.PromptTokensCleared() {
  429. _spec.ClearField(usagedetail.FieldPromptTokens, field.TypeUint64)
  430. }
  431. if value, ok := udu.mutation.CompletionTokens(); ok {
  432. _spec.SetField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
  433. }
  434. if value, ok := udu.mutation.AddedCompletionTokens(); ok {
  435. _spec.AddField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
  436. }
  437. if udu.mutation.CompletionTokensCleared() {
  438. _spec.ClearField(usagedetail.FieldCompletionTokens, field.TypeUint64)
  439. }
  440. if value, ok := udu.mutation.OrganizationID(); ok {
  441. _spec.SetField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
  442. }
  443. if value, ok := udu.mutation.AddedOrganizationID(); ok {
  444. _spec.AddField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
  445. }
  446. if udu.mutation.OrganizationIDCleared() {
  447. _spec.ClearField(usagedetail.FieldOrganizationID, field.TypeUint64)
  448. }
  449. if value, ok := udu.mutation.Model(); ok {
  450. _spec.SetField(usagedetail.FieldModel, field.TypeString, value)
  451. }
  452. if udu.mutation.ModelCleared() {
  453. _spec.ClearField(usagedetail.FieldModel, field.TypeString)
  454. }
  455. if value, ok := udu.mutation.Credits(); ok {
  456. _spec.SetField(usagedetail.FieldCredits, field.TypeFloat64, value)
  457. }
  458. if value, ok := udu.mutation.AddedCredits(); ok {
  459. _spec.AddField(usagedetail.FieldCredits, field.TypeFloat64, value)
  460. }
  461. if udu.mutation.CreditsCleared() {
  462. _spec.ClearField(usagedetail.FieldCredits, field.TypeFloat64)
  463. }
  464. if n, err = sqlgraph.UpdateNodes(ctx, udu.driver, _spec); err != nil {
  465. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  466. err = &NotFoundError{usagedetail.Label}
  467. } else if sqlgraph.IsConstraintError(err) {
  468. err = &ConstraintError{msg: err.Error(), wrap: err}
  469. }
  470. return 0, err
  471. }
  472. udu.mutation.done = true
  473. return n, nil
  474. }
  475. // UsageDetailUpdateOne is the builder for updating a single UsageDetail entity.
  476. type UsageDetailUpdateOne struct {
  477. config
  478. fields []string
  479. hooks []Hook
  480. mutation *UsageDetailMutation
  481. }
  482. // SetUpdatedAt sets the "updated_at" field.
  483. func (uduo *UsageDetailUpdateOne) SetUpdatedAt(t time.Time) *UsageDetailUpdateOne {
  484. uduo.mutation.SetUpdatedAt(t)
  485. return uduo
  486. }
  487. // SetStatus sets the "status" field.
  488. func (uduo *UsageDetailUpdateOne) SetStatus(u uint8) *UsageDetailUpdateOne {
  489. uduo.mutation.ResetStatus()
  490. uduo.mutation.SetStatus(u)
  491. return uduo
  492. }
  493. // SetNillableStatus sets the "status" field if the given value is not nil.
  494. func (uduo *UsageDetailUpdateOne) SetNillableStatus(u *uint8) *UsageDetailUpdateOne {
  495. if u != nil {
  496. uduo.SetStatus(*u)
  497. }
  498. return uduo
  499. }
  500. // AddStatus adds u to the "status" field.
  501. func (uduo *UsageDetailUpdateOne) AddStatus(u int8) *UsageDetailUpdateOne {
  502. uduo.mutation.AddStatus(u)
  503. return uduo
  504. }
  505. // ClearStatus clears the value of the "status" field.
  506. func (uduo *UsageDetailUpdateOne) ClearStatus() *UsageDetailUpdateOne {
  507. uduo.mutation.ClearStatus()
  508. return uduo
  509. }
  510. // SetType sets the "type" field.
  511. func (uduo *UsageDetailUpdateOne) SetType(i int) *UsageDetailUpdateOne {
  512. uduo.mutation.ResetType()
  513. uduo.mutation.SetType(i)
  514. return uduo
  515. }
  516. // SetNillableType sets the "type" field if the given value is not nil.
  517. func (uduo *UsageDetailUpdateOne) SetNillableType(i *int) *UsageDetailUpdateOne {
  518. if i != nil {
  519. uduo.SetType(*i)
  520. }
  521. return uduo
  522. }
  523. // AddType adds i to the "type" field.
  524. func (uduo *UsageDetailUpdateOne) AddType(i int) *UsageDetailUpdateOne {
  525. uduo.mutation.AddType(i)
  526. return uduo
  527. }
  528. // ClearType clears the value of the "type" field.
  529. func (uduo *UsageDetailUpdateOne) ClearType() *UsageDetailUpdateOne {
  530. uduo.mutation.ClearType()
  531. return uduo
  532. }
  533. // SetBotID sets the "bot_id" field.
  534. func (uduo *UsageDetailUpdateOne) SetBotID(s string) *UsageDetailUpdateOne {
  535. uduo.mutation.SetBotID(s)
  536. return uduo
  537. }
  538. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  539. func (uduo *UsageDetailUpdateOne) SetNillableBotID(s *string) *UsageDetailUpdateOne {
  540. if s != nil {
  541. uduo.SetBotID(*s)
  542. }
  543. return uduo
  544. }
  545. // SetReceiverID sets the "receiver_id" field.
  546. func (uduo *UsageDetailUpdateOne) SetReceiverID(s string) *UsageDetailUpdateOne {
  547. uduo.mutation.SetReceiverID(s)
  548. return uduo
  549. }
  550. // SetNillableReceiverID sets the "receiver_id" field if the given value is not nil.
  551. func (uduo *UsageDetailUpdateOne) SetNillableReceiverID(s *string) *UsageDetailUpdateOne {
  552. if s != nil {
  553. uduo.SetReceiverID(*s)
  554. }
  555. return uduo
  556. }
  557. // SetApp sets the "app" field.
  558. func (uduo *UsageDetailUpdateOne) SetApp(i int) *UsageDetailUpdateOne {
  559. uduo.mutation.ResetApp()
  560. uduo.mutation.SetApp(i)
  561. return uduo
  562. }
  563. // SetNillableApp sets the "app" field if the given value is not nil.
  564. func (uduo *UsageDetailUpdateOne) SetNillableApp(i *int) *UsageDetailUpdateOne {
  565. if i != nil {
  566. uduo.SetApp(*i)
  567. }
  568. return uduo
  569. }
  570. // AddApp adds i to the "app" field.
  571. func (uduo *UsageDetailUpdateOne) AddApp(i int) *UsageDetailUpdateOne {
  572. uduo.mutation.AddApp(i)
  573. return uduo
  574. }
  575. // ClearApp clears the value of the "app" field.
  576. func (uduo *UsageDetailUpdateOne) ClearApp() *UsageDetailUpdateOne {
  577. uduo.mutation.ClearApp()
  578. return uduo
  579. }
  580. // SetSessionID sets the "session_id" field.
  581. func (uduo *UsageDetailUpdateOne) SetSessionID(u uint64) *UsageDetailUpdateOne {
  582. uduo.mutation.ResetSessionID()
  583. uduo.mutation.SetSessionID(u)
  584. return uduo
  585. }
  586. // SetNillableSessionID sets the "session_id" field if the given value is not nil.
  587. func (uduo *UsageDetailUpdateOne) SetNillableSessionID(u *uint64) *UsageDetailUpdateOne {
  588. if u != nil {
  589. uduo.SetSessionID(*u)
  590. }
  591. return uduo
  592. }
  593. // AddSessionID adds u to the "session_id" field.
  594. func (uduo *UsageDetailUpdateOne) AddSessionID(u int64) *UsageDetailUpdateOne {
  595. uduo.mutation.AddSessionID(u)
  596. return uduo
  597. }
  598. // ClearSessionID clears the value of the "session_id" field.
  599. func (uduo *UsageDetailUpdateOne) ClearSessionID() *UsageDetailUpdateOne {
  600. uduo.mutation.ClearSessionID()
  601. return uduo
  602. }
  603. // SetRequest sets the "request" field.
  604. func (uduo *UsageDetailUpdateOne) SetRequest(s string) *UsageDetailUpdateOne {
  605. uduo.mutation.SetRequest(s)
  606. return uduo
  607. }
  608. // SetNillableRequest sets the "request" field if the given value is not nil.
  609. func (uduo *UsageDetailUpdateOne) SetNillableRequest(s *string) *UsageDetailUpdateOne {
  610. if s != nil {
  611. uduo.SetRequest(*s)
  612. }
  613. return uduo
  614. }
  615. // SetResponse sets the "response" field.
  616. func (uduo *UsageDetailUpdateOne) SetResponse(s string) *UsageDetailUpdateOne {
  617. uduo.mutation.SetResponse(s)
  618. return uduo
  619. }
  620. // SetNillableResponse sets the "response" field if the given value is not nil.
  621. func (uduo *UsageDetailUpdateOne) SetNillableResponse(s *string) *UsageDetailUpdateOne {
  622. if s != nil {
  623. uduo.SetResponse(*s)
  624. }
  625. return uduo
  626. }
  627. // SetOriginalData sets the "original_data" field.
  628. func (uduo *UsageDetailUpdateOne) SetOriginalData(ctd custom_types.OriginalData) *UsageDetailUpdateOne {
  629. uduo.mutation.SetOriginalData(ctd)
  630. return uduo
  631. }
  632. // SetNillableOriginalData sets the "original_data" field if the given value is not nil.
  633. func (uduo *UsageDetailUpdateOne) SetNillableOriginalData(ctd *custom_types.OriginalData) *UsageDetailUpdateOne {
  634. if ctd != nil {
  635. uduo.SetOriginalData(*ctd)
  636. }
  637. return uduo
  638. }
  639. // SetTotalTokens sets the "total_tokens" field.
  640. func (uduo *UsageDetailUpdateOne) SetTotalTokens(u uint64) *UsageDetailUpdateOne {
  641. uduo.mutation.ResetTotalTokens()
  642. uduo.mutation.SetTotalTokens(u)
  643. return uduo
  644. }
  645. // SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil.
  646. func (uduo *UsageDetailUpdateOne) SetNillableTotalTokens(u *uint64) *UsageDetailUpdateOne {
  647. if u != nil {
  648. uduo.SetTotalTokens(*u)
  649. }
  650. return uduo
  651. }
  652. // AddTotalTokens adds u to the "total_tokens" field.
  653. func (uduo *UsageDetailUpdateOne) AddTotalTokens(u int64) *UsageDetailUpdateOne {
  654. uduo.mutation.AddTotalTokens(u)
  655. return uduo
  656. }
  657. // ClearTotalTokens clears the value of the "total_tokens" field.
  658. func (uduo *UsageDetailUpdateOne) ClearTotalTokens() *UsageDetailUpdateOne {
  659. uduo.mutation.ClearTotalTokens()
  660. return uduo
  661. }
  662. // SetPromptTokens sets the "prompt_tokens" field.
  663. func (uduo *UsageDetailUpdateOne) SetPromptTokens(u uint64) *UsageDetailUpdateOne {
  664. uduo.mutation.ResetPromptTokens()
  665. uduo.mutation.SetPromptTokens(u)
  666. return uduo
  667. }
  668. // SetNillablePromptTokens sets the "prompt_tokens" field if the given value is not nil.
  669. func (uduo *UsageDetailUpdateOne) SetNillablePromptTokens(u *uint64) *UsageDetailUpdateOne {
  670. if u != nil {
  671. uduo.SetPromptTokens(*u)
  672. }
  673. return uduo
  674. }
  675. // AddPromptTokens adds u to the "prompt_tokens" field.
  676. func (uduo *UsageDetailUpdateOne) AddPromptTokens(u int64) *UsageDetailUpdateOne {
  677. uduo.mutation.AddPromptTokens(u)
  678. return uduo
  679. }
  680. // ClearPromptTokens clears the value of the "prompt_tokens" field.
  681. func (uduo *UsageDetailUpdateOne) ClearPromptTokens() *UsageDetailUpdateOne {
  682. uduo.mutation.ClearPromptTokens()
  683. return uduo
  684. }
  685. // SetCompletionTokens sets the "completion_tokens" field.
  686. func (uduo *UsageDetailUpdateOne) SetCompletionTokens(u uint64) *UsageDetailUpdateOne {
  687. uduo.mutation.ResetCompletionTokens()
  688. uduo.mutation.SetCompletionTokens(u)
  689. return uduo
  690. }
  691. // SetNillableCompletionTokens sets the "completion_tokens" field if the given value is not nil.
  692. func (uduo *UsageDetailUpdateOne) SetNillableCompletionTokens(u *uint64) *UsageDetailUpdateOne {
  693. if u != nil {
  694. uduo.SetCompletionTokens(*u)
  695. }
  696. return uduo
  697. }
  698. // AddCompletionTokens adds u to the "completion_tokens" field.
  699. func (uduo *UsageDetailUpdateOne) AddCompletionTokens(u int64) *UsageDetailUpdateOne {
  700. uduo.mutation.AddCompletionTokens(u)
  701. return uduo
  702. }
  703. // ClearCompletionTokens clears the value of the "completion_tokens" field.
  704. func (uduo *UsageDetailUpdateOne) ClearCompletionTokens() *UsageDetailUpdateOne {
  705. uduo.mutation.ClearCompletionTokens()
  706. return uduo
  707. }
  708. // SetOrganizationID sets the "organization_id" field.
  709. func (uduo *UsageDetailUpdateOne) SetOrganizationID(u uint64) *UsageDetailUpdateOne {
  710. uduo.mutation.ResetOrganizationID()
  711. uduo.mutation.SetOrganizationID(u)
  712. return uduo
  713. }
  714. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  715. func (uduo *UsageDetailUpdateOne) SetNillableOrganizationID(u *uint64) *UsageDetailUpdateOne {
  716. if u != nil {
  717. uduo.SetOrganizationID(*u)
  718. }
  719. return uduo
  720. }
  721. // AddOrganizationID adds u to the "organization_id" field.
  722. func (uduo *UsageDetailUpdateOne) AddOrganizationID(u int64) *UsageDetailUpdateOne {
  723. uduo.mutation.AddOrganizationID(u)
  724. return uduo
  725. }
  726. // ClearOrganizationID clears the value of the "organization_id" field.
  727. func (uduo *UsageDetailUpdateOne) ClearOrganizationID() *UsageDetailUpdateOne {
  728. uduo.mutation.ClearOrganizationID()
  729. return uduo
  730. }
  731. // SetModel sets the "model" field.
  732. func (uduo *UsageDetailUpdateOne) SetModel(s string) *UsageDetailUpdateOne {
  733. uduo.mutation.SetModel(s)
  734. return uduo
  735. }
  736. // SetNillableModel sets the "model" field if the given value is not nil.
  737. func (uduo *UsageDetailUpdateOne) SetNillableModel(s *string) *UsageDetailUpdateOne {
  738. if s != nil {
  739. uduo.SetModel(*s)
  740. }
  741. return uduo
  742. }
  743. // ClearModel clears the value of the "model" field.
  744. func (uduo *UsageDetailUpdateOne) ClearModel() *UsageDetailUpdateOne {
  745. uduo.mutation.ClearModel()
  746. return uduo
  747. }
  748. // SetCredits sets the "credits" field.
  749. func (uduo *UsageDetailUpdateOne) SetCredits(f float64) *UsageDetailUpdateOne {
  750. uduo.mutation.ResetCredits()
  751. uduo.mutation.SetCredits(f)
  752. return uduo
  753. }
  754. // SetNillableCredits sets the "credits" field if the given value is not nil.
  755. func (uduo *UsageDetailUpdateOne) SetNillableCredits(f *float64) *UsageDetailUpdateOne {
  756. if f != nil {
  757. uduo.SetCredits(*f)
  758. }
  759. return uduo
  760. }
  761. // AddCredits adds f to the "credits" field.
  762. func (uduo *UsageDetailUpdateOne) AddCredits(f float64) *UsageDetailUpdateOne {
  763. uduo.mutation.AddCredits(f)
  764. return uduo
  765. }
  766. // ClearCredits clears the value of the "credits" field.
  767. func (uduo *UsageDetailUpdateOne) ClearCredits() *UsageDetailUpdateOne {
  768. uduo.mutation.ClearCredits()
  769. return uduo
  770. }
  771. // Mutation returns the UsageDetailMutation object of the builder.
  772. func (uduo *UsageDetailUpdateOne) Mutation() *UsageDetailMutation {
  773. return uduo.mutation
  774. }
  775. // Where appends a list predicates to the UsageDetailUpdate builder.
  776. func (uduo *UsageDetailUpdateOne) Where(ps ...predicate.UsageDetail) *UsageDetailUpdateOne {
  777. uduo.mutation.Where(ps...)
  778. return uduo
  779. }
  780. // Select allows selecting one or more fields (columns) of the returned entity.
  781. // The default is selecting all fields defined in the entity schema.
  782. func (uduo *UsageDetailUpdateOne) Select(field string, fields ...string) *UsageDetailUpdateOne {
  783. uduo.fields = append([]string{field}, fields...)
  784. return uduo
  785. }
  786. // Save executes the query and returns the updated UsageDetail entity.
  787. func (uduo *UsageDetailUpdateOne) Save(ctx context.Context) (*UsageDetail, error) {
  788. uduo.defaults()
  789. return withHooks(ctx, uduo.sqlSave, uduo.mutation, uduo.hooks)
  790. }
  791. // SaveX is like Save, but panics if an error occurs.
  792. func (uduo *UsageDetailUpdateOne) SaveX(ctx context.Context) *UsageDetail {
  793. node, err := uduo.Save(ctx)
  794. if err != nil {
  795. panic(err)
  796. }
  797. return node
  798. }
  799. // Exec executes the query on the entity.
  800. func (uduo *UsageDetailUpdateOne) Exec(ctx context.Context) error {
  801. _, err := uduo.Save(ctx)
  802. return err
  803. }
  804. // ExecX is like Exec, but panics if an error occurs.
  805. func (uduo *UsageDetailUpdateOne) ExecX(ctx context.Context) {
  806. if err := uduo.Exec(ctx); err != nil {
  807. panic(err)
  808. }
  809. }
  810. // defaults sets the default values of the builder before save.
  811. func (uduo *UsageDetailUpdateOne) defaults() {
  812. if _, ok := uduo.mutation.UpdatedAt(); !ok {
  813. v := usagedetail.UpdateDefaultUpdatedAt()
  814. uduo.mutation.SetUpdatedAt(v)
  815. }
  816. }
  817. func (uduo *UsageDetailUpdateOne) sqlSave(ctx context.Context) (_node *UsageDetail, err error) {
  818. _spec := sqlgraph.NewUpdateSpec(usagedetail.Table, usagedetail.Columns, sqlgraph.NewFieldSpec(usagedetail.FieldID, field.TypeUint64))
  819. id, ok := uduo.mutation.ID()
  820. if !ok {
  821. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageDetail.id" for update`)}
  822. }
  823. _spec.Node.ID.Value = id
  824. if fields := uduo.fields; len(fields) > 0 {
  825. _spec.Node.Columns = make([]string, 0, len(fields))
  826. _spec.Node.Columns = append(_spec.Node.Columns, usagedetail.FieldID)
  827. for _, f := range fields {
  828. if !usagedetail.ValidColumn(f) {
  829. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  830. }
  831. if f != usagedetail.FieldID {
  832. _spec.Node.Columns = append(_spec.Node.Columns, f)
  833. }
  834. }
  835. }
  836. if ps := uduo.mutation.predicates; len(ps) > 0 {
  837. _spec.Predicate = func(selector *sql.Selector) {
  838. for i := range ps {
  839. ps[i](selector)
  840. }
  841. }
  842. }
  843. if value, ok := uduo.mutation.UpdatedAt(); ok {
  844. _spec.SetField(usagedetail.FieldUpdatedAt, field.TypeTime, value)
  845. }
  846. if value, ok := uduo.mutation.Status(); ok {
  847. _spec.SetField(usagedetail.FieldStatus, field.TypeUint8, value)
  848. }
  849. if value, ok := uduo.mutation.AddedStatus(); ok {
  850. _spec.AddField(usagedetail.FieldStatus, field.TypeUint8, value)
  851. }
  852. if uduo.mutation.StatusCleared() {
  853. _spec.ClearField(usagedetail.FieldStatus, field.TypeUint8)
  854. }
  855. if value, ok := uduo.mutation.GetType(); ok {
  856. _spec.SetField(usagedetail.FieldType, field.TypeInt, value)
  857. }
  858. if value, ok := uduo.mutation.AddedType(); ok {
  859. _spec.AddField(usagedetail.FieldType, field.TypeInt, value)
  860. }
  861. if uduo.mutation.TypeCleared() {
  862. _spec.ClearField(usagedetail.FieldType, field.TypeInt)
  863. }
  864. if value, ok := uduo.mutation.BotID(); ok {
  865. _spec.SetField(usagedetail.FieldBotID, field.TypeString, value)
  866. }
  867. if value, ok := uduo.mutation.ReceiverID(); ok {
  868. _spec.SetField(usagedetail.FieldReceiverID, field.TypeString, value)
  869. }
  870. if value, ok := uduo.mutation.App(); ok {
  871. _spec.SetField(usagedetail.FieldApp, field.TypeInt, value)
  872. }
  873. if value, ok := uduo.mutation.AddedApp(); ok {
  874. _spec.AddField(usagedetail.FieldApp, field.TypeInt, value)
  875. }
  876. if uduo.mutation.AppCleared() {
  877. _spec.ClearField(usagedetail.FieldApp, field.TypeInt)
  878. }
  879. if value, ok := uduo.mutation.SessionID(); ok {
  880. _spec.SetField(usagedetail.FieldSessionID, field.TypeUint64, value)
  881. }
  882. if value, ok := uduo.mutation.AddedSessionID(); ok {
  883. _spec.AddField(usagedetail.FieldSessionID, field.TypeUint64, value)
  884. }
  885. if uduo.mutation.SessionIDCleared() {
  886. _spec.ClearField(usagedetail.FieldSessionID, field.TypeUint64)
  887. }
  888. if value, ok := uduo.mutation.Request(); ok {
  889. _spec.SetField(usagedetail.FieldRequest, field.TypeString, value)
  890. }
  891. if value, ok := uduo.mutation.Response(); ok {
  892. _spec.SetField(usagedetail.FieldResponse, field.TypeString, value)
  893. }
  894. if value, ok := uduo.mutation.OriginalData(); ok {
  895. _spec.SetField(usagedetail.FieldOriginalData, field.TypeJSON, value)
  896. }
  897. if value, ok := uduo.mutation.TotalTokens(); ok {
  898. _spec.SetField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
  899. }
  900. if value, ok := uduo.mutation.AddedTotalTokens(); ok {
  901. _spec.AddField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
  902. }
  903. if uduo.mutation.TotalTokensCleared() {
  904. _spec.ClearField(usagedetail.FieldTotalTokens, field.TypeUint64)
  905. }
  906. if value, ok := uduo.mutation.PromptTokens(); ok {
  907. _spec.SetField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
  908. }
  909. if value, ok := uduo.mutation.AddedPromptTokens(); ok {
  910. _spec.AddField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
  911. }
  912. if uduo.mutation.PromptTokensCleared() {
  913. _spec.ClearField(usagedetail.FieldPromptTokens, field.TypeUint64)
  914. }
  915. if value, ok := uduo.mutation.CompletionTokens(); ok {
  916. _spec.SetField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
  917. }
  918. if value, ok := uduo.mutation.AddedCompletionTokens(); ok {
  919. _spec.AddField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
  920. }
  921. if uduo.mutation.CompletionTokensCleared() {
  922. _spec.ClearField(usagedetail.FieldCompletionTokens, field.TypeUint64)
  923. }
  924. if value, ok := uduo.mutation.OrganizationID(); ok {
  925. _spec.SetField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
  926. }
  927. if value, ok := uduo.mutation.AddedOrganizationID(); ok {
  928. _spec.AddField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
  929. }
  930. if uduo.mutation.OrganizationIDCleared() {
  931. _spec.ClearField(usagedetail.FieldOrganizationID, field.TypeUint64)
  932. }
  933. if value, ok := uduo.mutation.Model(); ok {
  934. _spec.SetField(usagedetail.FieldModel, field.TypeString, value)
  935. }
  936. if uduo.mutation.ModelCleared() {
  937. _spec.ClearField(usagedetail.FieldModel, field.TypeString)
  938. }
  939. if value, ok := uduo.mutation.Credits(); ok {
  940. _spec.SetField(usagedetail.FieldCredits, field.TypeFloat64, value)
  941. }
  942. if value, ok := uduo.mutation.AddedCredits(); ok {
  943. _spec.AddField(usagedetail.FieldCredits, field.TypeFloat64, value)
  944. }
  945. if uduo.mutation.CreditsCleared() {
  946. _spec.ClearField(usagedetail.FieldCredits, field.TypeFloat64)
  947. }
  948. _node = &UsageDetail{config: uduo.config}
  949. _spec.Assign = _node.assignValues
  950. _spec.ScanValues = _node.scanValues
  951. if err = sqlgraph.UpdateNode(ctx, uduo.driver, _spec); err != nil {
  952. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  953. err = &NotFoundError{usagedetail.Label}
  954. } else if sqlgraph.IsConstraintError(err) {
  955. err = &ConstraintError{msg: err.Error(), wrap: err}
  956. }
  957. return nil, err
  958. }
  959. uduo.mutation.done = true
  960. return _node, nil
  961. }