usersubscription_create.go 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700
  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/group"
  12. "github.com/Wei-Shaw/sub2api/ent/usagelog"
  13. "github.com/Wei-Shaw/sub2api/ent/user"
  14. "github.com/Wei-Shaw/sub2api/ent/usersubscription"
  15. )
  16. // UserSubscriptionCreate is the builder for creating a UserSubscription entity.
  17. type UserSubscriptionCreate struct {
  18. config
  19. mutation *UserSubscriptionMutation
  20. hooks []Hook
  21. conflict []sql.ConflictOption
  22. }
  23. // SetCreatedAt sets the "created_at" field.
  24. func (_c *UserSubscriptionCreate) SetCreatedAt(v time.Time) *UserSubscriptionCreate {
  25. _c.mutation.SetCreatedAt(v)
  26. return _c
  27. }
  28. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  29. func (_c *UserSubscriptionCreate) SetNillableCreatedAt(v *time.Time) *UserSubscriptionCreate {
  30. if v != nil {
  31. _c.SetCreatedAt(*v)
  32. }
  33. return _c
  34. }
  35. // SetUpdatedAt sets the "updated_at" field.
  36. func (_c *UserSubscriptionCreate) SetUpdatedAt(v time.Time) *UserSubscriptionCreate {
  37. _c.mutation.SetUpdatedAt(v)
  38. return _c
  39. }
  40. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  41. func (_c *UserSubscriptionCreate) SetNillableUpdatedAt(v *time.Time) *UserSubscriptionCreate {
  42. if v != nil {
  43. _c.SetUpdatedAt(*v)
  44. }
  45. return _c
  46. }
  47. // SetDeletedAt sets the "deleted_at" field.
  48. func (_c *UserSubscriptionCreate) SetDeletedAt(v time.Time) *UserSubscriptionCreate {
  49. _c.mutation.SetDeletedAt(v)
  50. return _c
  51. }
  52. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  53. func (_c *UserSubscriptionCreate) SetNillableDeletedAt(v *time.Time) *UserSubscriptionCreate {
  54. if v != nil {
  55. _c.SetDeletedAt(*v)
  56. }
  57. return _c
  58. }
  59. // SetUserID sets the "user_id" field.
  60. func (_c *UserSubscriptionCreate) SetUserID(v int64) *UserSubscriptionCreate {
  61. _c.mutation.SetUserID(v)
  62. return _c
  63. }
  64. // SetGroupID sets the "group_id" field.
  65. func (_c *UserSubscriptionCreate) SetGroupID(v int64) *UserSubscriptionCreate {
  66. _c.mutation.SetGroupID(v)
  67. return _c
  68. }
  69. // SetStartsAt sets the "starts_at" field.
  70. func (_c *UserSubscriptionCreate) SetStartsAt(v time.Time) *UserSubscriptionCreate {
  71. _c.mutation.SetStartsAt(v)
  72. return _c
  73. }
  74. // SetExpiresAt sets the "expires_at" field.
  75. func (_c *UserSubscriptionCreate) SetExpiresAt(v time.Time) *UserSubscriptionCreate {
  76. _c.mutation.SetExpiresAt(v)
  77. return _c
  78. }
  79. // SetStatus sets the "status" field.
  80. func (_c *UserSubscriptionCreate) SetStatus(v string) *UserSubscriptionCreate {
  81. _c.mutation.SetStatus(v)
  82. return _c
  83. }
  84. // SetNillableStatus sets the "status" field if the given value is not nil.
  85. func (_c *UserSubscriptionCreate) SetNillableStatus(v *string) *UserSubscriptionCreate {
  86. if v != nil {
  87. _c.SetStatus(*v)
  88. }
  89. return _c
  90. }
  91. // SetDailyWindowStart sets the "daily_window_start" field.
  92. func (_c *UserSubscriptionCreate) SetDailyWindowStart(v time.Time) *UserSubscriptionCreate {
  93. _c.mutation.SetDailyWindowStart(v)
  94. return _c
  95. }
  96. // SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
  97. func (_c *UserSubscriptionCreate) SetNillableDailyWindowStart(v *time.Time) *UserSubscriptionCreate {
  98. if v != nil {
  99. _c.SetDailyWindowStart(*v)
  100. }
  101. return _c
  102. }
  103. // SetWeeklyWindowStart sets the "weekly_window_start" field.
  104. func (_c *UserSubscriptionCreate) SetWeeklyWindowStart(v time.Time) *UserSubscriptionCreate {
  105. _c.mutation.SetWeeklyWindowStart(v)
  106. return _c
  107. }
  108. // SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
  109. func (_c *UserSubscriptionCreate) SetNillableWeeklyWindowStart(v *time.Time) *UserSubscriptionCreate {
  110. if v != nil {
  111. _c.SetWeeklyWindowStart(*v)
  112. }
  113. return _c
  114. }
  115. // SetMonthlyWindowStart sets the "monthly_window_start" field.
  116. func (_c *UserSubscriptionCreate) SetMonthlyWindowStart(v time.Time) *UserSubscriptionCreate {
  117. _c.mutation.SetMonthlyWindowStart(v)
  118. return _c
  119. }
  120. // SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
  121. func (_c *UserSubscriptionCreate) SetNillableMonthlyWindowStart(v *time.Time) *UserSubscriptionCreate {
  122. if v != nil {
  123. _c.SetMonthlyWindowStart(*v)
  124. }
  125. return _c
  126. }
  127. // SetDailyUsageUsd sets the "daily_usage_usd" field.
  128. func (_c *UserSubscriptionCreate) SetDailyUsageUsd(v float64) *UserSubscriptionCreate {
  129. _c.mutation.SetDailyUsageUsd(v)
  130. return _c
  131. }
  132. // SetNillableDailyUsageUsd sets the "daily_usage_usd" field if the given value is not nil.
  133. func (_c *UserSubscriptionCreate) SetNillableDailyUsageUsd(v *float64) *UserSubscriptionCreate {
  134. if v != nil {
  135. _c.SetDailyUsageUsd(*v)
  136. }
  137. return _c
  138. }
  139. // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
  140. func (_c *UserSubscriptionCreate) SetWeeklyUsageUsd(v float64) *UserSubscriptionCreate {
  141. _c.mutation.SetWeeklyUsageUsd(v)
  142. return _c
  143. }
  144. // SetNillableWeeklyUsageUsd sets the "weekly_usage_usd" field if the given value is not nil.
  145. func (_c *UserSubscriptionCreate) SetNillableWeeklyUsageUsd(v *float64) *UserSubscriptionCreate {
  146. if v != nil {
  147. _c.SetWeeklyUsageUsd(*v)
  148. }
  149. return _c
  150. }
  151. // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
  152. func (_c *UserSubscriptionCreate) SetMonthlyUsageUsd(v float64) *UserSubscriptionCreate {
  153. _c.mutation.SetMonthlyUsageUsd(v)
  154. return _c
  155. }
  156. // SetNillableMonthlyUsageUsd sets the "monthly_usage_usd" field if the given value is not nil.
  157. func (_c *UserSubscriptionCreate) SetNillableMonthlyUsageUsd(v *float64) *UserSubscriptionCreate {
  158. if v != nil {
  159. _c.SetMonthlyUsageUsd(*v)
  160. }
  161. return _c
  162. }
  163. // SetAssignedBy sets the "assigned_by" field.
  164. func (_c *UserSubscriptionCreate) SetAssignedBy(v int64) *UserSubscriptionCreate {
  165. _c.mutation.SetAssignedBy(v)
  166. return _c
  167. }
  168. // SetNillableAssignedBy sets the "assigned_by" field if the given value is not nil.
  169. func (_c *UserSubscriptionCreate) SetNillableAssignedBy(v *int64) *UserSubscriptionCreate {
  170. if v != nil {
  171. _c.SetAssignedBy(*v)
  172. }
  173. return _c
  174. }
  175. // SetAssignedAt sets the "assigned_at" field.
  176. func (_c *UserSubscriptionCreate) SetAssignedAt(v time.Time) *UserSubscriptionCreate {
  177. _c.mutation.SetAssignedAt(v)
  178. return _c
  179. }
  180. // SetNillableAssignedAt sets the "assigned_at" field if the given value is not nil.
  181. func (_c *UserSubscriptionCreate) SetNillableAssignedAt(v *time.Time) *UserSubscriptionCreate {
  182. if v != nil {
  183. _c.SetAssignedAt(*v)
  184. }
  185. return _c
  186. }
  187. // SetNotes sets the "notes" field.
  188. func (_c *UserSubscriptionCreate) SetNotes(v string) *UserSubscriptionCreate {
  189. _c.mutation.SetNotes(v)
  190. return _c
  191. }
  192. // SetNillableNotes sets the "notes" field if the given value is not nil.
  193. func (_c *UserSubscriptionCreate) SetNillableNotes(v *string) *UserSubscriptionCreate {
  194. if v != nil {
  195. _c.SetNotes(*v)
  196. }
  197. return _c
  198. }
  199. // SetUser sets the "user" edge to the User entity.
  200. func (_c *UserSubscriptionCreate) SetUser(v *User) *UserSubscriptionCreate {
  201. return _c.SetUserID(v.ID)
  202. }
  203. // SetGroup sets the "group" edge to the Group entity.
  204. func (_c *UserSubscriptionCreate) SetGroup(v *Group) *UserSubscriptionCreate {
  205. return _c.SetGroupID(v.ID)
  206. }
  207. // SetAssignedByUserID sets the "assigned_by_user" edge to the User entity by ID.
  208. func (_c *UserSubscriptionCreate) SetAssignedByUserID(id int64) *UserSubscriptionCreate {
  209. _c.mutation.SetAssignedByUserID(id)
  210. return _c
  211. }
  212. // SetNillableAssignedByUserID sets the "assigned_by_user" edge to the User entity by ID if the given value is not nil.
  213. func (_c *UserSubscriptionCreate) SetNillableAssignedByUserID(id *int64) *UserSubscriptionCreate {
  214. if id != nil {
  215. _c = _c.SetAssignedByUserID(*id)
  216. }
  217. return _c
  218. }
  219. // SetAssignedByUser sets the "assigned_by_user" edge to the User entity.
  220. func (_c *UserSubscriptionCreate) SetAssignedByUser(v *User) *UserSubscriptionCreate {
  221. return _c.SetAssignedByUserID(v.ID)
  222. }
  223. // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
  224. func (_c *UserSubscriptionCreate) AddUsageLogIDs(ids ...int64) *UserSubscriptionCreate {
  225. _c.mutation.AddUsageLogIDs(ids...)
  226. return _c
  227. }
  228. // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
  229. func (_c *UserSubscriptionCreate) AddUsageLogs(v ...*UsageLog) *UserSubscriptionCreate {
  230. ids := make([]int64, len(v))
  231. for i := range v {
  232. ids[i] = v[i].ID
  233. }
  234. return _c.AddUsageLogIDs(ids...)
  235. }
  236. // Mutation returns the UserSubscriptionMutation object of the builder.
  237. func (_c *UserSubscriptionCreate) Mutation() *UserSubscriptionMutation {
  238. return _c.mutation
  239. }
  240. // Save creates the UserSubscription in the database.
  241. func (_c *UserSubscriptionCreate) Save(ctx context.Context) (*UserSubscription, error) {
  242. if err := _c.defaults(); err != nil {
  243. return nil, err
  244. }
  245. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  246. }
  247. // SaveX calls Save and panics if Save returns an error.
  248. func (_c *UserSubscriptionCreate) SaveX(ctx context.Context) *UserSubscription {
  249. v, err := _c.Save(ctx)
  250. if err != nil {
  251. panic(err)
  252. }
  253. return v
  254. }
  255. // Exec executes the query.
  256. func (_c *UserSubscriptionCreate) Exec(ctx context.Context) error {
  257. _, err := _c.Save(ctx)
  258. return err
  259. }
  260. // ExecX is like Exec, but panics if an error occurs.
  261. func (_c *UserSubscriptionCreate) ExecX(ctx context.Context) {
  262. if err := _c.Exec(ctx); err != nil {
  263. panic(err)
  264. }
  265. }
  266. // defaults sets the default values of the builder before save.
  267. func (_c *UserSubscriptionCreate) defaults() error {
  268. if _, ok := _c.mutation.CreatedAt(); !ok {
  269. if usersubscription.DefaultCreatedAt == nil {
  270. return fmt.Errorf("ent: uninitialized usersubscription.DefaultCreatedAt (forgotten import ent/runtime?)")
  271. }
  272. v := usersubscription.DefaultCreatedAt()
  273. _c.mutation.SetCreatedAt(v)
  274. }
  275. if _, ok := _c.mutation.UpdatedAt(); !ok {
  276. if usersubscription.DefaultUpdatedAt == nil {
  277. return fmt.Errorf("ent: uninitialized usersubscription.DefaultUpdatedAt (forgotten import ent/runtime?)")
  278. }
  279. v := usersubscription.DefaultUpdatedAt()
  280. _c.mutation.SetUpdatedAt(v)
  281. }
  282. if _, ok := _c.mutation.Status(); !ok {
  283. v := usersubscription.DefaultStatus
  284. _c.mutation.SetStatus(v)
  285. }
  286. if _, ok := _c.mutation.DailyUsageUsd(); !ok {
  287. v := usersubscription.DefaultDailyUsageUsd
  288. _c.mutation.SetDailyUsageUsd(v)
  289. }
  290. if _, ok := _c.mutation.WeeklyUsageUsd(); !ok {
  291. v := usersubscription.DefaultWeeklyUsageUsd
  292. _c.mutation.SetWeeklyUsageUsd(v)
  293. }
  294. if _, ok := _c.mutation.MonthlyUsageUsd(); !ok {
  295. v := usersubscription.DefaultMonthlyUsageUsd
  296. _c.mutation.SetMonthlyUsageUsd(v)
  297. }
  298. if _, ok := _c.mutation.AssignedAt(); !ok {
  299. if usersubscription.DefaultAssignedAt == nil {
  300. return fmt.Errorf("ent: uninitialized usersubscription.DefaultAssignedAt (forgotten import ent/runtime?)")
  301. }
  302. v := usersubscription.DefaultAssignedAt()
  303. _c.mutation.SetAssignedAt(v)
  304. }
  305. return nil
  306. }
  307. // check runs all checks and user-defined validators on the builder.
  308. func (_c *UserSubscriptionCreate) check() error {
  309. if _, ok := _c.mutation.CreatedAt(); !ok {
  310. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UserSubscription.created_at"`)}
  311. }
  312. if _, ok := _c.mutation.UpdatedAt(); !ok {
  313. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UserSubscription.updated_at"`)}
  314. }
  315. if _, ok := _c.mutation.UserID(); !ok {
  316. return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "UserSubscription.user_id"`)}
  317. }
  318. if _, ok := _c.mutation.GroupID(); !ok {
  319. return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "UserSubscription.group_id"`)}
  320. }
  321. if _, ok := _c.mutation.StartsAt(); !ok {
  322. return &ValidationError{Name: "starts_at", err: errors.New(`ent: missing required field "UserSubscription.starts_at"`)}
  323. }
  324. if _, ok := _c.mutation.ExpiresAt(); !ok {
  325. return &ValidationError{Name: "expires_at", err: errors.New(`ent: missing required field "UserSubscription.expires_at"`)}
  326. }
  327. if _, ok := _c.mutation.Status(); !ok {
  328. return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "UserSubscription.status"`)}
  329. }
  330. if v, ok := _c.mutation.Status(); ok {
  331. if err := usersubscription.StatusValidator(v); err != nil {
  332. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UserSubscription.status": %w`, err)}
  333. }
  334. }
  335. if _, ok := _c.mutation.DailyUsageUsd(); !ok {
  336. return &ValidationError{Name: "daily_usage_usd", err: errors.New(`ent: missing required field "UserSubscription.daily_usage_usd"`)}
  337. }
  338. if _, ok := _c.mutation.WeeklyUsageUsd(); !ok {
  339. return &ValidationError{Name: "weekly_usage_usd", err: errors.New(`ent: missing required field "UserSubscription.weekly_usage_usd"`)}
  340. }
  341. if _, ok := _c.mutation.MonthlyUsageUsd(); !ok {
  342. return &ValidationError{Name: "monthly_usage_usd", err: errors.New(`ent: missing required field "UserSubscription.monthly_usage_usd"`)}
  343. }
  344. if _, ok := _c.mutation.AssignedAt(); !ok {
  345. return &ValidationError{Name: "assigned_at", err: errors.New(`ent: missing required field "UserSubscription.assigned_at"`)}
  346. }
  347. if len(_c.mutation.UserIDs()) == 0 {
  348. return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "UserSubscription.user"`)}
  349. }
  350. if len(_c.mutation.GroupIDs()) == 0 {
  351. return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "UserSubscription.group"`)}
  352. }
  353. return nil
  354. }
  355. func (_c *UserSubscriptionCreate) sqlSave(ctx context.Context) (*UserSubscription, error) {
  356. if err := _c.check(); err != nil {
  357. return nil, err
  358. }
  359. _node, _spec := _c.createSpec()
  360. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  361. if sqlgraph.IsConstraintError(err) {
  362. err = &ConstraintError{msg: err.Error(), wrap: err}
  363. }
  364. return nil, err
  365. }
  366. id := _spec.ID.Value.(int64)
  367. _node.ID = int64(id)
  368. _c.mutation.id = &_node.ID
  369. _c.mutation.done = true
  370. return _node, nil
  371. }
  372. func (_c *UserSubscriptionCreate) createSpec() (*UserSubscription, *sqlgraph.CreateSpec) {
  373. var (
  374. _node = &UserSubscription{config: _c.config}
  375. _spec = sqlgraph.NewCreateSpec(usersubscription.Table, sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64))
  376. )
  377. _spec.OnConflict = _c.conflict
  378. if value, ok := _c.mutation.CreatedAt(); ok {
  379. _spec.SetField(usersubscription.FieldCreatedAt, field.TypeTime, value)
  380. _node.CreatedAt = value
  381. }
  382. if value, ok := _c.mutation.UpdatedAt(); ok {
  383. _spec.SetField(usersubscription.FieldUpdatedAt, field.TypeTime, value)
  384. _node.UpdatedAt = value
  385. }
  386. if value, ok := _c.mutation.DeletedAt(); ok {
  387. _spec.SetField(usersubscription.FieldDeletedAt, field.TypeTime, value)
  388. _node.DeletedAt = &value
  389. }
  390. if value, ok := _c.mutation.StartsAt(); ok {
  391. _spec.SetField(usersubscription.FieldStartsAt, field.TypeTime, value)
  392. _node.StartsAt = value
  393. }
  394. if value, ok := _c.mutation.ExpiresAt(); ok {
  395. _spec.SetField(usersubscription.FieldExpiresAt, field.TypeTime, value)
  396. _node.ExpiresAt = value
  397. }
  398. if value, ok := _c.mutation.Status(); ok {
  399. _spec.SetField(usersubscription.FieldStatus, field.TypeString, value)
  400. _node.Status = value
  401. }
  402. if value, ok := _c.mutation.DailyWindowStart(); ok {
  403. _spec.SetField(usersubscription.FieldDailyWindowStart, field.TypeTime, value)
  404. _node.DailyWindowStart = &value
  405. }
  406. if value, ok := _c.mutation.WeeklyWindowStart(); ok {
  407. _spec.SetField(usersubscription.FieldWeeklyWindowStart, field.TypeTime, value)
  408. _node.WeeklyWindowStart = &value
  409. }
  410. if value, ok := _c.mutation.MonthlyWindowStart(); ok {
  411. _spec.SetField(usersubscription.FieldMonthlyWindowStart, field.TypeTime, value)
  412. _node.MonthlyWindowStart = &value
  413. }
  414. if value, ok := _c.mutation.DailyUsageUsd(); ok {
  415. _spec.SetField(usersubscription.FieldDailyUsageUsd, field.TypeFloat64, value)
  416. _node.DailyUsageUsd = value
  417. }
  418. if value, ok := _c.mutation.WeeklyUsageUsd(); ok {
  419. _spec.SetField(usersubscription.FieldWeeklyUsageUsd, field.TypeFloat64, value)
  420. _node.WeeklyUsageUsd = value
  421. }
  422. if value, ok := _c.mutation.MonthlyUsageUsd(); ok {
  423. _spec.SetField(usersubscription.FieldMonthlyUsageUsd, field.TypeFloat64, value)
  424. _node.MonthlyUsageUsd = value
  425. }
  426. if value, ok := _c.mutation.AssignedAt(); ok {
  427. _spec.SetField(usersubscription.FieldAssignedAt, field.TypeTime, value)
  428. _node.AssignedAt = value
  429. }
  430. if value, ok := _c.mutation.Notes(); ok {
  431. _spec.SetField(usersubscription.FieldNotes, field.TypeString, value)
  432. _node.Notes = &value
  433. }
  434. if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
  435. edge := &sqlgraph.EdgeSpec{
  436. Rel: sqlgraph.M2O,
  437. Inverse: true,
  438. Table: usersubscription.UserTable,
  439. Columns: []string{usersubscription.UserColumn},
  440. Bidi: false,
  441. Target: &sqlgraph.EdgeTarget{
  442. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  443. },
  444. }
  445. for _, k := range nodes {
  446. edge.Target.Nodes = append(edge.Target.Nodes, k)
  447. }
  448. _node.UserID = nodes[0]
  449. _spec.Edges = append(_spec.Edges, edge)
  450. }
  451. if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
  452. edge := &sqlgraph.EdgeSpec{
  453. Rel: sqlgraph.M2O,
  454. Inverse: true,
  455. Table: usersubscription.GroupTable,
  456. Columns: []string{usersubscription.GroupColumn},
  457. Bidi: false,
  458. Target: &sqlgraph.EdgeTarget{
  459. IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
  460. },
  461. }
  462. for _, k := range nodes {
  463. edge.Target.Nodes = append(edge.Target.Nodes, k)
  464. }
  465. _node.GroupID = nodes[0]
  466. _spec.Edges = append(_spec.Edges, edge)
  467. }
  468. if nodes := _c.mutation.AssignedByUserIDs(); len(nodes) > 0 {
  469. edge := &sqlgraph.EdgeSpec{
  470. Rel: sqlgraph.M2O,
  471. Inverse: true,
  472. Table: usersubscription.AssignedByUserTable,
  473. Columns: []string{usersubscription.AssignedByUserColumn},
  474. Bidi: false,
  475. Target: &sqlgraph.EdgeTarget{
  476. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  477. },
  478. }
  479. for _, k := range nodes {
  480. edge.Target.Nodes = append(edge.Target.Nodes, k)
  481. }
  482. _node.AssignedBy = &nodes[0]
  483. _spec.Edges = append(_spec.Edges, edge)
  484. }
  485. if nodes := _c.mutation.UsageLogsIDs(); len(nodes) > 0 {
  486. edge := &sqlgraph.EdgeSpec{
  487. Rel: sqlgraph.O2M,
  488. Inverse: false,
  489. Table: usersubscription.UsageLogsTable,
  490. Columns: []string{usersubscription.UsageLogsColumn},
  491. Bidi: false,
  492. Target: &sqlgraph.EdgeTarget{
  493. IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
  494. },
  495. }
  496. for _, k := range nodes {
  497. edge.Target.Nodes = append(edge.Target.Nodes, k)
  498. }
  499. _spec.Edges = append(_spec.Edges, edge)
  500. }
  501. return _node, _spec
  502. }
  503. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  504. // of the `INSERT` statement. For example:
  505. //
  506. // client.UserSubscription.Create().
  507. // SetCreatedAt(v).
  508. // OnConflict(
  509. // // Update the row with the new values
  510. // // the was proposed for insertion.
  511. // sql.ResolveWithNewValues(),
  512. // ).
  513. // // Override some of the fields with custom
  514. // // update values.
  515. // Update(func(u *ent.UserSubscriptionUpsert) {
  516. // SetCreatedAt(v+v).
  517. // }).
  518. // Exec(ctx)
  519. func (_c *UserSubscriptionCreate) OnConflict(opts ...sql.ConflictOption) *UserSubscriptionUpsertOne {
  520. _c.conflict = opts
  521. return &UserSubscriptionUpsertOne{
  522. create: _c,
  523. }
  524. }
  525. // OnConflictColumns calls `OnConflict` and configures the columns
  526. // as conflict target. Using this option is equivalent to using:
  527. //
  528. // client.UserSubscription.Create().
  529. // OnConflict(sql.ConflictColumns(columns...)).
  530. // Exec(ctx)
  531. func (_c *UserSubscriptionCreate) OnConflictColumns(columns ...string) *UserSubscriptionUpsertOne {
  532. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  533. return &UserSubscriptionUpsertOne{
  534. create: _c,
  535. }
  536. }
  537. type (
  538. // UserSubscriptionUpsertOne is the builder for "upsert"-ing
  539. // one UserSubscription node.
  540. UserSubscriptionUpsertOne struct {
  541. create *UserSubscriptionCreate
  542. }
  543. // UserSubscriptionUpsert is the "OnConflict" setter.
  544. UserSubscriptionUpsert struct {
  545. *sql.UpdateSet
  546. }
  547. )
  548. // SetUpdatedAt sets the "updated_at" field.
  549. func (u *UserSubscriptionUpsert) SetUpdatedAt(v time.Time) *UserSubscriptionUpsert {
  550. u.Set(usersubscription.FieldUpdatedAt, v)
  551. return u
  552. }
  553. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  554. func (u *UserSubscriptionUpsert) UpdateUpdatedAt() *UserSubscriptionUpsert {
  555. u.SetExcluded(usersubscription.FieldUpdatedAt)
  556. return u
  557. }
  558. // SetDeletedAt sets the "deleted_at" field.
  559. func (u *UserSubscriptionUpsert) SetDeletedAt(v time.Time) *UserSubscriptionUpsert {
  560. u.Set(usersubscription.FieldDeletedAt, v)
  561. return u
  562. }
  563. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  564. func (u *UserSubscriptionUpsert) UpdateDeletedAt() *UserSubscriptionUpsert {
  565. u.SetExcluded(usersubscription.FieldDeletedAt)
  566. return u
  567. }
  568. // ClearDeletedAt clears the value of the "deleted_at" field.
  569. func (u *UserSubscriptionUpsert) ClearDeletedAt() *UserSubscriptionUpsert {
  570. u.SetNull(usersubscription.FieldDeletedAt)
  571. return u
  572. }
  573. // SetUserID sets the "user_id" field.
  574. func (u *UserSubscriptionUpsert) SetUserID(v int64) *UserSubscriptionUpsert {
  575. u.Set(usersubscription.FieldUserID, v)
  576. return u
  577. }
  578. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  579. func (u *UserSubscriptionUpsert) UpdateUserID() *UserSubscriptionUpsert {
  580. u.SetExcluded(usersubscription.FieldUserID)
  581. return u
  582. }
  583. // SetGroupID sets the "group_id" field.
  584. func (u *UserSubscriptionUpsert) SetGroupID(v int64) *UserSubscriptionUpsert {
  585. u.Set(usersubscription.FieldGroupID, v)
  586. return u
  587. }
  588. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  589. func (u *UserSubscriptionUpsert) UpdateGroupID() *UserSubscriptionUpsert {
  590. u.SetExcluded(usersubscription.FieldGroupID)
  591. return u
  592. }
  593. // SetStartsAt sets the "starts_at" field.
  594. func (u *UserSubscriptionUpsert) SetStartsAt(v time.Time) *UserSubscriptionUpsert {
  595. u.Set(usersubscription.FieldStartsAt, v)
  596. return u
  597. }
  598. // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
  599. func (u *UserSubscriptionUpsert) UpdateStartsAt() *UserSubscriptionUpsert {
  600. u.SetExcluded(usersubscription.FieldStartsAt)
  601. return u
  602. }
  603. // SetExpiresAt sets the "expires_at" field.
  604. func (u *UserSubscriptionUpsert) SetExpiresAt(v time.Time) *UserSubscriptionUpsert {
  605. u.Set(usersubscription.FieldExpiresAt, v)
  606. return u
  607. }
  608. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  609. func (u *UserSubscriptionUpsert) UpdateExpiresAt() *UserSubscriptionUpsert {
  610. u.SetExcluded(usersubscription.FieldExpiresAt)
  611. return u
  612. }
  613. // SetStatus sets the "status" field.
  614. func (u *UserSubscriptionUpsert) SetStatus(v string) *UserSubscriptionUpsert {
  615. u.Set(usersubscription.FieldStatus, v)
  616. return u
  617. }
  618. // UpdateStatus sets the "status" field to the value that was provided on create.
  619. func (u *UserSubscriptionUpsert) UpdateStatus() *UserSubscriptionUpsert {
  620. u.SetExcluded(usersubscription.FieldStatus)
  621. return u
  622. }
  623. // SetDailyWindowStart sets the "daily_window_start" field.
  624. func (u *UserSubscriptionUpsert) SetDailyWindowStart(v time.Time) *UserSubscriptionUpsert {
  625. u.Set(usersubscription.FieldDailyWindowStart, v)
  626. return u
  627. }
  628. // UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
  629. func (u *UserSubscriptionUpsert) UpdateDailyWindowStart() *UserSubscriptionUpsert {
  630. u.SetExcluded(usersubscription.FieldDailyWindowStart)
  631. return u
  632. }
  633. // ClearDailyWindowStart clears the value of the "daily_window_start" field.
  634. func (u *UserSubscriptionUpsert) ClearDailyWindowStart() *UserSubscriptionUpsert {
  635. u.SetNull(usersubscription.FieldDailyWindowStart)
  636. return u
  637. }
  638. // SetWeeklyWindowStart sets the "weekly_window_start" field.
  639. func (u *UserSubscriptionUpsert) SetWeeklyWindowStart(v time.Time) *UserSubscriptionUpsert {
  640. u.Set(usersubscription.FieldWeeklyWindowStart, v)
  641. return u
  642. }
  643. // UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
  644. func (u *UserSubscriptionUpsert) UpdateWeeklyWindowStart() *UserSubscriptionUpsert {
  645. u.SetExcluded(usersubscription.FieldWeeklyWindowStart)
  646. return u
  647. }
  648. // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
  649. func (u *UserSubscriptionUpsert) ClearWeeklyWindowStart() *UserSubscriptionUpsert {
  650. u.SetNull(usersubscription.FieldWeeklyWindowStart)
  651. return u
  652. }
  653. // SetMonthlyWindowStart sets the "monthly_window_start" field.
  654. func (u *UserSubscriptionUpsert) SetMonthlyWindowStart(v time.Time) *UserSubscriptionUpsert {
  655. u.Set(usersubscription.FieldMonthlyWindowStart, v)
  656. return u
  657. }
  658. // UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
  659. func (u *UserSubscriptionUpsert) UpdateMonthlyWindowStart() *UserSubscriptionUpsert {
  660. u.SetExcluded(usersubscription.FieldMonthlyWindowStart)
  661. return u
  662. }
  663. // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
  664. func (u *UserSubscriptionUpsert) ClearMonthlyWindowStart() *UserSubscriptionUpsert {
  665. u.SetNull(usersubscription.FieldMonthlyWindowStart)
  666. return u
  667. }
  668. // SetDailyUsageUsd sets the "daily_usage_usd" field.
  669. func (u *UserSubscriptionUpsert) SetDailyUsageUsd(v float64) *UserSubscriptionUpsert {
  670. u.Set(usersubscription.FieldDailyUsageUsd, v)
  671. return u
  672. }
  673. // UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
  674. func (u *UserSubscriptionUpsert) UpdateDailyUsageUsd() *UserSubscriptionUpsert {
  675. u.SetExcluded(usersubscription.FieldDailyUsageUsd)
  676. return u
  677. }
  678. // AddDailyUsageUsd adds v to the "daily_usage_usd" field.
  679. func (u *UserSubscriptionUpsert) AddDailyUsageUsd(v float64) *UserSubscriptionUpsert {
  680. u.Add(usersubscription.FieldDailyUsageUsd, v)
  681. return u
  682. }
  683. // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
  684. func (u *UserSubscriptionUpsert) SetWeeklyUsageUsd(v float64) *UserSubscriptionUpsert {
  685. u.Set(usersubscription.FieldWeeklyUsageUsd, v)
  686. return u
  687. }
  688. // UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
  689. func (u *UserSubscriptionUpsert) UpdateWeeklyUsageUsd() *UserSubscriptionUpsert {
  690. u.SetExcluded(usersubscription.FieldWeeklyUsageUsd)
  691. return u
  692. }
  693. // AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
  694. func (u *UserSubscriptionUpsert) AddWeeklyUsageUsd(v float64) *UserSubscriptionUpsert {
  695. u.Add(usersubscription.FieldWeeklyUsageUsd, v)
  696. return u
  697. }
  698. // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
  699. func (u *UserSubscriptionUpsert) SetMonthlyUsageUsd(v float64) *UserSubscriptionUpsert {
  700. u.Set(usersubscription.FieldMonthlyUsageUsd, v)
  701. return u
  702. }
  703. // UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
  704. func (u *UserSubscriptionUpsert) UpdateMonthlyUsageUsd() *UserSubscriptionUpsert {
  705. u.SetExcluded(usersubscription.FieldMonthlyUsageUsd)
  706. return u
  707. }
  708. // AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
  709. func (u *UserSubscriptionUpsert) AddMonthlyUsageUsd(v float64) *UserSubscriptionUpsert {
  710. u.Add(usersubscription.FieldMonthlyUsageUsd, v)
  711. return u
  712. }
  713. // SetAssignedBy sets the "assigned_by" field.
  714. func (u *UserSubscriptionUpsert) SetAssignedBy(v int64) *UserSubscriptionUpsert {
  715. u.Set(usersubscription.FieldAssignedBy, v)
  716. return u
  717. }
  718. // UpdateAssignedBy sets the "assigned_by" field to the value that was provided on create.
  719. func (u *UserSubscriptionUpsert) UpdateAssignedBy() *UserSubscriptionUpsert {
  720. u.SetExcluded(usersubscription.FieldAssignedBy)
  721. return u
  722. }
  723. // ClearAssignedBy clears the value of the "assigned_by" field.
  724. func (u *UserSubscriptionUpsert) ClearAssignedBy() *UserSubscriptionUpsert {
  725. u.SetNull(usersubscription.FieldAssignedBy)
  726. return u
  727. }
  728. // SetAssignedAt sets the "assigned_at" field.
  729. func (u *UserSubscriptionUpsert) SetAssignedAt(v time.Time) *UserSubscriptionUpsert {
  730. u.Set(usersubscription.FieldAssignedAt, v)
  731. return u
  732. }
  733. // UpdateAssignedAt sets the "assigned_at" field to the value that was provided on create.
  734. func (u *UserSubscriptionUpsert) UpdateAssignedAt() *UserSubscriptionUpsert {
  735. u.SetExcluded(usersubscription.FieldAssignedAt)
  736. return u
  737. }
  738. // SetNotes sets the "notes" field.
  739. func (u *UserSubscriptionUpsert) SetNotes(v string) *UserSubscriptionUpsert {
  740. u.Set(usersubscription.FieldNotes, v)
  741. return u
  742. }
  743. // UpdateNotes sets the "notes" field to the value that was provided on create.
  744. func (u *UserSubscriptionUpsert) UpdateNotes() *UserSubscriptionUpsert {
  745. u.SetExcluded(usersubscription.FieldNotes)
  746. return u
  747. }
  748. // ClearNotes clears the value of the "notes" field.
  749. func (u *UserSubscriptionUpsert) ClearNotes() *UserSubscriptionUpsert {
  750. u.SetNull(usersubscription.FieldNotes)
  751. return u
  752. }
  753. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  754. // Using this option is equivalent to using:
  755. //
  756. // client.UserSubscription.Create().
  757. // OnConflict(
  758. // sql.ResolveWithNewValues(),
  759. // ).
  760. // Exec(ctx)
  761. func (u *UserSubscriptionUpsertOne) UpdateNewValues() *UserSubscriptionUpsertOne {
  762. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  763. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  764. if _, exists := u.create.mutation.CreatedAt(); exists {
  765. s.SetIgnore(usersubscription.FieldCreatedAt)
  766. }
  767. }))
  768. return u
  769. }
  770. // Ignore sets each column to itself in case of conflict.
  771. // Using this option is equivalent to using:
  772. //
  773. // client.UserSubscription.Create().
  774. // OnConflict(sql.ResolveWithIgnore()).
  775. // Exec(ctx)
  776. func (u *UserSubscriptionUpsertOne) Ignore() *UserSubscriptionUpsertOne {
  777. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  778. return u
  779. }
  780. // DoNothing configures the conflict_action to `DO NOTHING`.
  781. // Supported only by SQLite and PostgreSQL.
  782. func (u *UserSubscriptionUpsertOne) DoNothing() *UserSubscriptionUpsertOne {
  783. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  784. return u
  785. }
  786. // Update allows overriding fields `UPDATE` values. See the UserSubscriptionCreate.OnConflict
  787. // documentation for more info.
  788. func (u *UserSubscriptionUpsertOne) Update(set func(*UserSubscriptionUpsert)) *UserSubscriptionUpsertOne {
  789. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  790. set(&UserSubscriptionUpsert{UpdateSet: update})
  791. }))
  792. return u
  793. }
  794. // SetUpdatedAt sets the "updated_at" field.
  795. func (u *UserSubscriptionUpsertOne) SetUpdatedAt(v time.Time) *UserSubscriptionUpsertOne {
  796. return u.Update(func(s *UserSubscriptionUpsert) {
  797. s.SetUpdatedAt(v)
  798. })
  799. }
  800. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  801. func (u *UserSubscriptionUpsertOne) UpdateUpdatedAt() *UserSubscriptionUpsertOne {
  802. return u.Update(func(s *UserSubscriptionUpsert) {
  803. s.UpdateUpdatedAt()
  804. })
  805. }
  806. // SetDeletedAt sets the "deleted_at" field.
  807. func (u *UserSubscriptionUpsertOne) SetDeletedAt(v time.Time) *UserSubscriptionUpsertOne {
  808. return u.Update(func(s *UserSubscriptionUpsert) {
  809. s.SetDeletedAt(v)
  810. })
  811. }
  812. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  813. func (u *UserSubscriptionUpsertOne) UpdateDeletedAt() *UserSubscriptionUpsertOne {
  814. return u.Update(func(s *UserSubscriptionUpsert) {
  815. s.UpdateDeletedAt()
  816. })
  817. }
  818. // ClearDeletedAt clears the value of the "deleted_at" field.
  819. func (u *UserSubscriptionUpsertOne) ClearDeletedAt() *UserSubscriptionUpsertOne {
  820. return u.Update(func(s *UserSubscriptionUpsert) {
  821. s.ClearDeletedAt()
  822. })
  823. }
  824. // SetUserID sets the "user_id" field.
  825. func (u *UserSubscriptionUpsertOne) SetUserID(v int64) *UserSubscriptionUpsertOne {
  826. return u.Update(func(s *UserSubscriptionUpsert) {
  827. s.SetUserID(v)
  828. })
  829. }
  830. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  831. func (u *UserSubscriptionUpsertOne) UpdateUserID() *UserSubscriptionUpsertOne {
  832. return u.Update(func(s *UserSubscriptionUpsert) {
  833. s.UpdateUserID()
  834. })
  835. }
  836. // SetGroupID sets the "group_id" field.
  837. func (u *UserSubscriptionUpsertOne) SetGroupID(v int64) *UserSubscriptionUpsertOne {
  838. return u.Update(func(s *UserSubscriptionUpsert) {
  839. s.SetGroupID(v)
  840. })
  841. }
  842. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  843. func (u *UserSubscriptionUpsertOne) UpdateGroupID() *UserSubscriptionUpsertOne {
  844. return u.Update(func(s *UserSubscriptionUpsert) {
  845. s.UpdateGroupID()
  846. })
  847. }
  848. // SetStartsAt sets the "starts_at" field.
  849. func (u *UserSubscriptionUpsertOne) SetStartsAt(v time.Time) *UserSubscriptionUpsertOne {
  850. return u.Update(func(s *UserSubscriptionUpsert) {
  851. s.SetStartsAt(v)
  852. })
  853. }
  854. // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
  855. func (u *UserSubscriptionUpsertOne) UpdateStartsAt() *UserSubscriptionUpsertOne {
  856. return u.Update(func(s *UserSubscriptionUpsert) {
  857. s.UpdateStartsAt()
  858. })
  859. }
  860. // SetExpiresAt sets the "expires_at" field.
  861. func (u *UserSubscriptionUpsertOne) SetExpiresAt(v time.Time) *UserSubscriptionUpsertOne {
  862. return u.Update(func(s *UserSubscriptionUpsert) {
  863. s.SetExpiresAt(v)
  864. })
  865. }
  866. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  867. func (u *UserSubscriptionUpsertOne) UpdateExpiresAt() *UserSubscriptionUpsertOne {
  868. return u.Update(func(s *UserSubscriptionUpsert) {
  869. s.UpdateExpiresAt()
  870. })
  871. }
  872. // SetStatus sets the "status" field.
  873. func (u *UserSubscriptionUpsertOne) SetStatus(v string) *UserSubscriptionUpsertOne {
  874. return u.Update(func(s *UserSubscriptionUpsert) {
  875. s.SetStatus(v)
  876. })
  877. }
  878. // UpdateStatus sets the "status" field to the value that was provided on create.
  879. func (u *UserSubscriptionUpsertOne) UpdateStatus() *UserSubscriptionUpsertOne {
  880. return u.Update(func(s *UserSubscriptionUpsert) {
  881. s.UpdateStatus()
  882. })
  883. }
  884. // SetDailyWindowStart sets the "daily_window_start" field.
  885. func (u *UserSubscriptionUpsertOne) SetDailyWindowStart(v time.Time) *UserSubscriptionUpsertOne {
  886. return u.Update(func(s *UserSubscriptionUpsert) {
  887. s.SetDailyWindowStart(v)
  888. })
  889. }
  890. // UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
  891. func (u *UserSubscriptionUpsertOne) UpdateDailyWindowStart() *UserSubscriptionUpsertOne {
  892. return u.Update(func(s *UserSubscriptionUpsert) {
  893. s.UpdateDailyWindowStart()
  894. })
  895. }
  896. // ClearDailyWindowStart clears the value of the "daily_window_start" field.
  897. func (u *UserSubscriptionUpsertOne) ClearDailyWindowStart() *UserSubscriptionUpsertOne {
  898. return u.Update(func(s *UserSubscriptionUpsert) {
  899. s.ClearDailyWindowStart()
  900. })
  901. }
  902. // SetWeeklyWindowStart sets the "weekly_window_start" field.
  903. func (u *UserSubscriptionUpsertOne) SetWeeklyWindowStart(v time.Time) *UserSubscriptionUpsertOne {
  904. return u.Update(func(s *UserSubscriptionUpsert) {
  905. s.SetWeeklyWindowStart(v)
  906. })
  907. }
  908. // UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
  909. func (u *UserSubscriptionUpsertOne) UpdateWeeklyWindowStart() *UserSubscriptionUpsertOne {
  910. return u.Update(func(s *UserSubscriptionUpsert) {
  911. s.UpdateWeeklyWindowStart()
  912. })
  913. }
  914. // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
  915. func (u *UserSubscriptionUpsertOne) ClearWeeklyWindowStart() *UserSubscriptionUpsertOne {
  916. return u.Update(func(s *UserSubscriptionUpsert) {
  917. s.ClearWeeklyWindowStart()
  918. })
  919. }
  920. // SetMonthlyWindowStart sets the "monthly_window_start" field.
  921. func (u *UserSubscriptionUpsertOne) SetMonthlyWindowStart(v time.Time) *UserSubscriptionUpsertOne {
  922. return u.Update(func(s *UserSubscriptionUpsert) {
  923. s.SetMonthlyWindowStart(v)
  924. })
  925. }
  926. // UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
  927. func (u *UserSubscriptionUpsertOne) UpdateMonthlyWindowStart() *UserSubscriptionUpsertOne {
  928. return u.Update(func(s *UserSubscriptionUpsert) {
  929. s.UpdateMonthlyWindowStart()
  930. })
  931. }
  932. // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
  933. func (u *UserSubscriptionUpsertOne) ClearMonthlyWindowStart() *UserSubscriptionUpsertOne {
  934. return u.Update(func(s *UserSubscriptionUpsert) {
  935. s.ClearMonthlyWindowStart()
  936. })
  937. }
  938. // SetDailyUsageUsd sets the "daily_usage_usd" field.
  939. func (u *UserSubscriptionUpsertOne) SetDailyUsageUsd(v float64) *UserSubscriptionUpsertOne {
  940. return u.Update(func(s *UserSubscriptionUpsert) {
  941. s.SetDailyUsageUsd(v)
  942. })
  943. }
  944. // AddDailyUsageUsd adds v to the "daily_usage_usd" field.
  945. func (u *UserSubscriptionUpsertOne) AddDailyUsageUsd(v float64) *UserSubscriptionUpsertOne {
  946. return u.Update(func(s *UserSubscriptionUpsert) {
  947. s.AddDailyUsageUsd(v)
  948. })
  949. }
  950. // UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
  951. func (u *UserSubscriptionUpsertOne) UpdateDailyUsageUsd() *UserSubscriptionUpsertOne {
  952. return u.Update(func(s *UserSubscriptionUpsert) {
  953. s.UpdateDailyUsageUsd()
  954. })
  955. }
  956. // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
  957. func (u *UserSubscriptionUpsertOne) SetWeeklyUsageUsd(v float64) *UserSubscriptionUpsertOne {
  958. return u.Update(func(s *UserSubscriptionUpsert) {
  959. s.SetWeeklyUsageUsd(v)
  960. })
  961. }
  962. // AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
  963. func (u *UserSubscriptionUpsertOne) AddWeeklyUsageUsd(v float64) *UserSubscriptionUpsertOne {
  964. return u.Update(func(s *UserSubscriptionUpsert) {
  965. s.AddWeeklyUsageUsd(v)
  966. })
  967. }
  968. // UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
  969. func (u *UserSubscriptionUpsertOne) UpdateWeeklyUsageUsd() *UserSubscriptionUpsertOne {
  970. return u.Update(func(s *UserSubscriptionUpsert) {
  971. s.UpdateWeeklyUsageUsd()
  972. })
  973. }
  974. // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
  975. func (u *UserSubscriptionUpsertOne) SetMonthlyUsageUsd(v float64) *UserSubscriptionUpsertOne {
  976. return u.Update(func(s *UserSubscriptionUpsert) {
  977. s.SetMonthlyUsageUsd(v)
  978. })
  979. }
  980. // AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
  981. func (u *UserSubscriptionUpsertOne) AddMonthlyUsageUsd(v float64) *UserSubscriptionUpsertOne {
  982. return u.Update(func(s *UserSubscriptionUpsert) {
  983. s.AddMonthlyUsageUsd(v)
  984. })
  985. }
  986. // UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
  987. func (u *UserSubscriptionUpsertOne) UpdateMonthlyUsageUsd() *UserSubscriptionUpsertOne {
  988. return u.Update(func(s *UserSubscriptionUpsert) {
  989. s.UpdateMonthlyUsageUsd()
  990. })
  991. }
  992. // SetAssignedBy sets the "assigned_by" field.
  993. func (u *UserSubscriptionUpsertOne) SetAssignedBy(v int64) *UserSubscriptionUpsertOne {
  994. return u.Update(func(s *UserSubscriptionUpsert) {
  995. s.SetAssignedBy(v)
  996. })
  997. }
  998. // UpdateAssignedBy sets the "assigned_by" field to the value that was provided on create.
  999. func (u *UserSubscriptionUpsertOne) UpdateAssignedBy() *UserSubscriptionUpsertOne {
  1000. return u.Update(func(s *UserSubscriptionUpsert) {
  1001. s.UpdateAssignedBy()
  1002. })
  1003. }
  1004. // ClearAssignedBy clears the value of the "assigned_by" field.
  1005. func (u *UserSubscriptionUpsertOne) ClearAssignedBy() *UserSubscriptionUpsertOne {
  1006. return u.Update(func(s *UserSubscriptionUpsert) {
  1007. s.ClearAssignedBy()
  1008. })
  1009. }
  1010. // SetAssignedAt sets the "assigned_at" field.
  1011. func (u *UserSubscriptionUpsertOne) SetAssignedAt(v time.Time) *UserSubscriptionUpsertOne {
  1012. return u.Update(func(s *UserSubscriptionUpsert) {
  1013. s.SetAssignedAt(v)
  1014. })
  1015. }
  1016. // UpdateAssignedAt sets the "assigned_at" field to the value that was provided on create.
  1017. func (u *UserSubscriptionUpsertOne) UpdateAssignedAt() *UserSubscriptionUpsertOne {
  1018. return u.Update(func(s *UserSubscriptionUpsert) {
  1019. s.UpdateAssignedAt()
  1020. })
  1021. }
  1022. // SetNotes sets the "notes" field.
  1023. func (u *UserSubscriptionUpsertOne) SetNotes(v string) *UserSubscriptionUpsertOne {
  1024. return u.Update(func(s *UserSubscriptionUpsert) {
  1025. s.SetNotes(v)
  1026. })
  1027. }
  1028. // UpdateNotes sets the "notes" field to the value that was provided on create.
  1029. func (u *UserSubscriptionUpsertOne) UpdateNotes() *UserSubscriptionUpsertOne {
  1030. return u.Update(func(s *UserSubscriptionUpsert) {
  1031. s.UpdateNotes()
  1032. })
  1033. }
  1034. // ClearNotes clears the value of the "notes" field.
  1035. func (u *UserSubscriptionUpsertOne) ClearNotes() *UserSubscriptionUpsertOne {
  1036. return u.Update(func(s *UserSubscriptionUpsert) {
  1037. s.ClearNotes()
  1038. })
  1039. }
  1040. // Exec executes the query.
  1041. func (u *UserSubscriptionUpsertOne) Exec(ctx context.Context) error {
  1042. if len(u.create.conflict) == 0 {
  1043. return errors.New("ent: missing options for UserSubscriptionCreate.OnConflict")
  1044. }
  1045. return u.create.Exec(ctx)
  1046. }
  1047. // ExecX is like Exec, but panics if an error occurs.
  1048. func (u *UserSubscriptionUpsertOne) ExecX(ctx context.Context) {
  1049. if err := u.create.Exec(ctx); err != nil {
  1050. panic(err)
  1051. }
  1052. }
  1053. // Exec executes the UPSERT query and returns the inserted/updated ID.
  1054. func (u *UserSubscriptionUpsertOne) ID(ctx context.Context) (id int64, err error) {
  1055. node, err := u.create.Save(ctx)
  1056. if err != nil {
  1057. return id, err
  1058. }
  1059. return node.ID, nil
  1060. }
  1061. // IDX is like ID, but panics if an error occurs.
  1062. func (u *UserSubscriptionUpsertOne) IDX(ctx context.Context) int64 {
  1063. id, err := u.ID(ctx)
  1064. if err != nil {
  1065. panic(err)
  1066. }
  1067. return id
  1068. }
  1069. // UserSubscriptionCreateBulk is the builder for creating many UserSubscription entities in bulk.
  1070. type UserSubscriptionCreateBulk struct {
  1071. config
  1072. err error
  1073. builders []*UserSubscriptionCreate
  1074. conflict []sql.ConflictOption
  1075. }
  1076. // Save creates the UserSubscription entities in the database.
  1077. func (_c *UserSubscriptionCreateBulk) Save(ctx context.Context) ([]*UserSubscription, error) {
  1078. if _c.err != nil {
  1079. return nil, _c.err
  1080. }
  1081. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  1082. nodes := make([]*UserSubscription, len(_c.builders))
  1083. mutators := make([]Mutator, len(_c.builders))
  1084. for i := range _c.builders {
  1085. func(i int, root context.Context) {
  1086. builder := _c.builders[i]
  1087. builder.defaults()
  1088. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  1089. mutation, ok := m.(*UserSubscriptionMutation)
  1090. if !ok {
  1091. return nil, fmt.Errorf("unexpected mutation type %T", m)
  1092. }
  1093. if err := builder.check(); err != nil {
  1094. return nil, err
  1095. }
  1096. builder.mutation = mutation
  1097. var err error
  1098. nodes[i], specs[i] = builder.createSpec()
  1099. if i < len(mutators)-1 {
  1100. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  1101. } else {
  1102. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  1103. spec.OnConflict = _c.conflict
  1104. // Invoke the actual operation on the latest mutation in the chain.
  1105. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  1106. if sqlgraph.IsConstraintError(err) {
  1107. err = &ConstraintError{msg: err.Error(), wrap: err}
  1108. }
  1109. }
  1110. }
  1111. if err != nil {
  1112. return nil, err
  1113. }
  1114. mutation.id = &nodes[i].ID
  1115. if specs[i].ID.Value != nil {
  1116. id := specs[i].ID.Value.(int64)
  1117. nodes[i].ID = int64(id)
  1118. }
  1119. mutation.done = true
  1120. return nodes[i], nil
  1121. })
  1122. for i := len(builder.hooks) - 1; i >= 0; i-- {
  1123. mut = builder.hooks[i](mut)
  1124. }
  1125. mutators[i] = mut
  1126. }(i, ctx)
  1127. }
  1128. if len(mutators) > 0 {
  1129. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  1130. return nil, err
  1131. }
  1132. }
  1133. return nodes, nil
  1134. }
  1135. // SaveX is like Save, but panics if an error occurs.
  1136. func (_c *UserSubscriptionCreateBulk) SaveX(ctx context.Context) []*UserSubscription {
  1137. v, err := _c.Save(ctx)
  1138. if err != nil {
  1139. panic(err)
  1140. }
  1141. return v
  1142. }
  1143. // Exec executes the query.
  1144. func (_c *UserSubscriptionCreateBulk) Exec(ctx context.Context) error {
  1145. _, err := _c.Save(ctx)
  1146. return err
  1147. }
  1148. // ExecX is like Exec, but panics if an error occurs.
  1149. func (_c *UserSubscriptionCreateBulk) ExecX(ctx context.Context) {
  1150. if err := _c.Exec(ctx); err != nil {
  1151. panic(err)
  1152. }
  1153. }
  1154. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  1155. // of the `INSERT` statement. For example:
  1156. //
  1157. // client.UserSubscription.CreateBulk(builders...).
  1158. // OnConflict(
  1159. // // Update the row with the new values
  1160. // // the was proposed for insertion.
  1161. // sql.ResolveWithNewValues(),
  1162. // ).
  1163. // // Override some of the fields with custom
  1164. // // update values.
  1165. // Update(func(u *ent.UserSubscriptionUpsert) {
  1166. // SetCreatedAt(v+v).
  1167. // }).
  1168. // Exec(ctx)
  1169. func (_c *UserSubscriptionCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserSubscriptionUpsertBulk {
  1170. _c.conflict = opts
  1171. return &UserSubscriptionUpsertBulk{
  1172. create: _c,
  1173. }
  1174. }
  1175. // OnConflictColumns calls `OnConflict` and configures the columns
  1176. // as conflict target. Using this option is equivalent to using:
  1177. //
  1178. // client.UserSubscription.Create().
  1179. // OnConflict(sql.ConflictColumns(columns...)).
  1180. // Exec(ctx)
  1181. func (_c *UserSubscriptionCreateBulk) OnConflictColumns(columns ...string) *UserSubscriptionUpsertBulk {
  1182. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  1183. return &UserSubscriptionUpsertBulk{
  1184. create: _c,
  1185. }
  1186. }
  1187. // UserSubscriptionUpsertBulk is the builder for "upsert"-ing
  1188. // a bulk of UserSubscription nodes.
  1189. type UserSubscriptionUpsertBulk struct {
  1190. create *UserSubscriptionCreateBulk
  1191. }
  1192. // UpdateNewValues updates the mutable fields using the new values that
  1193. // were set on create. Using this option is equivalent to using:
  1194. //
  1195. // client.UserSubscription.Create().
  1196. // OnConflict(
  1197. // sql.ResolveWithNewValues(),
  1198. // ).
  1199. // Exec(ctx)
  1200. func (u *UserSubscriptionUpsertBulk) UpdateNewValues() *UserSubscriptionUpsertBulk {
  1201. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1202. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1203. for _, b := range u.create.builders {
  1204. if _, exists := b.mutation.CreatedAt(); exists {
  1205. s.SetIgnore(usersubscription.FieldCreatedAt)
  1206. }
  1207. }
  1208. }))
  1209. return u
  1210. }
  1211. // Ignore sets each column to itself in case of conflict.
  1212. // Using this option is equivalent to using:
  1213. //
  1214. // client.UserSubscription.Create().
  1215. // OnConflict(sql.ResolveWithIgnore()).
  1216. // Exec(ctx)
  1217. func (u *UserSubscriptionUpsertBulk) Ignore() *UserSubscriptionUpsertBulk {
  1218. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1219. return u
  1220. }
  1221. // DoNothing configures the conflict_action to `DO NOTHING`.
  1222. // Supported only by SQLite and PostgreSQL.
  1223. func (u *UserSubscriptionUpsertBulk) DoNothing() *UserSubscriptionUpsertBulk {
  1224. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1225. return u
  1226. }
  1227. // Update allows overriding fields `UPDATE` values. See the UserSubscriptionCreateBulk.OnConflict
  1228. // documentation for more info.
  1229. func (u *UserSubscriptionUpsertBulk) Update(set func(*UserSubscriptionUpsert)) *UserSubscriptionUpsertBulk {
  1230. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1231. set(&UserSubscriptionUpsert{UpdateSet: update})
  1232. }))
  1233. return u
  1234. }
  1235. // SetUpdatedAt sets the "updated_at" field.
  1236. func (u *UserSubscriptionUpsertBulk) SetUpdatedAt(v time.Time) *UserSubscriptionUpsertBulk {
  1237. return u.Update(func(s *UserSubscriptionUpsert) {
  1238. s.SetUpdatedAt(v)
  1239. })
  1240. }
  1241. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1242. func (u *UserSubscriptionUpsertBulk) UpdateUpdatedAt() *UserSubscriptionUpsertBulk {
  1243. return u.Update(func(s *UserSubscriptionUpsert) {
  1244. s.UpdateUpdatedAt()
  1245. })
  1246. }
  1247. // SetDeletedAt sets the "deleted_at" field.
  1248. func (u *UserSubscriptionUpsertBulk) SetDeletedAt(v time.Time) *UserSubscriptionUpsertBulk {
  1249. return u.Update(func(s *UserSubscriptionUpsert) {
  1250. s.SetDeletedAt(v)
  1251. })
  1252. }
  1253. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1254. func (u *UserSubscriptionUpsertBulk) UpdateDeletedAt() *UserSubscriptionUpsertBulk {
  1255. return u.Update(func(s *UserSubscriptionUpsert) {
  1256. s.UpdateDeletedAt()
  1257. })
  1258. }
  1259. // ClearDeletedAt clears the value of the "deleted_at" field.
  1260. func (u *UserSubscriptionUpsertBulk) ClearDeletedAt() *UserSubscriptionUpsertBulk {
  1261. return u.Update(func(s *UserSubscriptionUpsert) {
  1262. s.ClearDeletedAt()
  1263. })
  1264. }
  1265. // SetUserID sets the "user_id" field.
  1266. func (u *UserSubscriptionUpsertBulk) SetUserID(v int64) *UserSubscriptionUpsertBulk {
  1267. return u.Update(func(s *UserSubscriptionUpsert) {
  1268. s.SetUserID(v)
  1269. })
  1270. }
  1271. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  1272. func (u *UserSubscriptionUpsertBulk) UpdateUserID() *UserSubscriptionUpsertBulk {
  1273. return u.Update(func(s *UserSubscriptionUpsert) {
  1274. s.UpdateUserID()
  1275. })
  1276. }
  1277. // SetGroupID sets the "group_id" field.
  1278. func (u *UserSubscriptionUpsertBulk) SetGroupID(v int64) *UserSubscriptionUpsertBulk {
  1279. return u.Update(func(s *UserSubscriptionUpsert) {
  1280. s.SetGroupID(v)
  1281. })
  1282. }
  1283. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  1284. func (u *UserSubscriptionUpsertBulk) UpdateGroupID() *UserSubscriptionUpsertBulk {
  1285. return u.Update(func(s *UserSubscriptionUpsert) {
  1286. s.UpdateGroupID()
  1287. })
  1288. }
  1289. // SetStartsAt sets the "starts_at" field.
  1290. func (u *UserSubscriptionUpsertBulk) SetStartsAt(v time.Time) *UserSubscriptionUpsertBulk {
  1291. return u.Update(func(s *UserSubscriptionUpsert) {
  1292. s.SetStartsAt(v)
  1293. })
  1294. }
  1295. // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
  1296. func (u *UserSubscriptionUpsertBulk) UpdateStartsAt() *UserSubscriptionUpsertBulk {
  1297. return u.Update(func(s *UserSubscriptionUpsert) {
  1298. s.UpdateStartsAt()
  1299. })
  1300. }
  1301. // SetExpiresAt sets the "expires_at" field.
  1302. func (u *UserSubscriptionUpsertBulk) SetExpiresAt(v time.Time) *UserSubscriptionUpsertBulk {
  1303. return u.Update(func(s *UserSubscriptionUpsert) {
  1304. s.SetExpiresAt(v)
  1305. })
  1306. }
  1307. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  1308. func (u *UserSubscriptionUpsertBulk) UpdateExpiresAt() *UserSubscriptionUpsertBulk {
  1309. return u.Update(func(s *UserSubscriptionUpsert) {
  1310. s.UpdateExpiresAt()
  1311. })
  1312. }
  1313. // SetStatus sets the "status" field.
  1314. func (u *UserSubscriptionUpsertBulk) SetStatus(v string) *UserSubscriptionUpsertBulk {
  1315. return u.Update(func(s *UserSubscriptionUpsert) {
  1316. s.SetStatus(v)
  1317. })
  1318. }
  1319. // UpdateStatus sets the "status" field to the value that was provided on create.
  1320. func (u *UserSubscriptionUpsertBulk) UpdateStatus() *UserSubscriptionUpsertBulk {
  1321. return u.Update(func(s *UserSubscriptionUpsert) {
  1322. s.UpdateStatus()
  1323. })
  1324. }
  1325. // SetDailyWindowStart sets the "daily_window_start" field.
  1326. func (u *UserSubscriptionUpsertBulk) SetDailyWindowStart(v time.Time) *UserSubscriptionUpsertBulk {
  1327. return u.Update(func(s *UserSubscriptionUpsert) {
  1328. s.SetDailyWindowStart(v)
  1329. })
  1330. }
  1331. // UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
  1332. func (u *UserSubscriptionUpsertBulk) UpdateDailyWindowStart() *UserSubscriptionUpsertBulk {
  1333. return u.Update(func(s *UserSubscriptionUpsert) {
  1334. s.UpdateDailyWindowStart()
  1335. })
  1336. }
  1337. // ClearDailyWindowStart clears the value of the "daily_window_start" field.
  1338. func (u *UserSubscriptionUpsertBulk) ClearDailyWindowStart() *UserSubscriptionUpsertBulk {
  1339. return u.Update(func(s *UserSubscriptionUpsert) {
  1340. s.ClearDailyWindowStart()
  1341. })
  1342. }
  1343. // SetWeeklyWindowStart sets the "weekly_window_start" field.
  1344. func (u *UserSubscriptionUpsertBulk) SetWeeklyWindowStart(v time.Time) *UserSubscriptionUpsertBulk {
  1345. return u.Update(func(s *UserSubscriptionUpsert) {
  1346. s.SetWeeklyWindowStart(v)
  1347. })
  1348. }
  1349. // UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
  1350. func (u *UserSubscriptionUpsertBulk) UpdateWeeklyWindowStart() *UserSubscriptionUpsertBulk {
  1351. return u.Update(func(s *UserSubscriptionUpsert) {
  1352. s.UpdateWeeklyWindowStart()
  1353. })
  1354. }
  1355. // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
  1356. func (u *UserSubscriptionUpsertBulk) ClearWeeklyWindowStart() *UserSubscriptionUpsertBulk {
  1357. return u.Update(func(s *UserSubscriptionUpsert) {
  1358. s.ClearWeeklyWindowStart()
  1359. })
  1360. }
  1361. // SetMonthlyWindowStart sets the "monthly_window_start" field.
  1362. func (u *UserSubscriptionUpsertBulk) SetMonthlyWindowStart(v time.Time) *UserSubscriptionUpsertBulk {
  1363. return u.Update(func(s *UserSubscriptionUpsert) {
  1364. s.SetMonthlyWindowStart(v)
  1365. })
  1366. }
  1367. // UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
  1368. func (u *UserSubscriptionUpsertBulk) UpdateMonthlyWindowStart() *UserSubscriptionUpsertBulk {
  1369. return u.Update(func(s *UserSubscriptionUpsert) {
  1370. s.UpdateMonthlyWindowStart()
  1371. })
  1372. }
  1373. // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
  1374. func (u *UserSubscriptionUpsertBulk) ClearMonthlyWindowStart() *UserSubscriptionUpsertBulk {
  1375. return u.Update(func(s *UserSubscriptionUpsert) {
  1376. s.ClearMonthlyWindowStart()
  1377. })
  1378. }
  1379. // SetDailyUsageUsd sets the "daily_usage_usd" field.
  1380. func (u *UserSubscriptionUpsertBulk) SetDailyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
  1381. return u.Update(func(s *UserSubscriptionUpsert) {
  1382. s.SetDailyUsageUsd(v)
  1383. })
  1384. }
  1385. // AddDailyUsageUsd adds v to the "daily_usage_usd" field.
  1386. func (u *UserSubscriptionUpsertBulk) AddDailyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
  1387. return u.Update(func(s *UserSubscriptionUpsert) {
  1388. s.AddDailyUsageUsd(v)
  1389. })
  1390. }
  1391. // UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
  1392. func (u *UserSubscriptionUpsertBulk) UpdateDailyUsageUsd() *UserSubscriptionUpsertBulk {
  1393. return u.Update(func(s *UserSubscriptionUpsert) {
  1394. s.UpdateDailyUsageUsd()
  1395. })
  1396. }
  1397. // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
  1398. func (u *UserSubscriptionUpsertBulk) SetWeeklyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
  1399. return u.Update(func(s *UserSubscriptionUpsert) {
  1400. s.SetWeeklyUsageUsd(v)
  1401. })
  1402. }
  1403. // AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
  1404. func (u *UserSubscriptionUpsertBulk) AddWeeklyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
  1405. return u.Update(func(s *UserSubscriptionUpsert) {
  1406. s.AddWeeklyUsageUsd(v)
  1407. })
  1408. }
  1409. // UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
  1410. func (u *UserSubscriptionUpsertBulk) UpdateWeeklyUsageUsd() *UserSubscriptionUpsertBulk {
  1411. return u.Update(func(s *UserSubscriptionUpsert) {
  1412. s.UpdateWeeklyUsageUsd()
  1413. })
  1414. }
  1415. // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
  1416. func (u *UserSubscriptionUpsertBulk) SetMonthlyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
  1417. return u.Update(func(s *UserSubscriptionUpsert) {
  1418. s.SetMonthlyUsageUsd(v)
  1419. })
  1420. }
  1421. // AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
  1422. func (u *UserSubscriptionUpsertBulk) AddMonthlyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
  1423. return u.Update(func(s *UserSubscriptionUpsert) {
  1424. s.AddMonthlyUsageUsd(v)
  1425. })
  1426. }
  1427. // UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
  1428. func (u *UserSubscriptionUpsertBulk) UpdateMonthlyUsageUsd() *UserSubscriptionUpsertBulk {
  1429. return u.Update(func(s *UserSubscriptionUpsert) {
  1430. s.UpdateMonthlyUsageUsd()
  1431. })
  1432. }
  1433. // SetAssignedBy sets the "assigned_by" field.
  1434. func (u *UserSubscriptionUpsertBulk) SetAssignedBy(v int64) *UserSubscriptionUpsertBulk {
  1435. return u.Update(func(s *UserSubscriptionUpsert) {
  1436. s.SetAssignedBy(v)
  1437. })
  1438. }
  1439. // UpdateAssignedBy sets the "assigned_by" field to the value that was provided on create.
  1440. func (u *UserSubscriptionUpsertBulk) UpdateAssignedBy() *UserSubscriptionUpsertBulk {
  1441. return u.Update(func(s *UserSubscriptionUpsert) {
  1442. s.UpdateAssignedBy()
  1443. })
  1444. }
  1445. // ClearAssignedBy clears the value of the "assigned_by" field.
  1446. func (u *UserSubscriptionUpsertBulk) ClearAssignedBy() *UserSubscriptionUpsertBulk {
  1447. return u.Update(func(s *UserSubscriptionUpsert) {
  1448. s.ClearAssignedBy()
  1449. })
  1450. }
  1451. // SetAssignedAt sets the "assigned_at" field.
  1452. func (u *UserSubscriptionUpsertBulk) SetAssignedAt(v time.Time) *UserSubscriptionUpsertBulk {
  1453. return u.Update(func(s *UserSubscriptionUpsert) {
  1454. s.SetAssignedAt(v)
  1455. })
  1456. }
  1457. // UpdateAssignedAt sets the "assigned_at" field to the value that was provided on create.
  1458. func (u *UserSubscriptionUpsertBulk) UpdateAssignedAt() *UserSubscriptionUpsertBulk {
  1459. return u.Update(func(s *UserSubscriptionUpsert) {
  1460. s.UpdateAssignedAt()
  1461. })
  1462. }
  1463. // SetNotes sets the "notes" field.
  1464. func (u *UserSubscriptionUpsertBulk) SetNotes(v string) *UserSubscriptionUpsertBulk {
  1465. return u.Update(func(s *UserSubscriptionUpsert) {
  1466. s.SetNotes(v)
  1467. })
  1468. }
  1469. // UpdateNotes sets the "notes" field to the value that was provided on create.
  1470. func (u *UserSubscriptionUpsertBulk) UpdateNotes() *UserSubscriptionUpsertBulk {
  1471. return u.Update(func(s *UserSubscriptionUpsert) {
  1472. s.UpdateNotes()
  1473. })
  1474. }
  1475. // ClearNotes clears the value of the "notes" field.
  1476. func (u *UserSubscriptionUpsertBulk) ClearNotes() *UserSubscriptionUpsertBulk {
  1477. return u.Update(func(s *UserSubscriptionUpsert) {
  1478. s.ClearNotes()
  1479. })
  1480. }
  1481. // Exec executes the query.
  1482. func (u *UserSubscriptionUpsertBulk) Exec(ctx context.Context) error {
  1483. if u.create.err != nil {
  1484. return u.create.err
  1485. }
  1486. for i, b := range u.create.builders {
  1487. if len(b.conflict) != 0 {
  1488. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the UserSubscriptionCreateBulk instead", i)
  1489. }
  1490. }
  1491. if len(u.create.conflict) == 0 {
  1492. return errors.New("ent: missing options for UserSubscriptionCreateBulk.OnConflict")
  1493. }
  1494. return u.create.Exec(ctx)
  1495. }
  1496. // ExecX is like Exec, but panics if an error occurs.
  1497. func (u *UserSubscriptionUpsertBulk) ExecX(ctx context.Context) {
  1498. if err := u.create.Exec(ctx); err != nil {
  1499. panic(err)
  1500. }
  1501. }