usagetotal_update.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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/usagetotal"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // UsageTotalUpdate is the builder for updating UsageTotal entities.
  15. type UsageTotalUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *UsageTotalMutation
  19. }
  20. // Where appends a list predicates to the UsageTotalUpdate builder.
  21. func (utu *UsageTotalUpdate) Where(ps ...predicate.UsageTotal) *UsageTotalUpdate {
  22. utu.mutation.Where(ps...)
  23. return utu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (utu *UsageTotalUpdate) SetUpdatedAt(t time.Time) *UsageTotalUpdate {
  27. utu.mutation.SetUpdatedAt(t)
  28. return utu
  29. }
  30. // SetStatus sets the "status" field.
  31. func (utu *UsageTotalUpdate) SetStatus(u uint8) *UsageTotalUpdate {
  32. utu.mutation.ResetStatus()
  33. utu.mutation.SetStatus(u)
  34. return utu
  35. }
  36. // SetNillableStatus sets the "status" field if the given value is not nil.
  37. func (utu *UsageTotalUpdate) SetNillableStatus(u *uint8) *UsageTotalUpdate {
  38. if u != nil {
  39. utu.SetStatus(*u)
  40. }
  41. return utu
  42. }
  43. // AddStatus adds u to the "status" field.
  44. func (utu *UsageTotalUpdate) AddStatus(u int8) *UsageTotalUpdate {
  45. utu.mutation.AddStatus(u)
  46. return utu
  47. }
  48. // ClearStatus clears the value of the "status" field.
  49. func (utu *UsageTotalUpdate) ClearStatus() *UsageTotalUpdate {
  50. utu.mutation.ClearStatus()
  51. return utu
  52. }
  53. // SetType sets the "type" field.
  54. func (utu *UsageTotalUpdate) SetType(i int) *UsageTotalUpdate {
  55. utu.mutation.ResetType()
  56. utu.mutation.SetType(i)
  57. return utu
  58. }
  59. // SetNillableType sets the "type" field if the given value is not nil.
  60. func (utu *UsageTotalUpdate) SetNillableType(i *int) *UsageTotalUpdate {
  61. if i != nil {
  62. utu.SetType(*i)
  63. }
  64. return utu
  65. }
  66. // AddType adds i to the "type" field.
  67. func (utu *UsageTotalUpdate) AddType(i int) *UsageTotalUpdate {
  68. utu.mutation.AddType(i)
  69. return utu
  70. }
  71. // ClearType clears the value of the "type" field.
  72. func (utu *UsageTotalUpdate) ClearType() *UsageTotalUpdate {
  73. utu.mutation.ClearType()
  74. return utu
  75. }
  76. // SetBotID sets the "bot_id" field.
  77. func (utu *UsageTotalUpdate) SetBotID(s string) *UsageTotalUpdate {
  78. utu.mutation.SetBotID(s)
  79. return utu
  80. }
  81. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  82. func (utu *UsageTotalUpdate) SetNillableBotID(s *string) *UsageTotalUpdate {
  83. if s != nil {
  84. utu.SetBotID(*s)
  85. }
  86. return utu
  87. }
  88. // SetTotalTokens sets the "total_tokens" field.
  89. func (utu *UsageTotalUpdate) SetTotalTokens(u uint64) *UsageTotalUpdate {
  90. utu.mutation.ResetTotalTokens()
  91. utu.mutation.SetTotalTokens(u)
  92. return utu
  93. }
  94. // SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil.
  95. func (utu *UsageTotalUpdate) SetNillableTotalTokens(u *uint64) *UsageTotalUpdate {
  96. if u != nil {
  97. utu.SetTotalTokens(*u)
  98. }
  99. return utu
  100. }
  101. // AddTotalTokens adds u to the "total_tokens" field.
  102. func (utu *UsageTotalUpdate) AddTotalTokens(u int64) *UsageTotalUpdate {
  103. utu.mutation.AddTotalTokens(u)
  104. return utu
  105. }
  106. // ClearTotalTokens clears the value of the "total_tokens" field.
  107. func (utu *UsageTotalUpdate) ClearTotalTokens() *UsageTotalUpdate {
  108. utu.mutation.ClearTotalTokens()
  109. return utu
  110. }
  111. // SetCredits sets the "credits" field.
  112. func (utu *UsageTotalUpdate) SetCredits(f float64) *UsageTotalUpdate {
  113. utu.mutation.ResetCredits()
  114. utu.mutation.SetCredits(f)
  115. return utu
  116. }
  117. // SetNillableCredits sets the "credits" field if the given value is not nil.
  118. func (utu *UsageTotalUpdate) SetNillableCredits(f *float64) *UsageTotalUpdate {
  119. if f != nil {
  120. utu.SetCredits(*f)
  121. }
  122. return utu
  123. }
  124. // AddCredits adds f to the "credits" field.
  125. func (utu *UsageTotalUpdate) AddCredits(f float64) *UsageTotalUpdate {
  126. utu.mutation.AddCredits(f)
  127. return utu
  128. }
  129. // ClearCredits clears the value of the "credits" field.
  130. func (utu *UsageTotalUpdate) ClearCredits() *UsageTotalUpdate {
  131. utu.mutation.ClearCredits()
  132. return utu
  133. }
  134. // SetStartIndex sets the "start_index" field.
  135. func (utu *UsageTotalUpdate) SetStartIndex(u uint64) *UsageTotalUpdate {
  136. utu.mutation.ResetStartIndex()
  137. utu.mutation.SetStartIndex(u)
  138. return utu
  139. }
  140. // SetNillableStartIndex sets the "start_index" field if the given value is not nil.
  141. func (utu *UsageTotalUpdate) SetNillableStartIndex(u *uint64) *UsageTotalUpdate {
  142. if u != nil {
  143. utu.SetStartIndex(*u)
  144. }
  145. return utu
  146. }
  147. // AddStartIndex adds u to the "start_index" field.
  148. func (utu *UsageTotalUpdate) AddStartIndex(u int64) *UsageTotalUpdate {
  149. utu.mutation.AddStartIndex(u)
  150. return utu
  151. }
  152. // ClearStartIndex clears the value of the "start_index" field.
  153. func (utu *UsageTotalUpdate) ClearStartIndex() *UsageTotalUpdate {
  154. utu.mutation.ClearStartIndex()
  155. return utu
  156. }
  157. // SetEndIndex sets the "end_index" field.
  158. func (utu *UsageTotalUpdate) SetEndIndex(u uint64) *UsageTotalUpdate {
  159. utu.mutation.ResetEndIndex()
  160. utu.mutation.SetEndIndex(u)
  161. return utu
  162. }
  163. // SetNillableEndIndex sets the "end_index" field if the given value is not nil.
  164. func (utu *UsageTotalUpdate) SetNillableEndIndex(u *uint64) *UsageTotalUpdate {
  165. if u != nil {
  166. utu.SetEndIndex(*u)
  167. }
  168. return utu
  169. }
  170. // AddEndIndex adds u to the "end_index" field.
  171. func (utu *UsageTotalUpdate) AddEndIndex(u int64) *UsageTotalUpdate {
  172. utu.mutation.AddEndIndex(u)
  173. return utu
  174. }
  175. // ClearEndIndex clears the value of the "end_index" field.
  176. func (utu *UsageTotalUpdate) ClearEndIndex() *UsageTotalUpdate {
  177. utu.mutation.ClearEndIndex()
  178. return utu
  179. }
  180. // SetOrganizationID sets the "organization_id" field.
  181. func (utu *UsageTotalUpdate) SetOrganizationID(u uint64) *UsageTotalUpdate {
  182. utu.mutation.ResetOrganizationID()
  183. utu.mutation.SetOrganizationID(u)
  184. return utu
  185. }
  186. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  187. func (utu *UsageTotalUpdate) SetNillableOrganizationID(u *uint64) *UsageTotalUpdate {
  188. if u != nil {
  189. utu.SetOrganizationID(*u)
  190. }
  191. return utu
  192. }
  193. // AddOrganizationID adds u to the "organization_id" field.
  194. func (utu *UsageTotalUpdate) AddOrganizationID(u int64) *UsageTotalUpdate {
  195. utu.mutation.AddOrganizationID(u)
  196. return utu
  197. }
  198. // ClearOrganizationID clears the value of the "organization_id" field.
  199. func (utu *UsageTotalUpdate) ClearOrganizationID() *UsageTotalUpdate {
  200. utu.mutation.ClearOrganizationID()
  201. return utu
  202. }
  203. // Mutation returns the UsageTotalMutation object of the builder.
  204. func (utu *UsageTotalUpdate) Mutation() *UsageTotalMutation {
  205. return utu.mutation
  206. }
  207. // Save executes the query and returns the number of nodes affected by the update operation.
  208. func (utu *UsageTotalUpdate) Save(ctx context.Context) (int, error) {
  209. utu.defaults()
  210. return withHooks(ctx, utu.sqlSave, utu.mutation, utu.hooks)
  211. }
  212. // SaveX is like Save, but panics if an error occurs.
  213. func (utu *UsageTotalUpdate) SaveX(ctx context.Context) int {
  214. affected, err := utu.Save(ctx)
  215. if err != nil {
  216. panic(err)
  217. }
  218. return affected
  219. }
  220. // Exec executes the query.
  221. func (utu *UsageTotalUpdate) Exec(ctx context.Context) error {
  222. _, err := utu.Save(ctx)
  223. return err
  224. }
  225. // ExecX is like Exec, but panics if an error occurs.
  226. func (utu *UsageTotalUpdate) ExecX(ctx context.Context) {
  227. if err := utu.Exec(ctx); err != nil {
  228. panic(err)
  229. }
  230. }
  231. // defaults sets the default values of the builder before save.
  232. func (utu *UsageTotalUpdate) defaults() {
  233. if _, ok := utu.mutation.UpdatedAt(); !ok {
  234. v := usagetotal.UpdateDefaultUpdatedAt()
  235. utu.mutation.SetUpdatedAt(v)
  236. }
  237. }
  238. func (utu *UsageTotalUpdate) sqlSave(ctx context.Context) (n int, err error) {
  239. _spec := sqlgraph.NewUpdateSpec(usagetotal.Table, usagetotal.Columns, sqlgraph.NewFieldSpec(usagetotal.FieldID, field.TypeUint64))
  240. if ps := utu.mutation.predicates; len(ps) > 0 {
  241. _spec.Predicate = func(selector *sql.Selector) {
  242. for i := range ps {
  243. ps[i](selector)
  244. }
  245. }
  246. }
  247. if value, ok := utu.mutation.UpdatedAt(); ok {
  248. _spec.SetField(usagetotal.FieldUpdatedAt, field.TypeTime, value)
  249. }
  250. if value, ok := utu.mutation.Status(); ok {
  251. _spec.SetField(usagetotal.FieldStatus, field.TypeUint8, value)
  252. }
  253. if value, ok := utu.mutation.AddedStatus(); ok {
  254. _spec.AddField(usagetotal.FieldStatus, field.TypeUint8, value)
  255. }
  256. if utu.mutation.StatusCleared() {
  257. _spec.ClearField(usagetotal.FieldStatus, field.TypeUint8)
  258. }
  259. if value, ok := utu.mutation.GetType(); ok {
  260. _spec.SetField(usagetotal.FieldType, field.TypeInt, value)
  261. }
  262. if value, ok := utu.mutation.AddedType(); ok {
  263. _spec.AddField(usagetotal.FieldType, field.TypeInt, value)
  264. }
  265. if utu.mutation.TypeCleared() {
  266. _spec.ClearField(usagetotal.FieldType, field.TypeInt)
  267. }
  268. if value, ok := utu.mutation.BotID(); ok {
  269. _spec.SetField(usagetotal.FieldBotID, field.TypeString, value)
  270. }
  271. if value, ok := utu.mutation.TotalTokens(); ok {
  272. _spec.SetField(usagetotal.FieldTotalTokens, field.TypeUint64, value)
  273. }
  274. if value, ok := utu.mutation.AddedTotalTokens(); ok {
  275. _spec.AddField(usagetotal.FieldTotalTokens, field.TypeUint64, value)
  276. }
  277. if utu.mutation.TotalTokensCleared() {
  278. _spec.ClearField(usagetotal.FieldTotalTokens, field.TypeUint64)
  279. }
  280. if value, ok := utu.mutation.Credits(); ok {
  281. _spec.SetField(usagetotal.FieldCredits, field.TypeFloat64, value)
  282. }
  283. if value, ok := utu.mutation.AddedCredits(); ok {
  284. _spec.AddField(usagetotal.FieldCredits, field.TypeFloat64, value)
  285. }
  286. if utu.mutation.CreditsCleared() {
  287. _spec.ClearField(usagetotal.FieldCredits, field.TypeFloat64)
  288. }
  289. if value, ok := utu.mutation.StartIndex(); ok {
  290. _spec.SetField(usagetotal.FieldStartIndex, field.TypeUint64, value)
  291. }
  292. if value, ok := utu.mutation.AddedStartIndex(); ok {
  293. _spec.AddField(usagetotal.FieldStartIndex, field.TypeUint64, value)
  294. }
  295. if utu.mutation.StartIndexCleared() {
  296. _spec.ClearField(usagetotal.FieldStartIndex, field.TypeUint64)
  297. }
  298. if value, ok := utu.mutation.EndIndex(); ok {
  299. _spec.SetField(usagetotal.FieldEndIndex, field.TypeUint64, value)
  300. }
  301. if value, ok := utu.mutation.AddedEndIndex(); ok {
  302. _spec.AddField(usagetotal.FieldEndIndex, field.TypeUint64, value)
  303. }
  304. if utu.mutation.EndIndexCleared() {
  305. _spec.ClearField(usagetotal.FieldEndIndex, field.TypeUint64)
  306. }
  307. if value, ok := utu.mutation.OrganizationID(); ok {
  308. _spec.SetField(usagetotal.FieldOrganizationID, field.TypeUint64, value)
  309. }
  310. if value, ok := utu.mutation.AddedOrganizationID(); ok {
  311. _spec.AddField(usagetotal.FieldOrganizationID, field.TypeUint64, value)
  312. }
  313. if utu.mutation.OrganizationIDCleared() {
  314. _spec.ClearField(usagetotal.FieldOrganizationID, field.TypeUint64)
  315. }
  316. if n, err = sqlgraph.UpdateNodes(ctx, utu.driver, _spec); err != nil {
  317. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  318. err = &NotFoundError{usagetotal.Label}
  319. } else if sqlgraph.IsConstraintError(err) {
  320. err = &ConstraintError{msg: err.Error(), wrap: err}
  321. }
  322. return 0, err
  323. }
  324. utu.mutation.done = true
  325. return n, nil
  326. }
  327. // UsageTotalUpdateOne is the builder for updating a single UsageTotal entity.
  328. type UsageTotalUpdateOne struct {
  329. config
  330. fields []string
  331. hooks []Hook
  332. mutation *UsageTotalMutation
  333. }
  334. // SetUpdatedAt sets the "updated_at" field.
  335. func (utuo *UsageTotalUpdateOne) SetUpdatedAt(t time.Time) *UsageTotalUpdateOne {
  336. utuo.mutation.SetUpdatedAt(t)
  337. return utuo
  338. }
  339. // SetStatus sets the "status" field.
  340. func (utuo *UsageTotalUpdateOne) SetStatus(u uint8) *UsageTotalUpdateOne {
  341. utuo.mutation.ResetStatus()
  342. utuo.mutation.SetStatus(u)
  343. return utuo
  344. }
  345. // SetNillableStatus sets the "status" field if the given value is not nil.
  346. func (utuo *UsageTotalUpdateOne) SetNillableStatus(u *uint8) *UsageTotalUpdateOne {
  347. if u != nil {
  348. utuo.SetStatus(*u)
  349. }
  350. return utuo
  351. }
  352. // AddStatus adds u to the "status" field.
  353. func (utuo *UsageTotalUpdateOne) AddStatus(u int8) *UsageTotalUpdateOne {
  354. utuo.mutation.AddStatus(u)
  355. return utuo
  356. }
  357. // ClearStatus clears the value of the "status" field.
  358. func (utuo *UsageTotalUpdateOne) ClearStatus() *UsageTotalUpdateOne {
  359. utuo.mutation.ClearStatus()
  360. return utuo
  361. }
  362. // SetType sets the "type" field.
  363. func (utuo *UsageTotalUpdateOne) SetType(i int) *UsageTotalUpdateOne {
  364. utuo.mutation.ResetType()
  365. utuo.mutation.SetType(i)
  366. return utuo
  367. }
  368. // SetNillableType sets the "type" field if the given value is not nil.
  369. func (utuo *UsageTotalUpdateOne) SetNillableType(i *int) *UsageTotalUpdateOne {
  370. if i != nil {
  371. utuo.SetType(*i)
  372. }
  373. return utuo
  374. }
  375. // AddType adds i to the "type" field.
  376. func (utuo *UsageTotalUpdateOne) AddType(i int) *UsageTotalUpdateOne {
  377. utuo.mutation.AddType(i)
  378. return utuo
  379. }
  380. // ClearType clears the value of the "type" field.
  381. func (utuo *UsageTotalUpdateOne) ClearType() *UsageTotalUpdateOne {
  382. utuo.mutation.ClearType()
  383. return utuo
  384. }
  385. // SetBotID sets the "bot_id" field.
  386. func (utuo *UsageTotalUpdateOne) SetBotID(s string) *UsageTotalUpdateOne {
  387. utuo.mutation.SetBotID(s)
  388. return utuo
  389. }
  390. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  391. func (utuo *UsageTotalUpdateOne) SetNillableBotID(s *string) *UsageTotalUpdateOne {
  392. if s != nil {
  393. utuo.SetBotID(*s)
  394. }
  395. return utuo
  396. }
  397. // SetTotalTokens sets the "total_tokens" field.
  398. func (utuo *UsageTotalUpdateOne) SetTotalTokens(u uint64) *UsageTotalUpdateOne {
  399. utuo.mutation.ResetTotalTokens()
  400. utuo.mutation.SetTotalTokens(u)
  401. return utuo
  402. }
  403. // SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil.
  404. func (utuo *UsageTotalUpdateOne) SetNillableTotalTokens(u *uint64) *UsageTotalUpdateOne {
  405. if u != nil {
  406. utuo.SetTotalTokens(*u)
  407. }
  408. return utuo
  409. }
  410. // AddTotalTokens adds u to the "total_tokens" field.
  411. func (utuo *UsageTotalUpdateOne) AddTotalTokens(u int64) *UsageTotalUpdateOne {
  412. utuo.mutation.AddTotalTokens(u)
  413. return utuo
  414. }
  415. // ClearTotalTokens clears the value of the "total_tokens" field.
  416. func (utuo *UsageTotalUpdateOne) ClearTotalTokens() *UsageTotalUpdateOne {
  417. utuo.mutation.ClearTotalTokens()
  418. return utuo
  419. }
  420. // SetCredits sets the "credits" field.
  421. func (utuo *UsageTotalUpdateOne) SetCredits(f float64) *UsageTotalUpdateOne {
  422. utuo.mutation.ResetCredits()
  423. utuo.mutation.SetCredits(f)
  424. return utuo
  425. }
  426. // SetNillableCredits sets the "credits" field if the given value is not nil.
  427. func (utuo *UsageTotalUpdateOne) SetNillableCredits(f *float64) *UsageTotalUpdateOne {
  428. if f != nil {
  429. utuo.SetCredits(*f)
  430. }
  431. return utuo
  432. }
  433. // AddCredits adds f to the "credits" field.
  434. func (utuo *UsageTotalUpdateOne) AddCredits(f float64) *UsageTotalUpdateOne {
  435. utuo.mutation.AddCredits(f)
  436. return utuo
  437. }
  438. // ClearCredits clears the value of the "credits" field.
  439. func (utuo *UsageTotalUpdateOne) ClearCredits() *UsageTotalUpdateOne {
  440. utuo.mutation.ClearCredits()
  441. return utuo
  442. }
  443. // SetStartIndex sets the "start_index" field.
  444. func (utuo *UsageTotalUpdateOne) SetStartIndex(u uint64) *UsageTotalUpdateOne {
  445. utuo.mutation.ResetStartIndex()
  446. utuo.mutation.SetStartIndex(u)
  447. return utuo
  448. }
  449. // SetNillableStartIndex sets the "start_index" field if the given value is not nil.
  450. func (utuo *UsageTotalUpdateOne) SetNillableStartIndex(u *uint64) *UsageTotalUpdateOne {
  451. if u != nil {
  452. utuo.SetStartIndex(*u)
  453. }
  454. return utuo
  455. }
  456. // AddStartIndex adds u to the "start_index" field.
  457. func (utuo *UsageTotalUpdateOne) AddStartIndex(u int64) *UsageTotalUpdateOne {
  458. utuo.mutation.AddStartIndex(u)
  459. return utuo
  460. }
  461. // ClearStartIndex clears the value of the "start_index" field.
  462. func (utuo *UsageTotalUpdateOne) ClearStartIndex() *UsageTotalUpdateOne {
  463. utuo.mutation.ClearStartIndex()
  464. return utuo
  465. }
  466. // SetEndIndex sets the "end_index" field.
  467. func (utuo *UsageTotalUpdateOne) SetEndIndex(u uint64) *UsageTotalUpdateOne {
  468. utuo.mutation.ResetEndIndex()
  469. utuo.mutation.SetEndIndex(u)
  470. return utuo
  471. }
  472. // SetNillableEndIndex sets the "end_index" field if the given value is not nil.
  473. func (utuo *UsageTotalUpdateOne) SetNillableEndIndex(u *uint64) *UsageTotalUpdateOne {
  474. if u != nil {
  475. utuo.SetEndIndex(*u)
  476. }
  477. return utuo
  478. }
  479. // AddEndIndex adds u to the "end_index" field.
  480. func (utuo *UsageTotalUpdateOne) AddEndIndex(u int64) *UsageTotalUpdateOne {
  481. utuo.mutation.AddEndIndex(u)
  482. return utuo
  483. }
  484. // ClearEndIndex clears the value of the "end_index" field.
  485. func (utuo *UsageTotalUpdateOne) ClearEndIndex() *UsageTotalUpdateOne {
  486. utuo.mutation.ClearEndIndex()
  487. return utuo
  488. }
  489. // SetOrganizationID sets the "organization_id" field.
  490. func (utuo *UsageTotalUpdateOne) SetOrganizationID(u uint64) *UsageTotalUpdateOne {
  491. utuo.mutation.ResetOrganizationID()
  492. utuo.mutation.SetOrganizationID(u)
  493. return utuo
  494. }
  495. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  496. func (utuo *UsageTotalUpdateOne) SetNillableOrganizationID(u *uint64) *UsageTotalUpdateOne {
  497. if u != nil {
  498. utuo.SetOrganizationID(*u)
  499. }
  500. return utuo
  501. }
  502. // AddOrganizationID adds u to the "organization_id" field.
  503. func (utuo *UsageTotalUpdateOne) AddOrganizationID(u int64) *UsageTotalUpdateOne {
  504. utuo.mutation.AddOrganizationID(u)
  505. return utuo
  506. }
  507. // ClearOrganizationID clears the value of the "organization_id" field.
  508. func (utuo *UsageTotalUpdateOne) ClearOrganizationID() *UsageTotalUpdateOne {
  509. utuo.mutation.ClearOrganizationID()
  510. return utuo
  511. }
  512. // Mutation returns the UsageTotalMutation object of the builder.
  513. func (utuo *UsageTotalUpdateOne) Mutation() *UsageTotalMutation {
  514. return utuo.mutation
  515. }
  516. // Where appends a list predicates to the UsageTotalUpdate builder.
  517. func (utuo *UsageTotalUpdateOne) Where(ps ...predicate.UsageTotal) *UsageTotalUpdateOne {
  518. utuo.mutation.Where(ps...)
  519. return utuo
  520. }
  521. // Select allows selecting one or more fields (columns) of the returned entity.
  522. // The default is selecting all fields defined in the entity schema.
  523. func (utuo *UsageTotalUpdateOne) Select(field string, fields ...string) *UsageTotalUpdateOne {
  524. utuo.fields = append([]string{field}, fields...)
  525. return utuo
  526. }
  527. // Save executes the query and returns the updated UsageTotal entity.
  528. func (utuo *UsageTotalUpdateOne) Save(ctx context.Context) (*UsageTotal, error) {
  529. utuo.defaults()
  530. return withHooks(ctx, utuo.sqlSave, utuo.mutation, utuo.hooks)
  531. }
  532. // SaveX is like Save, but panics if an error occurs.
  533. func (utuo *UsageTotalUpdateOne) SaveX(ctx context.Context) *UsageTotal {
  534. node, err := utuo.Save(ctx)
  535. if err != nil {
  536. panic(err)
  537. }
  538. return node
  539. }
  540. // Exec executes the query on the entity.
  541. func (utuo *UsageTotalUpdateOne) Exec(ctx context.Context) error {
  542. _, err := utuo.Save(ctx)
  543. return err
  544. }
  545. // ExecX is like Exec, but panics if an error occurs.
  546. func (utuo *UsageTotalUpdateOne) ExecX(ctx context.Context) {
  547. if err := utuo.Exec(ctx); err != nil {
  548. panic(err)
  549. }
  550. }
  551. // defaults sets the default values of the builder before save.
  552. func (utuo *UsageTotalUpdateOne) defaults() {
  553. if _, ok := utuo.mutation.UpdatedAt(); !ok {
  554. v := usagetotal.UpdateDefaultUpdatedAt()
  555. utuo.mutation.SetUpdatedAt(v)
  556. }
  557. }
  558. func (utuo *UsageTotalUpdateOne) sqlSave(ctx context.Context) (_node *UsageTotal, err error) {
  559. _spec := sqlgraph.NewUpdateSpec(usagetotal.Table, usagetotal.Columns, sqlgraph.NewFieldSpec(usagetotal.FieldID, field.TypeUint64))
  560. id, ok := utuo.mutation.ID()
  561. if !ok {
  562. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageTotal.id" for update`)}
  563. }
  564. _spec.Node.ID.Value = id
  565. if fields := utuo.fields; len(fields) > 0 {
  566. _spec.Node.Columns = make([]string, 0, len(fields))
  567. _spec.Node.Columns = append(_spec.Node.Columns, usagetotal.FieldID)
  568. for _, f := range fields {
  569. if !usagetotal.ValidColumn(f) {
  570. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  571. }
  572. if f != usagetotal.FieldID {
  573. _spec.Node.Columns = append(_spec.Node.Columns, f)
  574. }
  575. }
  576. }
  577. if ps := utuo.mutation.predicates; len(ps) > 0 {
  578. _spec.Predicate = func(selector *sql.Selector) {
  579. for i := range ps {
  580. ps[i](selector)
  581. }
  582. }
  583. }
  584. if value, ok := utuo.mutation.UpdatedAt(); ok {
  585. _spec.SetField(usagetotal.FieldUpdatedAt, field.TypeTime, value)
  586. }
  587. if value, ok := utuo.mutation.Status(); ok {
  588. _spec.SetField(usagetotal.FieldStatus, field.TypeUint8, value)
  589. }
  590. if value, ok := utuo.mutation.AddedStatus(); ok {
  591. _spec.AddField(usagetotal.FieldStatus, field.TypeUint8, value)
  592. }
  593. if utuo.mutation.StatusCleared() {
  594. _spec.ClearField(usagetotal.FieldStatus, field.TypeUint8)
  595. }
  596. if value, ok := utuo.mutation.GetType(); ok {
  597. _spec.SetField(usagetotal.FieldType, field.TypeInt, value)
  598. }
  599. if value, ok := utuo.mutation.AddedType(); ok {
  600. _spec.AddField(usagetotal.FieldType, field.TypeInt, value)
  601. }
  602. if utuo.mutation.TypeCleared() {
  603. _spec.ClearField(usagetotal.FieldType, field.TypeInt)
  604. }
  605. if value, ok := utuo.mutation.BotID(); ok {
  606. _spec.SetField(usagetotal.FieldBotID, field.TypeString, value)
  607. }
  608. if value, ok := utuo.mutation.TotalTokens(); ok {
  609. _spec.SetField(usagetotal.FieldTotalTokens, field.TypeUint64, value)
  610. }
  611. if value, ok := utuo.mutation.AddedTotalTokens(); ok {
  612. _spec.AddField(usagetotal.FieldTotalTokens, field.TypeUint64, value)
  613. }
  614. if utuo.mutation.TotalTokensCleared() {
  615. _spec.ClearField(usagetotal.FieldTotalTokens, field.TypeUint64)
  616. }
  617. if value, ok := utuo.mutation.Credits(); ok {
  618. _spec.SetField(usagetotal.FieldCredits, field.TypeFloat64, value)
  619. }
  620. if value, ok := utuo.mutation.AddedCredits(); ok {
  621. _spec.AddField(usagetotal.FieldCredits, field.TypeFloat64, value)
  622. }
  623. if utuo.mutation.CreditsCleared() {
  624. _spec.ClearField(usagetotal.FieldCredits, field.TypeFloat64)
  625. }
  626. if value, ok := utuo.mutation.StartIndex(); ok {
  627. _spec.SetField(usagetotal.FieldStartIndex, field.TypeUint64, value)
  628. }
  629. if value, ok := utuo.mutation.AddedStartIndex(); ok {
  630. _spec.AddField(usagetotal.FieldStartIndex, field.TypeUint64, value)
  631. }
  632. if utuo.mutation.StartIndexCleared() {
  633. _spec.ClearField(usagetotal.FieldStartIndex, field.TypeUint64)
  634. }
  635. if value, ok := utuo.mutation.EndIndex(); ok {
  636. _spec.SetField(usagetotal.FieldEndIndex, field.TypeUint64, value)
  637. }
  638. if value, ok := utuo.mutation.AddedEndIndex(); ok {
  639. _spec.AddField(usagetotal.FieldEndIndex, field.TypeUint64, value)
  640. }
  641. if utuo.mutation.EndIndexCleared() {
  642. _spec.ClearField(usagetotal.FieldEndIndex, field.TypeUint64)
  643. }
  644. if value, ok := utuo.mutation.OrganizationID(); ok {
  645. _spec.SetField(usagetotal.FieldOrganizationID, field.TypeUint64, value)
  646. }
  647. if value, ok := utuo.mutation.AddedOrganizationID(); ok {
  648. _spec.AddField(usagetotal.FieldOrganizationID, field.TypeUint64, value)
  649. }
  650. if utuo.mutation.OrganizationIDCleared() {
  651. _spec.ClearField(usagetotal.FieldOrganizationID, field.TypeUint64)
  652. }
  653. _node = &UsageTotal{config: utuo.config}
  654. _spec.Assign = _node.assignValues
  655. _spec.ScanValues = _node.scanValues
  656. if err = sqlgraph.UpdateNode(ctx, utuo.driver, _spec); err != nil {
  657. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  658. err = &NotFoundError{usagetotal.Label}
  659. } else if sqlgraph.IsConstraintError(err) {
  660. err = &ConstraintError{msg: err.Error(), wrap: err}
  661. }
  662. return nil, err
  663. }
  664. utuo.mutation.done = true
  665. return _node, nil
  666. }