creditusage_update.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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/creditusage"
  9. "wechat-api/ent/predicate"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // CreditUsageUpdate is the builder for updating CreditUsage entities.
  15. type CreditUsageUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *CreditUsageMutation
  19. }
  20. // Where appends a list predicates to the CreditUsageUpdate builder.
  21. func (cuu *CreditUsageUpdate) Where(ps ...predicate.CreditUsage) *CreditUsageUpdate {
  22. cuu.mutation.Where(ps...)
  23. return cuu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (cuu *CreditUsageUpdate) SetUpdatedAt(t time.Time) *CreditUsageUpdate {
  27. cuu.mutation.SetUpdatedAt(t)
  28. return cuu
  29. }
  30. // SetDeletedAt sets the "deleted_at" field.
  31. func (cuu *CreditUsageUpdate) SetDeletedAt(t time.Time) *CreditUsageUpdate {
  32. cuu.mutation.SetDeletedAt(t)
  33. return cuu
  34. }
  35. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  36. func (cuu *CreditUsageUpdate) SetNillableDeletedAt(t *time.Time) *CreditUsageUpdate {
  37. if t != nil {
  38. cuu.SetDeletedAt(*t)
  39. }
  40. return cuu
  41. }
  42. // ClearDeletedAt clears the value of the "deleted_at" field.
  43. func (cuu *CreditUsageUpdate) ClearDeletedAt() *CreditUsageUpdate {
  44. cuu.mutation.ClearDeletedAt()
  45. return cuu
  46. }
  47. // SetUserID sets the "user_id" field.
  48. func (cuu *CreditUsageUpdate) SetUserID(s string) *CreditUsageUpdate {
  49. cuu.mutation.SetUserID(s)
  50. return cuu
  51. }
  52. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  53. func (cuu *CreditUsageUpdate) SetNillableUserID(s *string) *CreditUsageUpdate {
  54. if s != nil {
  55. cuu.SetUserID(*s)
  56. }
  57. return cuu
  58. }
  59. // ClearUserID clears the value of the "user_id" field.
  60. func (cuu *CreditUsageUpdate) ClearUserID() *CreditUsageUpdate {
  61. cuu.mutation.ClearUserID()
  62. return cuu
  63. }
  64. // SetNumber sets the "number" field.
  65. func (cuu *CreditUsageUpdate) SetNumber(f float64) *CreditUsageUpdate {
  66. cuu.mutation.ResetNumber()
  67. cuu.mutation.SetNumber(f)
  68. return cuu
  69. }
  70. // SetNillableNumber sets the "number" field if the given value is not nil.
  71. func (cuu *CreditUsageUpdate) SetNillableNumber(f *float64) *CreditUsageUpdate {
  72. if f != nil {
  73. cuu.SetNumber(*f)
  74. }
  75. return cuu
  76. }
  77. // AddNumber adds f to the "number" field.
  78. func (cuu *CreditUsageUpdate) AddNumber(f float64) *CreditUsageUpdate {
  79. cuu.mutation.AddNumber(f)
  80. return cuu
  81. }
  82. // SetPayNumber sets the "pay_number" field.
  83. func (cuu *CreditUsageUpdate) SetPayNumber(f float64) *CreditUsageUpdate {
  84. cuu.mutation.ResetPayNumber()
  85. cuu.mutation.SetPayNumber(f)
  86. return cuu
  87. }
  88. // SetNillablePayNumber sets the "pay_number" field if the given value is not nil.
  89. func (cuu *CreditUsageUpdate) SetNillablePayNumber(f *float64) *CreditUsageUpdate {
  90. if f != nil {
  91. cuu.SetPayNumber(*f)
  92. }
  93. return cuu
  94. }
  95. // AddPayNumber adds f to the "pay_number" field.
  96. func (cuu *CreditUsageUpdate) AddPayNumber(f float64) *CreditUsageUpdate {
  97. cuu.mutation.AddPayNumber(f)
  98. return cuu
  99. }
  100. // ClearPayNumber clears the value of the "pay_number" field.
  101. func (cuu *CreditUsageUpdate) ClearPayNumber() *CreditUsageUpdate {
  102. cuu.mutation.ClearPayNumber()
  103. return cuu
  104. }
  105. // SetBeforeNumber sets the "before_number" field.
  106. func (cuu *CreditUsageUpdate) SetBeforeNumber(f float64) *CreditUsageUpdate {
  107. cuu.mutation.ResetBeforeNumber()
  108. cuu.mutation.SetBeforeNumber(f)
  109. return cuu
  110. }
  111. // SetNillableBeforeNumber sets the "before_number" field if the given value is not nil.
  112. func (cuu *CreditUsageUpdate) SetNillableBeforeNumber(f *float64) *CreditUsageUpdate {
  113. if f != nil {
  114. cuu.SetBeforeNumber(*f)
  115. }
  116. return cuu
  117. }
  118. // AddBeforeNumber adds f to the "before_number" field.
  119. func (cuu *CreditUsageUpdate) AddBeforeNumber(f float64) *CreditUsageUpdate {
  120. cuu.mutation.AddBeforeNumber(f)
  121. return cuu
  122. }
  123. // ClearBeforeNumber clears the value of the "before_number" field.
  124. func (cuu *CreditUsageUpdate) ClearBeforeNumber() *CreditUsageUpdate {
  125. cuu.mutation.ClearBeforeNumber()
  126. return cuu
  127. }
  128. // SetAfterNumber sets the "after_number" field.
  129. func (cuu *CreditUsageUpdate) SetAfterNumber(f float64) *CreditUsageUpdate {
  130. cuu.mutation.ResetAfterNumber()
  131. cuu.mutation.SetAfterNumber(f)
  132. return cuu
  133. }
  134. // SetNillableAfterNumber sets the "after_number" field if the given value is not nil.
  135. func (cuu *CreditUsageUpdate) SetNillableAfterNumber(f *float64) *CreditUsageUpdate {
  136. if f != nil {
  137. cuu.SetAfterNumber(*f)
  138. }
  139. return cuu
  140. }
  141. // AddAfterNumber adds f to the "after_number" field.
  142. func (cuu *CreditUsageUpdate) AddAfterNumber(f float64) *CreditUsageUpdate {
  143. cuu.mutation.AddAfterNumber(f)
  144. return cuu
  145. }
  146. // ClearAfterNumber clears the value of the "after_number" field.
  147. func (cuu *CreditUsageUpdate) ClearAfterNumber() *CreditUsageUpdate {
  148. cuu.mutation.ClearAfterNumber()
  149. return cuu
  150. }
  151. // SetPayMethod sets the "pay_method" field.
  152. func (cuu *CreditUsageUpdate) SetPayMethod(i int) *CreditUsageUpdate {
  153. cuu.mutation.ResetPayMethod()
  154. cuu.mutation.SetPayMethod(i)
  155. return cuu
  156. }
  157. // SetNillablePayMethod sets the "pay_method" field if the given value is not nil.
  158. func (cuu *CreditUsageUpdate) SetNillablePayMethod(i *int) *CreditUsageUpdate {
  159. if i != nil {
  160. cuu.SetPayMethod(*i)
  161. }
  162. return cuu
  163. }
  164. // AddPayMethod adds i to the "pay_method" field.
  165. func (cuu *CreditUsageUpdate) AddPayMethod(i int) *CreditUsageUpdate {
  166. cuu.mutation.AddPayMethod(i)
  167. return cuu
  168. }
  169. // ClearPayMethod clears the value of the "pay_method" field.
  170. func (cuu *CreditUsageUpdate) ClearPayMethod() *CreditUsageUpdate {
  171. cuu.mutation.ClearPayMethod()
  172. return cuu
  173. }
  174. // SetStatus sets the "status" field.
  175. func (cuu *CreditUsageUpdate) SetStatus(i int) *CreditUsageUpdate {
  176. cuu.mutation.ResetStatus()
  177. cuu.mutation.SetStatus(i)
  178. return cuu
  179. }
  180. // SetNillableStatus sets the "status" field if the given value is not nil.
  181. func (cuu *CreditUsageUpdate) SetNillableStatus(i *int) *CreditUsageUpdate {
  182. if i != nil {
  183. cuu.SetStatus(*i)
  184. }
  185. return cuu
  186. }
  187. // AddStatus adds i to the "status" field.
  188. func (cuu *CreditUsageUpdate) AddStatus(i int) *CreditUsageUpdate {
  189. cuu.mutation.AddStatus(i)
  190. return cuu
  191. }
  192. // ClearStatus clears the value of the "status" field.
  193. func (cuu *CreditUsageUpdate) ClearStatus() *CreditUsageUpdate {
  194. cuu.mutation.ClearStatus()
  195. return cuu
  196. }
  197. // SetNtype sets the "ntype" field.
  198. func (cuu *CreditUsageUpdate) SetNtype(i int) *CreditUsageUpdate {
  199. cuu.mutation.ResetNtype()
  200. cuu.mutation.SetNtype(i)
  201. return cuu
  202. }
  203. // SetNillableNtype sets the "ntype" field if the given value is not nil.
  204. func (cuu *CreditUsageUpdate) SetNillableNtype(i *int) *CreditUsageUpdate {
  205. if i != nil {
  206. cuu.SetNtype(*i)
  207. }
  208. return cuu
  209. }
  210. // AddNtype adds i to the "ntype" field.
  211. func (cuu *CreditUsageUpdate) AddNtype(i int) *CreditUsageUpdate {
  212. cuu.mutation.AddNtype(i)
  213. return cuu
  214. }
  215. // SetTable sets the "table" field.
  216. func (cuu *CreditUsageUpdate) SetTable(s string) *CreditUsageUpdate {
  217. cuu.mutation.SetTable(s)
  218. return cuu
  219. }
  220. // SetNillableTable sets the "table" field if the given value is not nil.
  221. func (cuu *CreditUsageUpdate) SetNillableTable(s *string) *CreditUsageUpdate {
  222. if s != nil {
  223. cuu.SetTable(*s)
  224. }
  225. return cuu
  226. }
  227. // SetOrganizationID sets the "organization_id" field.
  228. func (cuu *CreditUsageUpdate) SetOrganizationID(u uint64) *CreditUsageUpdate {
  229. cuu.mutation.ResetOrganizationID()
  230. cuu.mutation.SetOrganizationID(u)
  231. return cuu
  232. }
  233. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  234. func (cuu *CreditUsageUpdate) SetNillableOrganizationID(u *uint64) *CreditUsageUpdate {
  235. if u != nil {
  236. cuu.SetOrganizationID(*u)
  237. }
  238. return cuu
  239. }
  240. // AddOrganizationID adds u to the "organization_id" field.
  241. func (cuu *CreditUsageUpdate) AddOrganizationID(u int64) *CreditUsageUpdate {
  242. cuu.mutation.AddOrganizationID(u)
  243. return cuu
  244. }
  245. // ClearOrganizationID clears the value of the "organization_id" field.
  246. func (cuu *CreditUsageUpdate) ClearOrganizationID() *CreditUsageUpdate {
  247. cuu.mutation.ClearOrganizationID()
  248. return cuu
  249. }
  250. // SetNid sets the "nid" field.
  251. func (cuu *CreditUsageUpdate) SetNid(u uint64) *CreditUsageUpdate {
  252. cuu.mutation.ResetNid()
  253. cuu.mutation.SetNid(u)
  254. return cuu
  255. }
  256. // SetNillableNid sets the "nid" field if the given value is not nil.
  257. func (cuu *CreditUsageUpdate) SetNillableNid(u *uint64) *CreditUsageUpdate {
  258. if u != nil {
  259. cuu.SetNid(*u)
  260. }
  261. return cuu
  262. }
  263. // AddNid adds u to the "nid" field.
  264. func (cuu *CreditUsageUpdate) AddNid(u int64) *CreditUsageUpdate {
  265. cuu.mutation.AddNid(u)
  266. return cuu
  267. }
  268. // SetReason sets the "reason" field.
  269. func (cuu *CreditUsageUpdate) SetReason(s string) *CreditUsageUpdate {
  270. cuu.mutation.SetReason(s)
  271. return cuu
  272. }
  273. // SetNillableReason sets the "reason" field if the given value is not nil.
  274. func (cuu *CreditUsageUpdate) SetNillableReason(s *string) *CreditUsageUpdate {
  275. if s != nil {
  276. cuu.SetReason(*s)
  277. }
  278. return cuu
  279. }
  280. // SetOperator sets the "operator" field.
  281. func (cuu *CreditUsageUpdate) SetOperator(s string) *CreditUsageUpdate {
  282. cuu.mutation.SetOperator(s)
  283. return cuu
  284. }
  285. // SetNillableOperator sets the "operator" field if the given value is not nil.
  286. func (cuu *CreditUsageUpdate) SetNillableOperator(s *string) *CreditUsageUpdate {
  287. if s != nil {
  288. cuu.SetOperator(*s)
  289. }
  290. return cuu
  291. }
  292. // Mutation returns the CreditUsageMutation object of the builder.
  293. func (cuu *CreditUsageUpdate) Mutation() *CreditUsageMutation {
  294. return cuu.mutation
  295. }
  296. // Save executes the query and returns the number of nodes affected by the update operation.
  297. func (cuu *CreditUsageUpdate) Save(ctx context.Context) (int, error) {
  298. if err := cuu.defaults(); err != nil {
  299. return 0, err
  300. }
  301. return withHooks(ctx, cuu.sqlSave, cuu.mutation, cuu.hooks)
  302. }
  303. // SaveX is like Save, but panics if an error occurs.
  304. func (cuu *CreditUsageUpdate) SaveX(ctx context.Context) int {
  305. affected, err := cuu.Save(ctx)
  306. if err != nil {
  307. panic(err)
  308. }
  309. return affected
  310. }
  311. // Exec executes the query.
  312. func (cuu *CreditUsageUpdate) Exec(ctx context.Context) error {
  313. _, err := cuu.Save(ctx)
  314. return err
  315. }
  316. // ExecX is like Exec, but panics if an error occurs.
  317. func (cuu *CreditUsageUpdate) ExecX(ctx context.Context) {
  318. if err := cuu.Exec(ctx); err != nil {
  319. panic(err)
  320. }
  321. }
  322. // defaults sets the default values of the builder before save.
  323. func (cuu *CreditUsageUpdate) defaults() error {
  324. if _, ok := cuu.mutation.UpdatedAt(); !ok {
  325. if creditusage.UpdateDefaultUpdatedAt == nil {
  326. return fmt.Errorf("ent: uninitialized creditusage.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  327. }
  328. v := creditusage.UpdateDefaultUpdatedAt()
  329. cuu.mutation.SetUpdatedAt(v)
  330. }
  331. return nil
  332. }
  333. // check runs all checks and user-defined validators on the builder.
  334. func (cuu *CreditUsageUpdate) check() error {
  335. if v, ok := cuu.mutation.UserID(); ok {
  336. if err := creditusage.UserIDValidator(v); err != nil {
  337. return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.user_id": %w`, err)}
  338. }
  339. }
  340. if v, ok := cuu.mutation.Status(); ok {
  341. if err := creditusage.StatusValidator(v); err != nil {
  342. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.status": %w`, err)}
  343. }
  344. }
  345. if v, ok := cuu.mutation.Reason(); ok {
  346. if err := creditusage.ReasonValidator(v); err != nil {
  347. return &ValidationError{Name: "reason", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.reason": %w`, err)}
  348. }
  349. }
  350. if v, ok := cuu.mutation.Operator(); ok {
  351. if err := creditusage.OperatorValidator(v); err != nil {
  352. return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.operator": %w`, err)}
  353. }
  354. }
  355. return nil
  356. }
  357. func (cuu *CreditUsageUpdate) sqlSave(ctx context.Context) (n int, err error) {
  358. if err := cuu.check(); err != nil {
  359. return n, err
  360. }
  361. _spec := sqlgraph.NewUpdateSpec(creditusage.Table, creditusage.Columns, sqlgraph.NewFieldSpec(creditusage.FieldID, field.TypeUint64))
  362. if ps := cuu.mutation.predicates; len(ps) > 0 {
  363. _spec.Predicate = func(selector *sql.Selector) {
  364. for i := range ps {
  365. ps[i](selector)
  366. }
  367. }
  368. }
  369. if value, ok := cuu.mutation.UpdatedAt(); ok {
  370. _spec.SetField(creditusage.FieldUpdatedAt, field.TypeTime, value)
  371. }
  372. if value, ok := cuu.mutation.DeletedAt(); ok {
  373. _spec.SetField(creditusage.FieldDeletedAt, field.TypeTime, value)
  374. }
  375. if cuu.mutation.DeletedAtCleared() {
  376. _spec.ClearField(creditusage.FieldDeletedAt, field.TypeTime)
  377. }
  378. if value, ok := cuu.mutation.UserID(); ok {
  379. _spec.SetField(creditusage.FieldUserID, field.TypeString, value)
  380. }
  381. if cuu.mutation.UserIDCleared() {
  382. _spec.ClearField(creditusage.FieldUserID, field.TypeString)
  383. }
  384. if value, ok := cuu.mutation.Number(); ok {
  385. _spec.SetField(creditusage.FieldNumber, field.TypeFloat64, value)
  386. }
  387. if value, ok := cuu.mutation.AddedNumber(); ok {
  388. _spec.AddField(creditusage.FieldNumber, field.TypeFloat64, value)
  389. }
  390. if value, ok := cuu.mutation.PayNumber(); ok {
  391. _spec.SetField(creditusage.FieldPayNumber, field.TypeFloat64, value)
  392. }
  393. if value, ok := cuu.mutation.AddedPayNumber(); ok {
  394. _spec.AddField(creditusage.FieldPayNumber, field.TypeFloat64, value)
  395. }
  396. if cuu.mutation.PayNumberCleared() {
  397. _spec.ClearField(creditusage.FieldPayNumber, field.TypeFloat64)
  398. }
  399. if value, ok := cuu.mutation.BeforeNumber(); ok {
  400. _spec.SetField(creditusage.FieldBeforeNumber, field.TypeFloat64, value)
  401. }
  402. if value, ok := cuu.mutation.AddedBeforeNumber(); ok {
  403. _spec.AddField(creditusage.FieldBeforeNumber, field.TypeFloat64, value)
  404. }
  405. if cuu.mutation.BeforeNumberCleared() {
  406. _spec.ClearField(creditusage.FieldBeforeNumber, field.TypeFloat64)
  407. }
  408. if value, ok := cuu.mutation.AfterNumber(); ok {
  409. _spec.SetField(creditusage.FieldAfterNumber, field.TypeFloat64, value)
  410. }
  411. if value, ok := cuu.mutation.AddedAfterNumber(); ok {
  412. _spec.AddField(creditusage.FieldAfterNumber, field.TypeFloat64, value)
  413. }
  414. if cuu.mutation.AfterNumberCleared() {
  415. _spec.ClearField(creditusage.FieldAfterNumber, field.TypeFloat64)
  416. }
  417. if value, ok := cuu.mutation.PayMethod(); ok {
  418. _spec.SetField(creditusage.FieldPayMethod, field.TypeInt, value)
  419. }
  420. if value, ok := cuu.mutation.AddedPayMethod(); ok {
  421. _spec.AddField(creditusage.FieldPayMethod, field.TypeInt, value)
  422. }
  423. if cuu.mutation.PayMethodCleared() {
  424. _spec.ClearField(creditusage.FieldPayMethod, field.TypeInt)
  425. }
  426. if value, ok := cuu.mutation.Status(); ok {
  427. _spec.SetField(creditusage.FieldStatus, field.TypeInt, value)
  428. }
  429. if value, ok := cuu.mutation.AddedStatus(); ok {
  430. _spec.AddField(creditusage.FieldStatus, field.TypeInt, value)
  431. }
  432. if cuu.mutation.StatusCleared() {
  433. _spec.ClearField(creditusage.FieldStatus, field.TypeInt)
  434. }
  435. if value, ok := cuu.mutation.Ntype(); ok {
  436. _spec.SetField(creditusage.FieldNtype, field.TypeInt, value)
  437. }
  438. if value, ok := cuu.mutation.AddedNtype(); ok {
  439. _spec.AddField(creditusage.FieldNtype, field.TypeInt, value)
  440. }
  441. if value, ok := cuu.mutation.Table(); ok {
  442. _spec.SetField(creditusage.FieldTable, field.TypeString, value)
  443. }
  444. if value, ok := cuu.mutation.OrganizationID(); ok {
  445. _spec.SetField(creditusage.FieldOrganizationID, field.TypeUint64, value)
  446. }
  447. if value, ok := cuu.mutation.AddedOrganizationID(); ok {
  448. _spec.AddField(creditusage.FieldOrganizationID, field.TypeUint64, value)
  449. }
  450. if cuu.mutation.OrganizationIDCleared() {
  451. _spec.ClearField(creditusage.FieldOrganizationID, field.TypeUint64)
  452. }
  453. if value, ok := cuu.mutation.Nid(); ok {
  454. _spec.SetField(creditusage.FieldNid, field.TypeUint64, value)
  455. }
  456. if value, ok := cuu.mutation.AddedNid(); ok {
  457. _spec.AddField(creditusage.FieldNid, field.TypeUint64, value)
  458. }
  459. if value, ok := cuu.mutation.Reason(); ok {
  460. _spec.SetField(creditusage.FieldReason, field.TypeString, value)
  461. }
  462. if value, ok := cuu.mutation.Operator(); ok {
  463. _spec.SetField(creditusage.FieldOperator, field.TypeString, value)
  464. }
  465. if n, err = sqlgraph.UpdateNodes(ctx, cuu.driver, _spec); err != nil {
  466. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  467. err = &NotFoundError{creditusage.Label}
  468. } else if sqlgraph.IsConstraintError(err) {
  469. err = &ConstraintError{msg: err.Error(), wrap: err}
  470. }
  471. return 0, err
  472. }
  473. cuu.mutation.done = true
  474. return n, nil
  475. }
  476. // CreditUsageUpdateOne is the builder for updating a single CreditUsage entity.
  477. type CreditUsageUpdateOne struct {
  478. config
  479. fields []string
  480. hooks []Hook
  481. mutation *CreditUsageMutation
  482. }
  483. // SetUpdatedAt sets the "updated_at" field.
  484. func (cuuo *CreditUsageUpdateOne) SetUpdatedAt(t time.Time) *CreditUsageUpdateOne {
  485. cuuo.mutation.SetUpdatedAt(t)
  486. return cuuo
  487. }
  488. // SetDeletedAt sets the "deleted_at" field.
  489. func (cuuo *CreditUsageUpdateOne) SetDeletedAt(t time.Time) *CreditUsageUpdateOne {
  490. cuuo.mutation.SetDeletedAt(t)
  491. return cuuo
  492. }
  493. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  494. func (cuuo *CreditUsageUpdateOne) SetNillableDeletedAt(t *time.Time) *CreditUsageUpdateOne {
  495. if t != nil {
  496. cuuo.SetDeletedAt(*t)
  497. }
  498. return cuuo
  499. }
  500. // ClearDeletedAt clears the value of the "deleted_at" field.
  501. func (cuuo *CreditUsageUpdateOne) ClearDeletedAt() *CreditUsageUpdateOne {
  502. cuuo.mutation.ClearDeletedAt()
  503. return cuuo
  504. }
  505. // SetUserID sets the "user_id" field.
  506. func (cuuo *CreditUsageUpdateOne) SetUserID(s string) *CreditUsageUpdateOne {
  507. cuuo.mutation.SetUserID(s)
  508. return cuuo
  509. }
  510. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  511. func (cuuo *CreditUsageUpdateOne) SetNillableUserID(s *string) *CreditUsageUpdateOne {
  512. if s != nil {
  513. cuuo.SetUserID(*s)
  514. }
  515. return cuuo
  516. }
  517. // ClearUserID clears the value of the "user_id" field.
  518. func (cuuo *CreditUsageUpdateOne) ClearUserID() *CreditUsageUpdateOne {
  519. cuuo.mutation.ClearUserID()
  520. return cuuo
  521. }
  522. // SetNumber sets the "number" field.
  523. func (cuuo *CreditUsageUpdateOne) SetNumber(f float64) *CreditUsageUpdateOne {
  524. cuuo.mutation.ResetNumber()
  525. cuuo.mutation.SetNumber(f)
  526. return cuuo
  527. }
  528. // SetNillableNumber sets the "number" field if the given value is not nil.
  529. func (cuuo *CreditUsageUpdateOne) SetNillableNumber(f *float64) *CreditUsageUpdateOne {
  530. if f != nil {
  531. cuuo.SetNumber(*f)
  532. }
  533. return cuuo
  534. }
  535. // AddNumber adds f to the "number" field.
  536. func (cuuo *CreditUsageUpdateOne) AddNumber(f float64) *CreditUsageUpdateOne {
  537. cuuo.mutation.AddNumber(f)
  538. return cuuo
  539. }
  540. // SetPayNumber sets the "pay_number" field.
  541. func (cuuo *CreditUsageUpdateOne) SetPayNumber(f float64) *CreditUsageUpdateOne {
  542. cuuo.mutation.ResetPayNumber()
  543. cuuo.mutation.SetPayNumber(f)
  544. return cuuo
  545. }
  546. // SetNillablePayNumber sets the "pay_number" field if the given value is not nil.
  547. func (cuuo *CreditUsageUpdateOne) SetNillablePayNumber(f *float64) *CreditUsageUpdateOne {
  548. if f != nil {
  549. cuuo.SetPayNumber(*f)
  550. }
  551. return cuuo
  552. }
  553. // AddPayNumber adds f to the "pay_number" field.
  554. func (cuuo *CreditUsageUpdateOne) AddPayNumber(f float64) *CreditUsageUpdateOne {
  555. cuuo.mutation.AddPayNumber(f)
  556. return cuuo
  557. }
  558. // ClearPayNumber clears the value of the "pay_number" field.
  559. func (cuuo *CreditUsageUpdateOne) ClearPayNumber() *CreditUsageUpdateOne {
  560. cuuo.mutation.ClearPayNumber()
  561. return cuuo
  562. }
  563. // SetBeforeNumber sets the "before_number" field.
  564. func (cuuo *CreditUsageUpdateOne) SetBeforeNumber(f float64) *CreditUsageUpdateOne {
  565. cuuo.mutation.ResetBeforeNumber()
  566. cuuo.mutation.SetBeforeNumber(f)
  567. return cuuo
  568. }
  569. // SetNillableBeforeNumber sets the "before_number" field if the given value is not nil.
  570. func (cuuo *CreditUsageUpdateOne) SetNillableBeforeNumber(f *float64) *CreditUsageUpdateOne {
  571. if f != nil {
  572. cuuo.SetBeforeNumber(*f)
  573. }
  574. return cuuo
  575. }
  576. // AddBeforeNumber adds f to the "before_number" field.
  577. func (cuuo *CreditUsageUpdateOne) AddBeforeNumber(f float64) *CreditUsageUpdateOne {
  578. cuuo.mutation.AddBeforeNumber(f)
  579. return cuuo
  580. }
  581. // ClearBeforeNumber clears the value of the "before_number" field.
  582. func (cuuo *CreditUsageUpdateOne) ClearBeforeNumber() *CreditUsageUpdateOne {
  583. cuuo.mutation.ClearBeforeNumber()
  584. return cuuo
  585. }
  586. // SetAfterNumber sets the "after_number" field.
  587. func (cuuo *CreditUsageUpdateOne) SetAfterNumber(f float64) *CreditUsageUpdateOne {
  588. cuuo.mutation.ResetAfterNumber()
  589. cuuo.mutation.SetAfterNumber(f)
  590. return cuuo
  591. }
  592. // SetNillableAfterNumber sets the "after_number" field if the given value is not nil.
  593. func (cuuo *CreditUsageUpdateOne) SetNillableAfterNumber(f *float64) *CreditUsageUpdateOne {
  594. if f != nil {
  595. cuuo.SetAfterNumber(*f)
  596. }
  597. return cuuo
  598. }
  599. // AddAfterNumber adds f to the "after_number" field.
  600. func (cuuo *CreditUsageUpdateOne) AddAfterNumber(f float64) *CreditUsageUpdateOne {
  601. cuuo.mutation.AddAfterNumber(f)
  602. return cuuo
  603. }
  604. // ClearAfterNumber clears the value of the "after_number" field.
  605. func (cuuo *CreditUsageUpdateOne) ClearAfterNumber() *CreditUsageUpdateOne {
  606. cuuo.mutation.ClearAfterNumber()
  607. return cuuo
  608. }
  609. // SetPayMethod sets the "pay_method" field.
  610. func (cuuo *CreditUsageUpdateOne) SetPayMethod(i int) *CreditUsageUpdateOne {
  611. cuuo.mutation.ResetPayMethod()
  612. cuuo.mutation.SetPayMethod(i)
  613. return cuuo
  614. }
  615. // SetNillablePayMethod sets the "pay_method" field if the given value is not nil.
  616. func (cuuo *CreditUsageUpdateOne) SetNillablePayMethod(i *int) *CreditUsageUpdateOne {
  617. if i != nil {
  618. cuuo.SetPayMethod(*i)
  619. }
  620. return cuuo
  621. }
  622. // AddPayMethod adds i to the "pay_method" field.
  623. func (cuuo *CreditUsageUpdateOne) AddPayMethod(i int) *CreditUsageUpdateOne {
  624. cuuo.mutation.AddPayMethod(i)
  625. return cuuo
  626. }
  627. // ClearPayMethod clears the value of the "pay_method" field.
  628. func (cuuo *CreditUsageUpdateOne) ClearPayMethod() *CreditUsageUpdateOne {
  629. cuuo.mutation.ClearPayMethod()
  630. return cuuo
  631. }
  632. // SetStatus sets the "status" field.
  633. func (cuuo *CreditUsageUpdateOne) SetStatus(i int) *CreditUsageUpdateOne {
  634. cuuo.mutation.ResetStatus()
  635. cuuo.mutation.SetStatus(i)
  636. return cuuo
  637. }
  638. // SetNillableStatus sets the "status" field if the given value is not nil.
  639. func (cuuo *CreditUsageUpdateOne) SetNillableStatus(i *int) *CreditUsageUpdateOne {
  640. if i != nil {
  641. cuuo.SetStatus(*i)
  642. }
  643. return cuuo
  644. }
  645. // AddStatus adds i to the "status" field.
  646. func (cuuo *CreditUsageUpdateOne) AddStatus(i int) *CreditUsageUpdateOne {
  647. cuuo.mutation.AddStatus(i)
  648. return cuuo
  649. }
  650. // ClearStatus clears the value of the "status" field.
  651. func (cuuo *CreditUsageUpdateOne) ClearStatus() *CreditUsageUpdateOne {
  652. cuuo.mutation.ClearStatus()
  653. return cuuo
  654. }
  655. // SetNtype sets the "ntype" field.
  656. func (cuuo *CreditUsageUpdateOne) SetNtype(i int) *CreditUsageUpdateOne {
  657. cuuo.mutation.ResetNtype()
  658. cuuo.mutation.SetNtype(i)
  659. return cuuo
  660. }
  661. // SetNillableNtype sets the "ntype" field if the given value is not nil.
  662. func (cuuo *CreditUsageUpdateOne) SetNillableNtype(i *int) *CreditUsageUpdateOne {
  663. if i != nil {
  664. cuuo.SetNtype(*i)
  665. }
  666. return cuuo
  667. }
  668. // AddNtype adds i to the "ntype" field.
  669. func (cuuo *CreditUsageUpdateOne) AddNtype(i int) *CreditUsageUpdateOne {
  670. cuuo.mutation.AddNtype(i)
  671. return cuuo
  672. }
  673. // SetTable sets the "table" field.
  674. func (cuuo *CreditUsageUpdateOne) SetTable(s string) *CreditUsageUpdateOne {
  675. cuuo.mutation.SetTable(s)
  676. return cuuo
  677. }
  678. // SetNillableTable sets the "table" field if the given value is not nil.
  679. func (cuuo *CreditUsageUpdateOne) SetNillableTable(s *string) *CreditUsageUpdateOne {
  680. if s != nil {
  681. cuuo.SetTable(*s)
  682. }
  683. return cuuo
  684. }
  685. // SetOrganizationID sets the "organization_id" field.
  686. func (cuuo *CreditUsageUpdateOne) SetOrganizationID(u uint64) *CreditUsageUpdateOne {
  687. cuuo.mutation.ResetOrganizationID()
  688. cuuo.mutation.SetOrganizationID(u)
  689. return cuuo
  690. }
  691. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  692. func (cuuo *CreditUsageUpdateOne) SetNillableOrganizationID(u *uint64) *CreditUsageUpdateOne {
  693. if u != nil {
  694. cuuo.SetOrganizationID(*u)
  695. }
  696. return cuuo
  697. }
  698. // AddOrganizationID adds u to the "organization_id" field.
  699. func (cuuo *CreditUsageUpdateOne) AddOrganizationID(u int64) *CreditUsageUpdateOne {
  700. cuuo.mutation.AddOrganizationID(u)
  701. return cuuo
  702. }
  703. // ClearOrganizationID clears the value of the "organization_id" field.
  704. func (cuuo *CreditUsageUpdateOne) ClearOrganizationID() *CreditUsageUpdateOne {
  705. cuuo.mutation.ClearOrganizationID()
  706. return cuuo
  707. }
  708. // SetNid sets the "nid" field.
  709. func (cuuo *CreditUsageUpdateOne) SetNid(u uint64) *CreditUsageUpdateOne {
  710. cuuo.mutation.ResetNid()
  711. cuuo.mutation.SetNid(u)
  712. return cuuo
  713. }
  714. // SetNillableNid sets the "nid" field if the given value is not nil.
  715. func (cuuo *CreditUsageUpdateOne) SetNillableNid(u *uint64) *CreditUsageUpdateOne {
  716. if u != nil {
  717. cuuo.SetNid(*u)
  718. }
  719. return cuuo
  720. }
  721. // AddNid adds u to the "nid" field.
  722. func (cuuo *CreditUsageUpdateOne) AddNid(u int64) *CreditUsageUpdateOne {
  723. cuuo.mutation.AddNid(u)
  724. return cuuo
  725. }
  726. // SetReason sets the "reason" field.
  727. func (cuuo *CreditUsageUpdateOne) SetReason(s string) *CreditUsageUpdateOne {
  728. cuuo.mutation.SetReason(s)
  729. return cuuo
  730. }
  731. // SetNillableReason sets the "reason" field if the given value is not nil.
  732. func (cuuo *CreditUsageUpdateOne) SetNillableReason(s *string) *CreditUsageUpdateOne {
  733. if s != nil {
  734. cuuo.SetReason(*s)
  735. }
  736. return cuuo
  737. }
  738. // SetOperator sets the "operator" field.
  739. func (cuuo *CreditUsageUpdateOne) SetOperator(s string) *CreditUsageUpdateOne {
  740. cuuo.mutation.SetOperator(s)
  741. return cuuo
  742. }
  743. // SetNillableOperator sets the "operator" field if the given value is not nil.
  744. func (cuuo *CreditUsageUpdateOne) SetNillableOperator(s *string) *CreditUsageUpdateOne {
  745. if s != nil {
  746. cuuo.SetOperator(*s)
  747. }
  748. return cuuo
  749. }
  750. // Mutation returns the CreditUsageMutation object of the builder.
  751. func (cuuo *CreditUsageUpdateOne) Mutation() *CreditUsageMutation {
  752. return cuuo.mutation
  753. }
  754. // Where appends a list predicates to the CreditUsageUpdate builder.
  755. func (cuuo *CreditUsageUpdateOne) Where(ps ...predicate.CreditUsage) *CreditUsageUpdateOne {
  756. cuuo.mutation.Where(ps...)
  757. return cuuo
  758. }
  759. // Select allows selecting one or more fields (columns) of the returned entity.
  760. // The default is selecting all fields defined in the entity schema.
  761. func (cuuo *CreditUsageUpdateOne) Select(field string, fields ...string) *CreditUsageUpdateOne {
  762. cuuo.fields = append([]string{field}, fields...)
  763. return cuuo
  764. }
  765. // Save executes the query and returns the updated CreditUsage entity.
  766. func (cuuo *CreditUsageUpdateOne) Save(ctx context.Context) (*CreditUsage, error) {
  767. if err := cuuo.defaults(); err != nil {
  768. return nil, err
  769. }
  770. return withHooks(ctx, cuuo.sqlSave, cuuo.mutation, cuuo.hooks)
  771. }
  772. // SaveX is like Save, but panics if an error occurs.
  773. func (cuuo *CreditUsageUpdateOne) SaveX(ctx context.Context) *CreditUsage {
  774. node, err := cuuo.Save(ctx)
  775. if err != nil {
  776. panic(err)
  777. }
  778. return node
  779. }
  780. // Exec executes the query on the entity.
  781. func (cuuo *CreditUsageUpdateOne) Exec(ctx context.Context) error {
  782. _, err := cuuo.Save(ctx)
  783. return err
  784. }
  785. // ExecX is like Exec, but panics if an error occurs.
  786. func (cuuo *CreditUsageUpdateOne) ExecX(ctx context.Context) {
  787. if err := cuuo.Exec(ctx); err != nil {
  788. panic(err)
  789. }
  790. }
  791. // defaults sets the default values of the builder before save.
  792. func (cuuo *CreditUsageUpdateOne) defaults() error {
  793. if _, ok := cuuo.mutation.UpdatedAt(); !ok {
  794. if creditusage.UpdateDefaultUpdatedAt == nil {
  795. return fmt.Errorf("ent: uninitialized creditusage.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  796. }
  797. v := creditusage.UpdateDefaultUpdatedAt()
  798. cuuo.mutation.SetUpdatedAt(v)
  799. }
  800. return nil
  801. }
  802. // check runs all checks and user-defined validators on the builder.
  803. func (cuuo *CreditUsageUpdateOne) check() error {
  804. if v, ok := cuuo.mutation.UserID(); ok {
  805. if err := creditusage.UserIDValidator(v); err != nil {
  806. return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.user_id": %w`, err)}
  807. }
  808. }
  809. if v, ok := cuuo.mutation.Status(); ok {
  810. if err := creditusage.StatusValidator(v); err != nil {
  811. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.status": %w`, err)}
  812. }
  813. }
  814. if v, ok := cuuo.mutation.Reason(); ok {
  815. if err := creditusage.ReasonValidator(v); err != nil {
  816. return &ValidationError{Name: "reason", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.reason": %w`, err)}
  817. }
  818. }
  819. if v, ok := cuuo.mutation.Operator(); ok {
  820. if err := creditusage.OperatorValidator(v); err != nil {
  821. return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.operator": %w`, err)}
  822. }
  823. }
  824. return nil
  825. }
  826. func (cuuo *CreditUsageUpdateOne) sqlSave(ctx context.Context) (_node *CreditUsage, err error) {
  827. if err := cuuo.check(); err != nil {
  828. return _node, err
  829. }
  830. _spec := sqlgraph.NewUpdateSpec(creditusage.Table, creditusage.Columns, sqlgraph.NewFieldSpec(creditusage.FieldID, field.TypeUint64))
  831. id, ok := cuuo.mutation.ID()
  832. if !ok {
  833. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CreditUsage.id" for update`)}
  834. }
  835. _spec.Node.ID.Value = id
  836. if fields := cuuo.fields; len(fields) > 0 {
  837. _spec.Node.Columns = make([]string, 0, len(fields))
  838. _spec.Node.Columns = append(_spec.Node.Columns, creditusage.FieldID)
  839. for _, f := range fields {
  840. if !creditusage.ValidColumn(f) {
  841. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  842. }
  843. if f != creditusage.FieldID {
  844. _spec.Node.Columns = append(_spec.Node.Columns, f)
  845. }
  846. }
  847. }
  848. if ps := cuuo.mutation.predicates; len(ps) > 0 {
  849. _spec.Predicate = func(selector *sql.Selector) {
  850. for i := range ps {
  851. ps[i](selector)
  852. }
  853. }
  854. }
  855. if value, ok := cuuo.mutation.UpdatedAt(); ok {
  856. _spec.SetField(creditusage.FieldUpdatedAt, field.TypeTime, value)
  857. }
  858. if value, ok := cuuo.mutation.DeletedAt(); ok {
  859. _spec.SetField(creditusage.FieldDeletedAt, field.TypeTime, value)
  860. }
  861. if cuuo.mutation.DeletedAtCleared() {
  862. _spec.ClearField(creditusage.FieldDeletedAt, field.TypeTime)
  863. }
  864. if value, ok := cuuo.mutation.UserID(); ok {
  865. _spec.SetField(creditusage.FieldUserID, field.TypeString, value)
  866. }
  867. if cuuo.mutation.UserIDCleared() {
  868. _spec.ClearField(creditusage.FieldUserID, field.TypeString)
  869. }
  870. if value, ok := cuuo.mutation.Number(); ok {
  871. _spec.SetField(creditusage.FieldNumber, field.TypeFloat64, value)
  872. }
  873. if value, ok := cuuo.mutation.AddedNumber(); ok {
  874. _spec.AddField(creditusage.FieldNumber, field.TypeFloat64, value)
  875. }
  876. if value, ok := cuuo.mutation.PayNumber(); ok {
  877. _spec.SetField(creditusage.FieldPayNumber, field.TypeFloat64, value)
  878. }
  879. if value, ok := cuuo.mutation.AddedPayNumber(); ok {
  880. _spec.AddField(creditusage.FieldPayNumber, field.TypeFloat64, value)
  881. }
  882. if cuuo.mutation.PayNumberCleared() {
  883. _spec.ClearField(creditusage.FieldPayNumber, field.TypeFloat64)
  884. }
  885. if value, ok := cuuo.mutation.BeforeNumber(); ok {
  886. _spec.SetField(creditusage.FieldBeforeNumber, field.TypeFloat64, value)
  887. }
  888. if value, ok := cuuo.mutation.AddedBeforeNumber(); ok {
  889. _spec.AddField(creditusage.FieldBeforeNumber, field.TypeFloat64, value)
  890. }
  891. if cuuo.mutation.BeforeNumberCleared() {
  892. _spec.ClearField(creditusage.FieldBeforeNumber, field.TypeFloat64)
  893. }
  894. if value, ok := cuuo.mutation.AfterNumber(); ok {
  895. _spec.SetField(creditusage.FieldAfterNumber, field.TypeFloat64, value)
  896. }
  897. if value, ok := cuuo.mutation.AddedAfterNumber(); ok {
  898. _spec.AddField(creditusage.FieldAfterNumber, field.TypeFloat64, value)
  899. }
  900. if cuuo.mutation.AfterNumberCleared() {
  901. _spec.ClearField(creditusage.FieldAfterNumber, field.TypeFloat64)
  902. }
  903. if value, ok := cuuo.mutation.PayMethod(); ok {
  904. _spec.SetField(creditusage.FieldPayMethod, field.TypeInt, value)
  905. }
  906. if value, ok := cuuo.mutation.AddedPayMethod(); ok {
  907. _spec.AddField(creditusage.FieldPayMethod, field.TypeInt, value)
  908. }
  909. if cuuo.mutation.PayMethodCleared() {
  910. _spec.ClearField(creditusage.FieldPayMethod, field.TypeInt)
  911. }
  912. if value, ok := cuuo.mutation.Status(); ok {
  913. _spec.SetField(creditusage.FieldStatus, field.TypeInt, value)
  914. }
  915. if value, ok := cuuo.mutation.AddedStatus(); ok {
  916. _spec.AddField(creditusage.FieldStatus, field.TypeInt, value)
  917. }
  918. if cuuo.mutation.StatusCleared() {
  919. _spec.ClearField(creditusage.FieldStatus, field.TypeInt)
  920. }
  921. if value, ok := cuuo.mutation.Ntype(); ok {
  922. _spec.SetField(creditusage.FieldNtype, field.TypeInt, value)
  923. }
  924. if value, ok := cuuo.mutation.AddedNtype(); ok {
  925. _spec.AddField(creditusage.FieldNtype, field.TypeInt, value)
  926. }
  927. if value, ok := cuuo.mutation.Table(); ok {
  928. _spec.SetField(creditusage.FieldTable, field.TypeString, value)
  929. }
  930. if value, ok := cuuo.mutation.OrganizationID(); ok {
  931. _spec.SetField(creditusage.FieldOrganizationID, field.TypeUint64, value)
  932. }
  933. if value, ok := cuuo.mutation.AddedOrganizationID(); ok {
  934. _spec.AddField(creditusage.FieldOrganizationID, field.TypeUint64, value)
  935. }
  936. if cuuo.mutation.OrganizationIDCleared() {
  937. _spec.ClearField(creditusage.FieldOrganizationID, field.TypeUint64)
  938. }
  939. if value, ok := cuuo.mutation.Nid(); ok {
  940. _spec.SetField(creditusage.FieldNid, field.TypeUint64, value)
  941. }
  942. if value, ok := cuuo.mutation.AddedNid(); ok {
  943. _spec.AddField(creditusage.FieldNid, field.TypeUint64, value)
  944. }
  945. if value, ok := cuuo.mutation.Reason(); ok {
  946. _spec.SetField(creditusage.FieldReason, field.TypeString, value)
  947. }
  948. if value, ok := cuuo.mutation.Operator(); ok {
  949. _spec.SetField(creditusage.FieldOperator, field.TypeString, value)
  950. }
  951. _node = &CreditUsage{config: cuuo.config}
  952. _spec.Assign = _node.assignValues
  953. _spec.ScanValues = _node.scanValues
  954. if err = sqlgraph.UpdateNode(ctx, cuuo.driver, _spec); err != nil {
  955. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  956. err = &NotFoundError{creditusage.Label}
  957. } else if sqlgraph.IsConstraintError(err) {
  958. err = &ConstraintError{msg: err.Error(), wrap: err}
  959. }
  960. return nil, err
  961. }
  962. cuuo.mutation.done = true
  963. return _node, nil
  964. }