userplatformquota_update.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/predicate"
  12. "github.com/Wei-Shaw/sub2api/ent/user"
  13. "github.com/Wei-Shaw/sub2api/ent/userplatformquota"
  14. )
  15. // UserPlatformQuotaUpdate is the builder for updating UserPlatformQuota entities.
  16. type UserPlatformQuotaUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *UserPlatformQuotaMutation
  20. }
  21. // Where appends a list predicates to the UserPlatformQuotaUpdate builder.
  22. func (_u *UserPlatformQuotaUpdate) Where(ps ...predicate.UserPlatformQuota) *UserPlatformQuotaUpdate {
  23. _u.mutation.Where(ps...)
  24. return _u
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (_u *UserPlatformQuotaUpdate) SetUpdatedAt(v time.Time) *UserPlatformQuotaUpdate {
  28. _u.mutation.SetUpdatedAt(v)
  29. return _u
  30. }
  31. // SetDeletedAt sets the "deleted_at" field.
  32. func (_u *UserPlatformQuotaUpdate) SetDeletedAt(v time.Time) *UserPlatformQuotaUpdate {
  33. _u.mutation.SetDeletedAt(v)
  34. return _u
  35. }
  36. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  37. func (_u *UserPlatformQuotaUpdate) SetNillableDeletedAt(v *time.Time) *UserPlatformQuotaUpdate {
  38. if v != nil {
  39. _u.SetDeletedAt(*v)
  40. }
  41. return _u
  42. }
  43. // ClearDeletedAt clears the value of the "deleted_at" field.
  44. func (_u *UserPlatformQuotaUpdate) ClearDeletedAt() *UserPlatformQuotaUpdate {
  45. _u.mutation.ClearDeletedAt()
  46. return _u
  47. }
  48. // SetUserID sets the "user_id" field.
  49. func (_u *UserPlatformQuotaUpdate) SetUserID(v int64) *UserPlatformQuotaUpdate {
  50. _u.mutation.SetUserID(v)
  51. return _u
  52. }
  53. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  54. func (_u *UserPlatformQuotaUpdate) SetNillableUserID(v *int64) *UserPlatformQuotaUpdate {
  55. if v != nil {
  56. _u.SetUserID(*v)
  57. }
  58. return _u
  59. }
  60. // SetPlatform sets the "platform" field.
  61. func (_u *UserPlatformQuotaUpdate) SetPlatform(v string) *UserPlatformQuotaUpdate {
  62. _u.mutation.SetPlatform(v)
  63. return _u
  64. }
  65. // SetNillablePlatform sets the "platform" field if the given value is not nil.
  66. func (_u *UserPlatformQuotaUpdate) SetNillablePlatform(v *string) *UserPlatformQuotaUpdate {
  67. if v != nil {
  68. _u.SetPlatform(*v)
  69. }
  70. return _u
  71. }
  72. // SetDailyLimitUsd sets the "daily_limit_usd" field.
  73. func (_u *UserPlatformQuotaUpdate) SetDailyLimitUsd(v float64) *UserPlatformQuotaUpdate {
  74. _u.mutation.ResetDailyLimitUsd()
  75. _u.mutation.SetDailyLimitUsd(v)
  76. return _u
  77. }
  78. // SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
  79. func (_u *UserPlatformQuotaUpdate) SetNillableDailyLimitUsd(v *float64) *UserPlatformQuotaUpdate {
  80. if v != nil {
  81. _u.SetDailyLimitUsd(*v)
  82. }
  83. return _u
  84. }
  85. // AddDailyLimitUsd adds value to the "daily_limit_usd" field.
  86. func (_u *UserPlatformQuotaUpdate) AddDailyLimitUsd(v float64) *UserPlatformQuotaUpdate {
  87. _u.mutation.AddDailyLimitUsd(v)
  88. return _u
  89. }
  90. // ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
  91. func (_u *UserPlatformQuotaUpdate) ClearDailyLimitUsd() *UserPlatformQuotaUpdate {
  92. _u.mutation.ClearDailyLimitUsd()
  93. return _u
  94. }
  95. // SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
  96. func (_u *UserPlatformQuotaUpdate) SetWeeklyLimitUsd(v float64) *UserPlatformQuotaUpdate {
  97. _u.mutation.ResetWeeklyLimitUsd()
  98. _u.mutation.SetWeeklyLimitUsd(v)
  99. return _u
  100. }
  101. // SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
  102. func (_u *UserPlatformQuotaUpdate) SetNillableWeeklyLimitUsd(v *float64) *UserPlatformQuotaUpdate {
  103. if v != nil {
  104. _u.SetWeeklyLimitUsd(*v)
  105. }
  106. return _u
  107. }
  108. // AddWeeklyLimitUsd adds value to the "weekly_limit_usd" field.
  109. func (_u *UserPlatformQuotaUpdate) AddWeeklyLimitUsd(v float64) *UserPlatformQuotaUpdate {
  110. _u.mutation.AddWeeklyLimitUsd(v)
  111. return _u
  112. }
  113. // ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
  114. func (_u *UserPlatformQuotaUpdate) ClearWeeklyLimitUsd() *UserPlatformQuotaUpdate {
  115. _u.mutation.ClearWeeklyLimitUsd()
  116. return _u
  117. }
  118. // SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
  119. func (_u *UserPlatformQuotaUpdate) SetMonthlyLimitUsd(v float64) *UserPlatformQuotaUpdate {
  120. _u.mutation.ResetMonthlyLimitUsd()
  121. _u.mutation.SetMonthlyLimitUsd(v)
  122. return _u
  123. }
  124. // SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
  125. func (_u *UserPlatformQuotaUpdate) SetNillableMonthlyLimitUsd(v *float64) *UserPlatformQuotaUpdate {
  126. if v != nil {
  127. _u.SetMonthlyLimitUsd(*v)
  128. }
  129. return _u
  130. }
  131. // AddMonthlyLimitUsd adds value to the "monthly_limit_usd" field.
  132. func (_u *UserPlatformQuotaUpdate) AddMonthlyLimitUsd(v float64) *UserPlatformQuotaUpdate {
  133. _u.mutation.AddMonthlyLimitUsd(v)
  134. return _u
  135. }
  136. // ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
  137. func (_u *UserPlatformQuotaUpdate) ClearMonthlyLimitUsd() *UserPlatformQuotaUpdate {
  138. _u.mutation.ClearMonthlyLimitUsd()
  139. return _u
  140. }
  141. // SetDailyUsageUsd sets the "daily_usage_usd" field.
  142. func (_u *UserPlatformQuotaUpdate) SetDailyUsageUsd(v float64) *UserPlatformQuotaUpdate {
  143. _u.mutation.ResetDailyUsageUsd()
  144. _u.mutation.SetDailyUsageUsd(v)
  145. return _u
  146. }
  147. // SetNillableDailyUsageUsd sets the "daily_usage_usd" field if the given value is not nil.
  148. func (_u *UserPlatformQuotaUpdate) SetNillableDailyUsageUsd(v *float64) *UserPlatformQuotaUpdate {
  149. if v != nil {
  150. _u.SetDailyUsageUsd(*v)
  151. }
  152. return _u
  153. }
  154. // AddDailyUsageUsd adds value to the "daily_usage_usd" field.
  155. func (_u *UserPlatformQuotaUpdate) AddDailyUsageUsd(v float64) *UserPlatformQuotaUpdate {
  156. _u.mutation.AddDailyUsageUsd(v)
  157. return _u
  158. }
  159. // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
  160. func (_u *UserPlatformQuotaUpdate) SetWeeklyUsageUsd(v float64) *UserPlatformQuotaUpdate {
  161. _u.mutation.ResetWeeklyUsageUsd()
  162. _u.mutation.SetWeeklyUsageUsd(v)
  163. return _u
  164. }
  165. // SetNillableWeeklyUsageUsd sets the "weekly_usage_usd" field if the given value is not nil.
  166. func (_u *UserPlatformQuotaUpdate) SetNillableWeeklyUsageUsd(v *float64) *UserPlatformQuotaUpdate {
  167. if v != nil {
  168. _u.SetWeeklyUsageUsd(*v)
  169. }
  170. return _u
  171. }
  172. // AddWeeklyUsageUsd adds value to the "weekly_usage_usd" field.
  173. func (_u *UserPlatformQuotaUpdate) AddWeeklyUsageUsd(v float64) *UserPlatformQuotaUpdate {
  174. _u.mutation.AddWeeklyUsageUsd(v)
  175. return _u
  176. }
  177. // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
  178. func (_u *UserPlatformQuotaUpdate) SetMonthlyUsageUsd(v float64) *UserPlatformQuotaUpdate {
  179. _u.mutation.ResetMonthlyUsageUsd()
  180. _u.mutation.SetMonthlyUsageUsd(v)
  181. return _u
  182. }
  183. // SetNillableMonthlyUsageUsd sets the "monthly_usage_usd" field if the given value is not nil.
  184. func (_u *UserPlatformQuotaUpdate) SetNillableMonthlyUsageUsd(v *float64) *UserPlatformQuotaUpdate {
  185. if v != nil {
  186. _u.SetMonthlyUsageUsd(*v)
  187. }
  188. return _u
  189. }
  190. // AddMonthlyUsageUsd adds value to the "monthly_usage_usd" field.
  191. func (_u *UserPlatformQuotaUpdate) AddMonthlyUsageUsd(v float64) *UserPlatformQuotaUpdate {
  192. _u.mutation.AddMonthlyUsageUsd(v)
  193. return _u
  194. }
  195. // SetDailyWindowStart sets the "daily_window_start" field.
  196. func (_u *UserPlatformQuotaUpdate) SetDailyWindowStart(v time.Time) *UserPlatformQuotaUpdate {
  197. _u.mutation.SetDailyWindowStart(v)
  198. return _u
  199. }
  200. // SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
  201. func (_u *UserPlatformQuotaUpdate) SetNillableDailyWindowStart(v *time.Time) *UserPlatformQuotaUpdate {
  202. if v != nil {
  203. _u.SetDailyWindowStart(*v)
  204. }
  205. return _u
  206. }
  207. // ClearDailyWindowStart clears the value of the "daily_window_start" field.
  208. func (_u *UserPlatformQuotaUpdate) ClearDailyWindowStart() *UserPlatformQuotaUpdate {
  209. _u.mutation.ClearDailyWindowStart()
  210. return _u
  211. }
  212. // SetWeeklyWindowStart sets the "weekly_window_start" field.
  213. func (_u *UserPlatformQuotaUpdate) SetWeeklyWindowStart(v time.Time) *UserPlatformQuotaUpdate {
  214. _u.mutation.SetWeeklyWindowStart(v)
  215. return _u
  216. }
  217. // SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
  218. func (_u *UserPlatformQuotaUpdate) SetNillableWeeklyWindowStart(v *time.Time) *UserPlatformQuotaUpdate {
  219. if v != nil {
  220. _u.SetWeeklyWindowStart(*v)
  221. }
  222. return _u
  223. }
  224. // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
  225. func (_u *UserPlatformQuotaUpdate) ClearWeeklyWindowStart() *UserPlatformQuotaUpdate {
  226. _u.mutation.ClearWeeklyWindowStart()
  227. return _u
  228. }
  229. // SetMonthlyWindowStart sets the "monthly_window_start" field.
  230. func (_u *UserPlatformQuotaUpdate) SetMonthlyWindowStart(v time.Time) *UserPlatformQuotaUpdate {
  231. _u.mutation.SetMonthlyWindowStart(v)
  232. return _u
  233. }
  234. // SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
  235. func (_u *UserPlatformQuotaUpdate) SetNillableMonthlyWindowStart(v *time.Time) *UserPlatformQuotaUpdate {
  236. if v != nil {
  237. _u.SetMonthlyWindowStart(*v)
  238. }
  239. return _u
  240. }
  241. // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
  242. func (_u *UserPlatformQuotaUpdate) ClearMonthlyWindowStart() *UserPlatformQuotaUpdate {
  243. _u.mutation.ClearMonthlyWindowStart()
  244. return _u
  245. }
  246. // SetUser sets the "user" edge to the User entity.
  247. func (_u *UserPlatformQuotaUpdate) SetUser(v *User) *UserPlatformQuotaUpdate {
  248. return _u.SetUserID(v.ID)
  249. }
  250. // Mutation returns the UserPlatformQuotaMutation object of the builder.
  251. func (_u *UserPlatformQuotaUpdate) Mutation() *UserPlatformQuotaMutation {
  252. return _u.mutation
  253. }
  254. // ClearUser clears the "user" edge to the User entity.
  255. func (_u *UserPlatformQuotaUpdate) ClearUser() *UserPlatformQuotaUpdate {
  256. _u.mutation.ClearUser()
  257. return _u
  258. }
  259. // Save executes the query and returns the number of nodes affected by the update operation.
  260. func (_u *UserPlatformQuotaUpdate) Save(ctx context.Context) (int, error) {
  261. if err := _u.defaults(); err != nil {
  262. return 0, err
  263. }
  264. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  265. }
  266. // SaveX is like Save, but panics if an error occurs.
  267. func (_u *UserPlatformQuotaUpdate) SaveX(ctx context.Context) int {
  268. affected, err := _u.Save(ctx)
  269. if err != nil {
  270. panic(err)
  271. }
  272. return affected
  273. }
  274. // Exec executes the query.
  275. func (_u *UserPlatformQuotaUpdate) Exec(ctx context.Context) error {
  276. _, err := _u.Save(ctx)
  277. return err
  278. }
  279. // ExecX is like Exec, but panics if an error occurs.
  280. func (_u *UserPlatformQuotaUpdate) ExecX(ctx context.Context) {
  281. if err := _u.Exec(ctx); err != nil {
  282. panic(err)
  283. }
  284. }
  285. // defaults sets the default values of the builder before save.
  286. func (_u *UserPlatformQuotaUpdate) defaults() error {
  287. if _, ok := _u.mutation.UpdatedAt(); !ok {
  288. if userplatformquota.UpdateDefaultUpdatedAt == nil {
  289. return fmt.Errorf("ent: uninitialized userplatformquota.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  290. }
  291. v := userplatformquota.UpdateDefaultUpdatedAt()
  292. _u.mutation.SetUpdatedAt(v)
  293. }
  294. return nil
  295. }
  296. // check runs all checks and user-defined validators on the builder.
  297. func (_u *UserPlatformQuotaUpdate) check() error {
  298. if v, ok := _u.mutation.Platform(); ok {
  299. if err := userplatformquota.PlatformValidator(v); err != nil {
  300. return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "UserPlatformQuota.platform": %w`, err)}
  301. }
  302. }
  303. if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
  304. return errors.New(`ent: clearing a required unique edge "UserPlatformQuota.user"`)
  305. }
  306. return nil
  307. }
  308. func (_u *UserPlatformQuotaUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  309. if err := _u.check(); err != nil {
  310. return _node, err
  311. }
  312. _spec := sqlgraph.NewUpdateSpec(userplatformquota.Table, userplatformquota.Columns, sqlgraph.NewFieldSpec(userplatformquota.FieldID, field.TypeInt64))
  313. if ps := _u.mutation.predicates; len(ps) > 0 {
  314. _spec.Predicate = func(selector *sql.Selector) {
  315. for i := range ps {
  316. ps[i](selector)
  317. }
  318. }
  319. }
  320. if value, ok := _u.mutation.UpdatedAt(); ok {
  321. _spec.SetField(userplatformquota.FieldUpdatedAt, field.TypeTime, value)
  322. }
  323. if value, ok := _u.mutation.DeletedAt(); ok {
  324. _spec.SetField(userplatformquota.FieldDeletedAt, field.TypeTime, value)
  325. }
  326. if _u.mutation.DeletedAtCleared() {
  327. _spec.ClearField(userplatformquota.FieldDeletedAt, field.TypeTime)
  328. }
  329. if value, ok := _u.mutation.Platform(); ok {
  330. _spec.SetField(userplatformquota.FieldPlatform, field.TypeString, value)
  331. }
  332. if value, ok := _u.mutation.DailyLimitUsd(); ok {
  333. _spec.SetField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
  334. }
  335. if value, ok := _u.mutation.AddedDailyLimitUsd(); ok {
  336. _spec.AddField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
  337. }
  338. if _u.mutation.DailyLimitUsdCleared() {
  339. _spec.ClearField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64)
  340. }
  341. if value, ok := _u.mutation.WeeklyLimitUsd(); ok {
  342. _spec.SetField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
  343. }
  344. if value, ok := _u.mutation.AddedWeeklyLimitUsd(); ok {
  345. _spec.AddField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
  346. }
  347. if _u.mutation.WeeklyLimitUsdCleared() {
  348. _spec.ClearField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64)
  349. }
  350. if value, ok := _u.mutation.MonthlyLimitUsd(); ok {
  351. _spec.SetField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
  352. }
  353. if value, ok := _u.mutation.AddedMonthlyLimitUsd(); ok {
  354. _spec.AddField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
  355. }
  356. if _u.mutation.MonthlyLimitUsdCleared() {
  357. _spec.ClearField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64)
  358. }
  359. if value, ok := _u.mutation.DailyUsageUsd(); ok {
  360. _spec.SetField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
  361. }
  362. if value, ok := _u.mutation.AddedDailyUsageUsd(); ok {
  363. _spec.AddField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
  364. }
  365. if value, ok := _u.mutation.WeeklyUsageUsd(); ok {
  366. _spec.SetField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
  367. }
  368. if value, ok := _u.mutation.AddedWeeklyUsageUsd(); ok {
  369. _spec.AddField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
  370. }
  371. if value, ok := _u.mutation.MonthlyUsageUsd(); ok {
  372. _spec.SetField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
  373. }
  374. if value, ok := _u.mutation.AddedMonthlyUsageUsd(); ok {
  375. _spec.AddField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
  376. }
  377. if value, ok := _u.mutation.DailyWindowStart(); ok {
  378. _spec.SetField(userplatformquota.FieldDailyWindowStart, field.TypeTime, value)
  379. }
  380. if _u.mutation.DailyWindowStartCleared() {
  381. _spec.ClearField(userplatformquota.FieldDailyWindowStart, field.TypeTime)
  382. }
  383. if value, ok := _u.mutation.WeeklyWindowStart(); ok {
  384. _spec.SetField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime, value)
  385. }
  386. if _u.mutation.WeeklyWindowStartCleared() {
  387. _spec.ClearField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime)
  388. }
  389. if value, ok := _u.mutation.MonthlyWindowStart(); ok {
  390. _spec.SetField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime, value)
  391. }
  392. if _u.mutation.MonthlyWindowStartCleared() {
  393. _spec.ClearField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime)
  394. }
  395. if _u.mutation.UserCleared() {
  396. edge := &sqlgraph.EdgeSpec{
  397. Rel: sqlgraph.M2O,
  398. Inverse: true,
  399. Table: userplatformquota.UserTable,
  400. Columns: []string{userplatformquota.UserColumn},
  401. Bidi: false,
  402. Target: &sqlgraph.EdgeTarget{
  403. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  404. },
  405. }
  406. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  407. }
  408. if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
  409. edge := &sqlgraph.EdgeSpec{
  410. Rel: sqlgraph.M2O,
  411. Inverse: true,
  412. Table: userplatformquota.UserTable,
  413. Columns: []string{userplatformquota.UserColumn},
  414. Bidi: false,
  415. Target: &sqlgraph.EdgeTarget{
  416. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  417. },
  418. }
  419. for _, k := range nodes {
  420. edge.Target.Nodes = append(edge.Target.Nodes, k)
  421. }
  422. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  423. }
  424. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  425. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  426. err = &NotFoundError{userplatformquota.Label}
  427. } else if sqlgraph.IsConstraintError(err) {
  428. err = &ConstraintError{msg: err.Error(), wrap: err}
  429. }
  430. return 0, err
  431. }
  432. _u.mutation.done = true
  433. return _node, nil
  434. }
  435. // UserPlatformQuotaUpdateOne is the builder for updating a single UserPlatformQuota entity.
  436. type UserPlatformQuotaUpdateOne struct {
  437. config
  438. fields []string
  439. hooks []Hook
  440. mutation *UserPlatformQuotaMutation
  441. }
  442. // SetUpdatedAt sets the "updated_at" field.
  443. func (_u *UserPlatformQuotaUpdateOne) SetUpdatedAt(v time.Time) *UserPlatformQuotaUpdateOne {
  444. _u.mutation.SetUpdatedAt(v)
  445. return _u
  446. }
  447. // SetDeletedAt sets the "deleted_at" field.
  448. func (_u *UserPlatformQuotaUpdateOne) SetDeletedAt(v time.Time) *UserPlatformQuotaUpdateOne {
  449. _u.mutation.SetDeletedAt(v)
  450. return _u
  451. }
  452. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  453. func (_u *UserPlatformQuotaUpdateOne) SetNillableDeletedAt(v *time.Time) *UserPlatformQuotaUpdateOne {
  454. if v != nil {
  455. _u.SetDeletedAt(*v)
  456. }
  457. return _u
  458. }
  459. // ClearDeletedAt clears the value of the "deleted_at" field.
  460. func (_u *UserPlatformQuotaUpdateOne) ClearDeletedAt() *UserPlatformQuotaUpdateOne {
  461. _u.mutation.ClearDeletedAt()
  462. return _u
  463. }
  464. // SetUserID sets the "user_id" field.
  465. func (_u *UserPlatformQuotaUpdateOne) SetUserID(v int64) *UserPlatformQuotaUpdateOne {
  466. _u.mutation.SetUserID(v)
  467. return _u
  468. }
  469. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  470. func (_u *UserPlatformQuotaUpdateOne) SetNillableUserID(v *int64) *UserPlatformQuotaUpdateOne {
  471. if v != nil {
  472. _u.SetUserID(*v)
  473. }
  474. return _u
  475. }
  476. // SetPlatform sets the "platform" field.
  477. func (_u *UserPlatformQuotaUpdateOne) SetPlatform(v string) *UserPlatformQuotaUpdateOne {
  478. _u.mutation.SetPlatform(v)
  479. return _u
  480. }
  481. // SetNillablePlatform sets the "platform" field if the given value is not nil.
  482. func (_u *UserPlatformQuotaUpdateOne) SetNillablePlatform(v *string) *UserPlatformQuotaUpdateOne {
  483. if v != nil {
  484. _u.SetPlatform(*v)
  485. }
  486. return _u
  487. }
  488. // SetDailyLimitUsd sets the "daily_limit_usd" field.
  489. func (_u *UserPlatformQuotaUpdateOne) SetDailyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
  490. _u.mutation.ResetDailyLimitUsd()
  491. _u.mutation.SetDailyLimitUsd(v)
  492. return _u
  493. }
  494. // SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
  495. func (_u *UserPlatformQuotaUpdateOne) SetNillableDailyLimitUsd(v *float64) *UserPlatformQuotaUpdateOne {
  496. if v != nil {
  497. _u.SetDailyLimitUsd(*v)
  498. }
  499. return _u
  500. }
  501. // AddDailyLimitUsd adds value to the "daily_limit_usd" field.
  502. func (_u *UserPlatformQuotaUpdateOne) AddDailyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
  503. _u.mutation.AddDailyLimitUsd(v)
  504. return _u
  505. }
  506. // ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
  507. func (_u *UserPlatformQuotaUpdateOne) ClearDailyLimitUsd() *UserPlatformQuotaUpdateOne {
  508. _u.mutation.ClearDailyLimitUsd()
  509. return _u
  510. }
  511. // SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
  512. func (_u *UserPlatformQuotaUpdateOne) SetWeeklyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
  513. _u.mutation.ResetWeeklyLimitUsd()
  514. _u.mutation.SetWeeklyLimitUsd(v)
  515. return _u
  516. }
  517. // SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
  518. func (_u *UserPlatformQuotaUpdateOne) SetNillableWeeklyLimitUsd(v *float64) *UserPlatformQuotaUpdateOne {
  519. if v != nil {
  520. _u.SetWeeklyLimitUsd(*v)
  521. }
  522. return _u
  523. }
  524. // AddWeeklyLimitUsd adds value to the "weekly_limit_usd" field.
  525. func (_u *UserPlatformQuotaUpdateOne) AddWeeklyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
  526. _u.mutation.AddWeeklyLimitUsd(v)
  527. return _u
  528. }
  529. // ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
  530. func (_u *UserPlatformQuotaUpdateOne) ClearWeeklyLimitUsd() *UserPlatformQuotaUpdateOne {
  531. _u.mutation.ClearWeeklyLimitUsd()
  532. return _u
  533. }
  534. // SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
  535. func (_u *UserPlatformQuotaUpdateOne) SetMonthlyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
  536. _u.mutation.ResetMonthlyLimitUsd()
  537. _u.mutation.SetMonthlyLimitUsd(v)
  538. return _u
  539. }
  540. // SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
  541. func (_u *UserPlatformQuotaUpdateOne) SetNillableMonthlyLimitUsd(v *float64) *UserPlatformQuotaUpdateOne {
  542. if v != nil {
  543. _u.SetMonthlyLimitUsd(*v)
  544. }
  545. return _u
  546. }
  547. // AddMonthlyLimitUsd adds value to the "monthly_limit_usd" field.
  548. func (_u *UserPlatformQuotaUpdateOne) AddMonthlyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
  549. _u.mutation.AddMonthlyLimitUsd(v)
  550. return _u
  551. }
  552. // ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
  553. func (_u *UserPlatformQuotaUpdateOne) ClearMonthlyLimitUsd() *UserPlatformQuotaUpdateOne {
  554. _u.mutation.ClearMonthlyLimitUsd()
  555. return _u
  556. }
  557. // SetDailyUsageUsd sets the "daily_usage_usd" field.
  558. func (_u *UserPlatformQuotaUpdateOne) SetDailyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
  559. _u.mutation.ResetDailyUsageUsd()
  560. _u.mutation.SetDailyUsageUsd(v)
  561. return _u
  562. }
  563. // SetNillableDailyUsageUsd sets the "daily_usage_usd" field if the given value is not nil.
  564. func (_u *UserPlatformQuotaUpdateOne) SetNillableDailyUsageUsd(v *float64) *UserPlatformQuotaUpdateOne {
  565. if v != nil {
  566. _u.SetDailyUsageUsd(*v)
  567. }
  568. return _u
  569. }
  570. // AddDailyUsageUsd adds value to the "daily_usage_usd" field.
  571. func (_u *UserPlatformQuotaUpdateOne) AddDailyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
  572. _u.mutation.AddDailyUsageUsd(v)
  573. return _u
  574. }
  575. // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
  576. func (_u *UserPlatformQuotaUpdateOne) SetWeeklyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
  577. _u.mutation.ResetWeeklyUsageUsd()
  578. _u.mutation.SetWeeklyUsageUsd(v)
  579. return _u
  580. }
  581. // SetNillableWeeklyUsageUsd sets the "weekly_usage_usd" field if the given value is not nil.
  582. func (_u *UserPlatformQuotaUpdateOne) SetNillableWeeklyUsageUsd(v *float64) *UserPlatformQuotaUpdateOne {
  583. if v != nil {
  584. _u.SetWeeklyUsageUsd(*v)
  585. }
  586. return _u
  587. }
  588. // AddWeeklyUsageUsd adds value to the "weekly_usage_usd" field.
  589. func (_u *UserPlatformQuotaUpdateOne) AddWeeklyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
  590. _u.mutation.AddWeeklyUsageUsd(v)
  591. return _u
  592. }
  593. // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
  594. func (_u *UserPlatformQuotaUpdateOne) SetMonthlyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
  595. _u.mutation.ResetMonthlyUsageUsd()
  596. _u.mutation.SetMonthlyUsageUsd(v)
  597. return _u
  598. }
  599. // SetNillableMonthlyUsageUsd sets the "monthly_usage_usd" field if the given value is not nil.
  600. func (_u *UserPlatformQuotaUpdateOne) SetNillableMonthlyUsageUsd(v *float64) *UserPlatformQuotaUpdateOne {
  601. if v != nil {
  602. _u.SetMonthlyUsageUsd(*v)
  603. }
  604. return _u
  605. }
  606. // AddMonthlyUsageUsd adds value to the "monthly_usage_usd" field.
  607. func (_u *UserPlatformQuotaUpdateOne) AddMonthlyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
  608. _u.mutation.AddMonthlyUsageUsd(v)
  609. return _u
  610. }
  611. // SetDailyWindowStart sets the "daily_window_start" field.
  612. func (_u *UserPlatformQuotaUpdateOne) SetDailyWindowStart(v time.Time) *UserPlatformQuotaUpdateOne {
  613. _u.mutation.SetDailyWindowStart(v)
  614. return _u
  615. }
  616. // SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
  617. func (_u *UserPlatformQuotaUpdateOne) SetNillableDailyWindowStart(v *time.Time) *UserPlatformQuotaUpdateOne {
  618. if v != nil {
  619. _u.SetDailyWindowStart(*v)
  620. }
  621. return _u
  622. }
  623. // ClearDailyWindowStart clears the value of the "daily_window_start" field.
  624. func (_u *UserPlatformQuotaUpdateOne) ClearDailyWindowStart() *UserPlatformQuotaUpdateOne {
  625. _u.mutation.ClearDailyWindowStart()
  626. return _u
  627. }
  628. // SetWeeklyWindowStart sets the "weekly_window_start" field.
  629. func (_u *UserPlatformQuotaUpdateOne) SetWeeklyWindowStart(v time.Time) *UserPlatformQuotaUpdateOne {
  630. _u.mutation.SetWeeklyWindowStart(v)
  631. return _u
  632. }
  633. // SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
  634. func (_u *UserPlatformQuotaUpdateOne) SetNillableWeeklyWindowStart(v *time.Time) *UserPlatformQuotaUpdateOne {
  635. if v != nil {
  636. _u.SetWeeklyWindowStart(*v)
  637. }
  638. return _u
  639. }
  640. // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
  641. func (_u *UserPlatformQuotaUpdateOne) ClearWeeklyWindowStart() *UserPlatformQuotaUpdateOne {
  642. _u.mutation.ClearWeeklyWindowStart()
  643. return _u
  644. }
  645. // SetMonthlyWindowStart sets the "monthly_window_start" field.
  646. func (_u *UserPlatformQuotaUpdateOne) SetMonthlyWindowStart(v time.Time) *UserPlatformQuotaUpdateOne {
  647. _u.mutation.SetMonthlyWindowStart(v)
  648. return _u
  649. }
  650. // SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
  651. func (_u *UserPlatformQuotaUpdateOne) SetNillableMonthlyWindowStart(v *time.Time) *UserPlatformQuotaUpdateOne {
  652. if v != nil {
  653. _u.SetMonthlyWindowStart(*v)
  654. }
  655. return _u
  656. }
  657. // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
  658. func (_u *UserPlatformQuotaUpdateOne) ClearMonthlyWindowStart() *UserPlatformQuotaUpdateOne {
  659. _u.mutation.ClearMonthlyWindowStart()
  660. return _u
  661. }
  662. // SetUser sets the "user" edge to the User entity.
  663. func (_u *UserPlatformQuotaUpdateOne) SetUser(v *User) *UserPlatformQuotaUpdateOne {
  664. return _u.SetUserID(v.ID)
  665. }
  666. // Mutation returns the UserPlatformQuotaMutation object of the builder.
  667. func (_u *UserPlatformQuotaUpdateOne) Mutation() *UserPlatformQuotaMutation {
  668. return _u.mutation
  669. }
  670. // ClearUser clears the "user" edge to the User entity.
  671. func (_u *UserPlatformQuotaUpdateOne) ClearUser() *UserPlatformQuotaUpdateOne {
  672. _u.mutation.ClearUser()
  673. return _u
  674. }
  675. // Where appends a list predicates to the UserPlatformQuotaUpdate builder.
  676. func (_u *UserPlatformQuotaUpdateOne) Where(ps ...predicate.UserPlatformQuota) *UserPlatformQuotaUpdateOne {
  677. _u.mutation.Where(ps...)
  678. return _u
  679. }
  680. // Select allows selecting one or more fields (columns) of the returned entity.
  681. // The default is selecting all fields defined in the entity schema.
  682. func (_u *UserPlatformQuotaUpdateOne) Select(field string, fields ...string) *UserPlatformQuotaUpdateOne {
  683. _u.fields = append([]string{field}, fields...)
  684. return _u
  685. }
  686. // Save executes the query and returns the updated UserPlatformQuota entity.
  687. func (_u *UserPlatformQuotaUpdateOne) Save(ctx context.Context) (*UserPlatformQuota, error) {
  688. if err := _u.defaults(); err != nil {
  689. return nil, err
  690. }
  691. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  692. }
  693. // SaveX is like Save, but panics if an error occurs.
  694. func (_u *UserPlatformQuotaUpdateOne) SaveX(ctx context.Context) *UserPlatformQuota {
  695. node, err := _u.Save(ctx)
  696. if err != nil {
  697. panic(err)
  698. }
  699. return node
  700. }
  701. // Exec executes the query on the entity.
  702. func (_u *UserPlatformQuotaUpdateOne) Exec(ctx context.Context) error {
  703. _, err := _u.Save(ctx)
  704. return err
  705. }
  706. // ExecX is like Exec, but panics if an error occurs.
  707. func (_u *UserPlatformQuotaUpdateOne) ExecX(ctx context.Context) {
  708. if err := _u.Exec(ctx); err != nil {
  709. panic(err)
  710. }
  711. }
  712. // defaults sets the default values of the builder before save.
  713. func (_u *UserPlatformQuotaUpdateOne) defaults() error {
  714. if _, ok := _u.mutation.UpdatedAt(); !ok {
  715. if userplatformquota.UpdateDefaultUpdatedAt == nil {
  716. return fmt.Errorf("ent: uninitialized userplatformquota.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  717. }
  718. v := userplatformquota.UpdateDefaultUpdatedAt()
  719. _u.mutation.SetUpdatedAt(v)
  720. }
  721. return nil
  722. }
  723. // check runs all checks and user-defined validators on the builder.
  724. func (_u *UserPlatformQuotaUpdateOne) check() error {
  725. if v, ok := _u.mutation.Platform(); ok {
  726. if err := userplatformquota.PlatformValidator(v); err != nil {
  727. return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "UserPlatformQuota.platform": %w`, err)}
  728. }
  729. }
  730. if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
  731. return errors.New(`ent: clearing a required unique edge "UserPlatformQuota.user"`)
  732. }
  733. return nil
  734. }
  735. func (_u *UserPlatformQuotaUpdateOne) sqlSave(ctx context.Context) (_node *UserPlatformQuota, err error) {
  736. if err := _u.check(); err != nil {
  737. return _node, err
  738. }
  739. _spec := sqlgraph.NewUpdateSpec(userplatformquota.Table, userplatformquota.Columns, sqlgraph.NewFieldSpec(userplatformquota.FieldID, field.TypeInt64))
  740. id, ok := _u.mutation.ID()
  741. if !ok {
  742. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserPlatformQuota.id" for update`)}
  743. }
  744. _spec.Node.ID.Value = id
  745. if fields := _u.fields; len(fields) > 0 {
  746. _spec.Node.Columns = make([]string, 0, len(fields))
  747. _spec.Node.Columns = append(_spec.Node.Columns, userplatformquota.FieldID)
  748. for _, f := range fields {
  749. if !userplatformquota.ValidColumn(f) {
  750. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  751. }
  752. if f != userplatformquota.FieldID {
  753. _spec.Node.Columns = append(_spec.Node.Columns, f)
  754. }
  755. }
  756. }
  757. if ps := _u.mutation.predicates; len(ps) > 0 {
  758. _spec.Predicate = func(selector *sql.Selector) {
  759. for i := range ps {
  760. ps[i](selector)
  761. }
  762. }
  763. }
  764. if value, ok := _u.mutation.UpdatedAt(); ok {
  765. _spec.SetField(userplatformquota.FieldUpdatedAt, field.TypeTime, value)
  766. }
  767. if value, ok := _u.mutation.DeletedAt(); ok {
  768. _spec.SetField(userplatformquota.FieldDeletedAt, field.TypeTime, value)
  769. }
  770. if _u.mutation.DeletedAtCleared() {
  771. _spec.ClearField(userplatformquota.FieldDeletedAt, field.TypeTime)
  772. }
  773. if value, ok := _u.mutation.Platform(); ok {
  774. _spec.SetField(userplatformquota.FieldPlatform, field.TypeString, value)
  775. }
  776. if value, ok := _u.mutation.DailyLimitUsd(); ok {
  777. _spec.SetField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
  778. }
  779. if value, ok := _u.mutation.AddedDailyLimitUsd(); ok {
  780. _spec.AddField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
  781. }
  782. if _u.mutation.DailyLimitUsdCleared() {
  783. _spec.ClearField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64)
  784. }
  785. if value, ok := _u.mutation.WeeklyLimitUsd(); ok {
  786. _spec.SetField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
  787. }
  788. if value, ok := _u.mutation.AddedWeeklyLimitUsd(); ok {
  789. _spec.AddField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
  790. }
  791. if _u.mutation.WeeklyLimitUsdCleared() {
  792. _spec.ClearField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64)
  793. }
  794. if value, ok := _u.mutation.MonthlyLimitUsd(); ok {
  795. _spec.SetField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
  796. }
  797. if value, ok := _u.mutation.AddedMonthlyLimitUsd(); ok {
  798. _spec.AddField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
  799. }
  800. if _u.mutation.MonthlyLimitUsdCleared() {
  801. _spec.ClearField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64)
  802. }
  803. if value, ok := _u.mutation.DailyUsageUsd(); ok {
  804. _spec.SetField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
  805. }
  806. if value, ok := _u.mutation.AddedDailyUsageUsd(); ok {
  807. _spec.AddField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
  808. }
  809. if value, ok := _u.mutation.WeeklyUsageUsd(); ok {
  810. _spec.SetField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
  811. }
  812. if value, ok := _u.mutation.AddedWeeklyUsageUsd(); ok {
  813. _spec.AddField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
  814. }
  815. if value, ok := _u.mutation.MonthlyUsageUsd(); ok {
  816. _spec.SetField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
  817. }
  818. if value, ok := _u.mutation.AddedMonthlyUsageUsd(); ok {
  819. _spec.AddField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
  820. }
  821. if value, ok := _u.mutation.DailyWindowStart(); ok {
  822. _spec.SetField(userplatformquota.FieldDailyWindowStart, field.TypeTime, value)
  823. }
  824. if _u.mutation.DailyWindowStartCleared() {
  825. _spec.ClearField(userplatformquota.FieldDailyWindowStart, field.TypeTime)
  826. }
  827. if value, ok := _u.mutation.WeeklyWindowStart(); ok {
  828. _spec.SetField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime, value)
  829. }
  830. if _u.mutation.WeeklyWindowStartCleared() {
  831. _spec.ClearField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime)
  832. }
  833. if value, ok := _u.mutation.MonthlyWindowStart(); ok {
  834. _spec.SetField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime, value)
  835. }
  836. if _u.mutation.MonthlyWindowStartCleared() {
  837. _spec.ClearField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime)
  838. }
  839. if _u.mutation.UserCleared() {
  840. edge := &sqlgraph.EdgeSpec{
  841. Rel: sqlgraph.M2O,
  842. Inverse: true,
  843. Table: userplatformquota.UserTable,
  844. Columns: []string{userplatformquota.UserColumn},
  845. Bidi: false,
  846. Target: &sqlgraph.EdgeTarget{
  847. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  848. },
  849. }
  850. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  851. }
  852. if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
  853. edge := &sqlgraph.EdgeSpec{
  854. Rel: sqlgraph.M2O,
  855. Inverse: true,
  856. Table: userplatformquota.UserTable,
  857. Columns: []string{userplatformquota.UserColumn},
  858. Bidi: false,
  859. Target: &sqlgraph.EdgeTarget{
  860. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  861. },
  862. }
  863. for _, k := range nodes {
  864. edge.Target.Nodes = append(edge.Target.Nodes, k)
  865. }
  866. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  867. }
  868. _node = &UserPlatformQuota{config: _u.config}
  869. _spec.Assign = _node.assignValues
  870. _spec.ScanValues = _node.scanValues
  871. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  872. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  873. err = &NotFoundError{userplatformquota.Label}
  874. } else if sqlgraph.IsConstraintError(err) {
  875. err = &ConstraintError{msg: err.Error(), wrap: err}
  876. }
  877. return nil, err
  878. }
  879. _u.mutation.done = true
  880. return _node, nil
  881. }