usagedetail_update.go 31 KB

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