usagetotal_update.go 20 KB

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