usagedetail_update.go 28 KB

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