subscriptionplan_create.go 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  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/subscriptionplan"
  12. )
  13. // SubscriptionPlanCreate is the builder for creating a SubscriptionPlan entity.
  14. type SubscriptionPlanCreate struct {
  15. config
  16. mutation *SubscriptionPlanMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetGroupID sets the "group_id" field.
  21. func (_c *SubscriptionPlanCreate) SetGroupID(v int64) *SubscriptionPlanCreate {
  22. _c.mutation.SetGroupID(v)
  23. return _c
  24. }
  25. // SetName sets the "name" field.
  26. func (_c *SubscriptionPlanCreate) SetName(v string) *SubscriptionPlanCreate {
  27. _c.mutation.SetName(v)
  28. return _c
  29. }
  30. // SetDescription sets the "description" field.
  31. func (_c *SubscriptionPlanCreate) SetDescription(v string) *SubscriptionPlanCreate {
  32. _c.mutation.SetDescription(v)
  33. return _c
  34. }
  35. // SetNillableDescription sets the "description" field if the given value is not nil.
  36. func (_c *SubscriptionPlanCreate) SetNillableDescription(v *string) *SubscriptionPlanCreate {
  37. if v != nil {
  38. _c.SetDescription(*v)
  39. }
  40. return _c
  41. }
  42. // SetPrice sets the "price" field.
  43. func (_c *SubscriptionPlanCreate) SetPrice(v float64) *SubscriptionPlanCreate {
  44. _c.mutation.SetPrice(v)
  45. return _c
  46. }
  47. // SetOriginalPrice sets the "original_price" field.
  48. func (_c *SubscriptionPlanCreate) SetOriginalPrice(v float64) *SubscriptionPlanCreate {
  49. _c.mutation.SetOriginalPrice(v)
  50. return _c
  51. }
  52. // SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
  53. func (_c *SubscriptionPlanCreate) SetNillableOriginalPrice(v *float64) *SubscriptionPlanCreate {
  54. if v != nil {
  55. _c.SetOriginalPrice(*v)
  56. }
  57. return _c
  58. }
  59. // SetCurrency sets the "currency" field.
  60. func (_c *SubscriptionPlanCreate) SetCurrency(v string) *SubscriptionPlanCreate {
  61. _c.mutation.SetCurrency(v)
  62. return _c
  63. }
  64. // SetNillableCurrency sets the "currency" field if the given value is not nil.
  65. func (_c *SubscriptionPlanCreate) SetNillableCurrency(v *string) *SubscriptionPlanCreate {
  66. if v != nil {
  67. _c.SetCurrency(*v)
  68. }
  69. return _c
  70. }
  71. // SetValidityDays sets the "validity_days" field.
  72. func (_c *SubscriptionPlanCreate) SetValidityDays(v int) *SubscriptionPlanCreate {
  73. _c.mutation.SetValidityDays(v)
  74. return _c
  75. }
  76. // SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
  77. func (_c *SubscriptionPlanCreate) SetNillableValidityDays(v *int) *SubscriptionPlanCreate {
  78. if v != nil {
  79. _c.SetValidityDays(*v)
  80. }
  81. return _c
  82. }
  83. // SetValidityUnit sets the "validity_unit" field.
  84. func (_c *SubscriptionPlanCreate) SetValidityUnit(v string) *SubscriptionPlanCreate {
  85. _c.mutation.SetValidityUnit(v)
  86. return _c
  87. }
  88. // SetNillableValidityUnit sets the "validity_unit" field if the given value is not nil.
  89. func (_c *SubscriptionPlanCreate) SetNillableValidityUnit(v *string) *SubscriptionPlanCreate {
  90. if v != nil {
  91. _c.SetValidityUnit(*v)
  92. }
  93. return _c
  94. }
  95. // SetFeatures sets the "features" field.
  96. func (_c *SubscriptionPlanCreate) SetFeatures(v string) *SubscriptionPlanCreate {
  97. _c.mutation.SetFeatures(v)
  98. return _c
  99. }
  100. // SetNillableFeatures sets the "features" field if the given value is not nil.
  101. func (_c *SubscriptionPlanCreate) SetNillableFeatures(v *string) *SubscriptionPlanCreate {
  102. if v != nil {
  103. _c.SetFeatures(*v)
  104. }
  105. return _c
  106. }
  107. // SetProductName sets the "product_name" field.
  108. func (_c *SubscriptionPlanCreate) SetProductName(v string) *SubscriptionPlanCreate {
  109. _c.mutation.SetProductName(v)
  110. return _c
  111. }
  112. // SetNillableProductName sets the "product_name" field if the given value is not nil.
  113. func (_c *SubscriptionPlanCreate) SetNillableProductName(v *string) *SubscriptionPlanCreate {
  114. if v != nil {
  115. _c.SetProductName(*v)
  116. }
  117. return _c
  118. }
  119. // SetForSale sets the "for_sale" field.
  120. func (_c *SubscriptionPlanCreate) SetForSale(v bool) *SubscriptionPlanCreate {
  121. _c.mutation.SetForSale(v)
  122. return _c
  123. }
  124. // SetNillableForSale sets the "for_sale" field if the given value is not nil.
  125. func (_c *SubscriptionPlanCreate) SetNillableForSale(v *bool) *SubscriptionPlanCreate {
  126. if v != nil {
  127. _c.SetForSale(*v)
  128. }
  129. return _c
  130. }
  131. // SetSortOrder sets the "sort_order" field.
  132. func (_c *SubscriptionPlanCreate) SetSortOrder(v int) *SubscriptionPlanCreate {
  133. _c.mutation.SetSortOrder(v)
  134. return _c
  135. }
  136. // SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
  137. func (_c *SubscriptionPlanCreate) SetNillableSortOrder(v *int) *SubscriptionPlanCreate {
  138. if v != nil {
  139. _c.SetSortOrder(*v)
  140. }
  141. return _c
  142. }
  143. // SetCreatedAt sets the "created_at" field.
  144. func (_c *SubscriptionPlanCreate) SetCreatedAt(v time.Time) *SubscriptionPlanCreate {
  145. _c.mutation.SetCreatedAt(v)
  146. return _c
  147. }
  148. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  149. func (_c *SubscriptionPlanCreate) SetNillableCreatedAt(v *time.Time) *SubscriptionPlanCreate {
  150. if v != nil {
  151. _c.SetCreatedAt(*v)
  152. }
  153. return _c
  154. }
  155. // SetUpdatedAt sets the "updated_at" field.
  156. func (_c *SubscriptionPlanCreate) SetUpdatedAt(v time.Time) *SubscriptionPlanCreate {
  157. _c.mutation.SetUpdatedAt(v)
  158. return _c
  159. }
  160. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  161. func (_c *SubscriptionPlanCreate) SetNillableUpdatedAt(v *time.Time) *SubscriptionPlanCreate {
  162. if v != nil {
  163. _c.SetUpdatedAt(*v)
  164. }
  165. return _c
  166. }
  167. // Mutation returns the SubscriptionPlanMutation object of the builder.
  168. func (_c *SubscriptionPlanCreate) Mutation() *SubscriptionPlanMutation {
  169. return _c.mutation
  170. }
  171. // Save creates the SubscriptionPlan in the database.
  172. func (_c *SubscriptionPlanCreate) Save(ctx context.Context) (*SubscriptionPlan, error) {
  173. _c.defaults()
  174. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  175. }
  176. // SaveX calls Save and panics if Save returns an error.
  177. func (_c *SubscriptionPlanCreate) SaveX(ctx context.Context) *SubscriptionPlan {
  178. v, err := _c.Save(ctx)
  179. if err != nil {
  180. panic(err)
  181. }
  182. return v
  183. }
  184. // Exec executes the query.
  185. func (_c *SubscriptionPlanCreate) Exec(ctx context.Context) error {
  186. _, err := _c.Save(ctx)
  187. return err
  188. }
  189. // ExecX is like Exec, but panics if an error occurs.
  190. func (_c *SubscriptionPlanCreate) ExecX(ctx context.Context) {
  191. if err := _c.Exec(ctx); err != nil {
  192. panic(err)
  193. }
  194. }
  195. // defaults sets the default values of the builder before save.
  196. func (_c *SubscriptionPlanCreate) defaults() {
  197. if _, ok := _c.mutation.Description(); !ok {
  198. v := subscriptionplan.DefaultDescription
  199. _c.mutation.SetDescription(v)
  200. }
  201. if _, ok := _c.mutation.Currency(); !ok {
  202. v := subscriptionplan.DefaultCurrency
  203. _c.mutation.SetCurrency(v)
  204. }
  205. if _, ok := _c.mutation.ValidityDays(); !ok {
  206. v := subscriptionplan.DefaultValidityDays
  207. _c.mutation.SetValidityDays(v)
  208. }
  209. if _, ok := _c.mutation.ValidityUnit(); !ok {
  210. v := subscriptionplan.DefaultValidityUnit
  211. _c.mutation.SetValidityUnit(v)
  212. }
  213. if _, ok := _c.mutation.Features(); !ok {
  214. v := subscriptionplan.DefaultFeatures
  215. _c.mutation.SetFeatures(v)
  216. }
  217. if _, ok := _c.mutation.ProductName(); !ok {
  218. v := subscriptionplan.DefaultProductName
  219. _c.mutation.SetProductName(v)
  220. }
  221. if _, ok := _c.mutation.ForSale(); !ok {
  222. v := subscriptionplan.DefaultForSale
  223. _c.mutation.SetForSale(v)
  224. }
  225. if _, ok := _c.mutation.SortOrder(); !ok {
  226. v := subscriptionplan.DefaultSortOrder
  227. _c.mutation.SetSortOrder(v)
  228. }
  229. if _, ok := _c.mutation.CreatedAt(); !ok {
  230. v := subscriptionplan.DefaultCreatedAt()
  231. _c.mutation.SetCreatedAt(v)
  232. }
  233. if _, ok := _c.mutation.UpdatedAt(); !ok {
  234. v := subscriptionplan.DefaultUpdatedAt()
  235. _c.mutation.SetUpdatedAt(v)
  236. }
  237. }
  238. // check runs all checks and user-defined validators on the builder.
  239. func (_c *SubscriptionPlanCreate) check() error {
  240. if _, ok := _c.mutation.GroupID(); !ok {
  241. return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "SubscriptionPlan.group_id"`)}
  242. }
  243. if _, ok := _c.mutation.Name(); !ok {
  244. return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "SubscriptionPlan.name"`)}
  245. }
  246. if v, ok := _c.mutation.Name(); ok {
  247. if err := subscriptionplan.NameValidator(v); err != nil {
  248. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.name": %w`, err)}
  249. }
  250. }
  251. if _, ok := _c.mutation.Description(); !ok {
  252. return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "SubscriptionPlan.description"`)}
  253. }
  254. if _, ok := _c.mutation.Price(); !ok {
  255. return &ValidationError{Name: "price", err: errors.New(`ent: missing required field "SubscriptionPlan.price"`)}
  256. }
  257. if _, ok := _c.mutation.Currency(); !ok {
  258. return &ValidationError{Name: "currency", err: errors.New(`ent: missing required field "SubscriptionPlan.currency"`)}
  259. }
  260. if v, ok := _c.mutation.Currency(); ok {
  261. if err := subscriptionplan.CurrencyValidator(v); err != nil {
  262. return &ValidationError{Name: "currency", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.currency": %w`, err)}
  263. }
  264. }
  265. if _, ok := _c.mutation.ValidityDays(); !ok {
  266. return &ValidationError{Name: "validity_days", err: errors.New(`ent: missing required field "SubscriptionPlan.validity_days"`)}
  267. }
  268. if _, ok := _c.mutation.ValidityUnit(); !ok {
  269. return &ValidationError{Name: "validity_unit", err: errors.New(`ent: missing required field "SubscriptionPlan.validity_unit"`)}
  270. }
  271. if v, ok := _c.mutation.ValidityUnit(); ok {
  272. if err := subscriptionplan.ValidityUnitValidator(v); err != nil {
  273. return &ValidationError{Name: "validity_unit", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.validity_unit": %w`, err)}
  274. }
  275. }
  276. if _, ok := _c.mutation.Features(); !ok {
  277. return &ValidationError{Name: "features", err: errors.New(`ent: missing required field "SubscriptionPlan.features"`)}
  278. }
  279. if _, ok := _c.mutation.ProductName(); !ok {
  280. return &ValidationError{Name: "product_name", err: errors.New(`ent: missing required field "SubscriptionPlan.product_name"`)}
  281. }
  282. if v, ok := _c.mutation.ProductName(); ok {
  283. if err := subscriptionplan.ProductNameValidator(v); err != nil {
  284. return &ValidationError{Name: "product_name", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.product_name": %w`, err)}
  285. }
  286. }
  287. if _, ok := _c.mutation.ForSale(); !ok {
  288. return &ValidationError{Name: "for_sale", err: errors.New(`ent: missing required field "SubscriptionPlan.for_sale"`)}
  289. }
  290. if _, ok := _c.mutation.SortOrder(); !ok {
  291. return &ValidationError{Name: "sort_order", err: errors.New(`ent: missing required field "SubscriptionPlan.sort_order"`)}
  292. }
  293. if _, ok := _c.mutation.CreatedAt(); !ok {
  294. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SubscriptionPlan.created_at"`)}
  295. }
  296. if _, ok := _c.mutation.UpdatedAt(); !ok {
  297. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SubscriptionPlan.updated_at"`)}
  298. }
  299. return nil
  300. }
  301. func (_c *SubscriptionPlanCreate) sqlSave(ctx context.Context) (*SubscriptionPlan, error) {
  302. if err := _c.check(); err != nil {
  303. return nil, err
  304. }
  305. _node, _spec := _c.createSpec()
  306. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  307. if sqlgraph.IsConstraintError(err) {
  308. err = &ConstraintError{msg: err.Error(), wrap: err}
  309. }
  310. return nil, err
  311. }
  312. id := _spec.ID.Value.(int64)
  313. _node.ID = int64(id)
  314. _c.mutation.id = &_node.ID
  315. _c.mutation.done = true
  316. return _node, nil
  317. }
  318. func (_c *SubscriptionPlanCreate) createSpec() (*SubscriptionPlan, *sqlgraph.CreateSpec) {
  319. var (
  320. _node = &SubscriptionPlan{config: _c.config}
  321. _spec = sqlgraph.NewCreateSpec(subscriptionplan.Table, sqlgraph.NewFieldSpec(subscriptionplan.FieldID, field.TypeInt64))
  322. )
  323. _spec.OnConflict = _c.conflict
  324. if value, ok := _c.mutation.GroupID(); ok {
  325. _spec.SetField(subscriptionplan.FieldGroupID, field.TypeInt64, value)
  326. _node.GroupID = value
  327. }
  328. if value, ok := _c.mutation.Name(); ok {
  329. _spec.SetField(subscriptionplan.FieldName, field.TypeString, value)
  330. _node.Name = value
  331. }
  332. if value, ok := _c.mutation.Description(); ok {
  333. _spec.SetField(subscriptionplan.FieldDescription, field.TypeString, value)
  334. _node.Description = value
  335. }
  336. if value, ok := _c.mutation.Price(); ok {
  337. _spec.SetField(subscriptionplan.FieldPrice, field.TypeFloat64, value)
  338. _node.Price = value
  339. }
  340. if value, ok := _c.mutation.OriginalPrice(); ok {
  341. _spec.SetField(subscriptionplan.FieldOriginalPrice, field.TypeFloat64, value)
  342. _node.OriginalPrice = &value
  343. }
  344. if value, ok := _c.mutation.Currency(); ok {
  345. _spec.SetField(subscriptionplan.FieldCurrency, field.TypeString, value)
  346. _node.Currency = value
  347. }
  348. if value, ok := _c.mutation.ValidityDays(); ok {
  349. _spec.SetField(subscriptionplan.FieldValidityDays, field.TypeInt, value)
  350. _node.ValidityDays = value
  351. }
  352. if value, ok := _c.mutation.ValidityUnit(); ok {
  353. _spec.SetField(subscriptionplan.FieldValidityUnit, field.TypeString, value)
  354. _node.ValidityUnit = value
  355. }
  356. if value, ok := _c.mutation.Features(); ok {
  357. _spec.SetField(subscriptionplan.FieldFeatures, field.TypeString, value)
  358. _node.Features = value
  359. }
  360. if value, ok := _c.mutation.ProductName(); ok {
  361. _spec.SetField(subscriptionplan.FieldProductName, field.TypeString, value)
  362. _node.ProductName = value
  363. }
  364. if value, ok := _c.mutation.ForSale(); ok {
  365. _spec.SetField(subscriptionplan.FieldForSale, field.TypeBool, value)
  366. _node.ForSale = value
  367. }
  368. if value, ok := _c.mutation.SortOrder(); ok {
  369. _spec.SetField(subscriptionplan.FieldSortOrder, field.TypeInt, value)
  370. _node.SortOrder = value
  371. }
  372. if value, ok := _c.mutation.CreatedAt(); ok {
  373. _spec.SetField(subscriptionplan.FieldCreatedAt, field.TypeTime, value)
  374. _node.CreatedAt = value
  375. }
  376. if value, ok := _c.mutation.UpdatedAt(); ok {
  377. _spec.SetField(subscriptionplan.FieldUpdatedAt, field.TypeTime, value)
  378. _node.UpdatedAt = value
  379. }
  380. return _node, _spec
  381. }
  382. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  383. // of the `INSERT` statement. For example:
  384. //
  385. // client.SubscriptionPlan.Create().
  386. // SetGroupID(v).
  387. // OnConflict(
  388. // // Update the row with the new values
  389. // // the was proposed for insertion.
  390. // sql.ResolveWithNewValues(),
  391. // ).
  392. // // Override some of the fields with custom
  393. // // update values.
  394. // Update(func(u *ent.SubscriptionPlanUpsert) {
  395. // SetGroupID(v+v).
  396. // }).
  397. // Exec(ctx)
  398. func (_c *SubscriptionPlanCreate) OnConflict(opts ...sql.ConflictOption) *SubscriptionPlanUpsertOne {
  399. _c.conflict = opts
  400. return &SubscriptionPlanUpsertOne{
  401. create: _c,
  402. }
  403. }
  404. // OnConflictColumns calls `OnConflict` and configures the columns
  405. // as conflict target. Using this option is equivalent to using:
  406. //
  407. // client.SubscriptionPlan.Create().
  408. // OnConflict(sql.ConflictColumns(columns...)).
  409. // Exec(ctx)
  410. func (_c *SubscriptionPlanCreate) OnConflictColumns(columns ...string) *SubscriptionPlanUpsertOne {
  411. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  412. return &SubscriptionPlanUpsertOne{
  413. create: _c,
  414. }
  415. }
  416. type (
  417. // SubscriptionPlanUpsertOne is the builder for "upsert"-ing
  418. // one SubscriptionPlan node.
  419. SubscriptionPlanUpsertOne struct {
  420. create *SubscriptionPlanCreate
  421. }
  422. // SubscriptionPlanUpsert is the "OnConflict" setter.
  423. SubscriptionPlanUpsert struct {
  424. *sql.UpdateSet
  425. }
  426. )
  427. // SetGroupID sets the "group_id" field.
  428. func (u *SubscriptionPlanUpsert) SetGroupID(v int64) *SubscriptionPlanUpsert {
  429. u.Set(subscriptionplan.FieldGroupID, v)
  430. return u
  431. }
  432. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  433. func (u *SubscriptionPlanUpsert) UpdateGroupID() *SubscriptionPlanUpsert {
  434. u.SetExcluded(subscriptionplan.FieldGroupID)
  435. return u
  436. }
  437. // AddGroupID adds v to the "group_id" field.
  438. func (u *SubscriptionPlanUpsert) AddGroupID(v int64) *SubscriptionPlanUpsert {
  439. u.Add(subscriptionplan.FieldGroupID, v)
  440. return u
  441. }
  442. // SetName sets the "name" field.
  443. func (u *SubscriptionPlanUpsert) SetName(v string) *SubscriptionPlanUpsert {
  444. u.Set(subscriptionplan.FieldName, v)
  445. return u
  446. }
  447. // UpdateName sets the "name" field to the value that was provided on create.
  448. func (u *SubscriptionPlanUpsert) UpdateName() *SubscriptionPlanUpsert {
  449. u.SetExcluded(subscriptionplan.FieldName)
  450. return u
  451. }
  452. // SetDescription sets the "description" field.
  453. func (u *SubscriptionPlanUpsert) SetDescription(v string) *SubscriptionPlanUpsert {
  454. u.Set(subscriptionplan.FieldDescription, v)
  455. return u
  456. }
  457. // UpdateDescription sets the "description" field to the value that was provided on create.
  458. func (u *SubscriptionPlanUpsert) UpdateDescription() *SubscriptionPlanUpsert {
  459. u.SetExcluded(subscriptionplan.FieldDescription)
  460. return u
  461. }
  462. // SetPrice sets the "price" field.
  463. func (u *SubscriptionPlanUpsert) SetPrice(v float64) *SubscriptionPlanUpsert {
  464. u.Set(subscriptionplan.FieldPrice, v)
  465. return u
  466. }
  467. // UpdatePrice sets the "price" field to the value that was provided on create.
  468. func (u *SubscriptionPlanUpsert) UpdatePrice() *SubscriptionPlanUpsert {
  469. u.SetExcluded(subscriptionplan.FieldPrice)
  470. return u
  471. }
  472. // AddPrice adds v to the "price" field.
  473. func (u *SubscriptionPlanUpsert) AddPrice(v float64) *SubscriptionPlanUpsert {
  474. u.Add(subscriptionplan.FieldPrice, v)
  475. return u
  476. }
  477. // SetOriginalPrice sets the "original_price" field.
  478. func (u *SubscriptionPlanUpsert) SetOriginalPrice(v float64) *SubscriptionPlanUpsert {
  479. u.Set(subscriptionplan.FieldOriginalPrice, v)
  480. return u
  481. }
  482. // UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
  483. func (u *SubscriptionPlanUpsert) UpdateOriginalPrice() *SubscriptionPlanUpsert {
  484. u.SetExcluded(subscriptionplan.FieldOriginalPrice)
  485. return u
  486. }
  487. // AddOriginalPrice adds v to the "original_price" field.
  488. func (u *SubscriptionPlanUpsert) AddOriginalPrice(v float64) *SubscriptionPlanUpsert {
  489. u.Add(subscriptionplan.FieldOriginalPrice, v)
  490. return u
  491. }
  492. // ClearOriginalPrice clears the value of the "original_price" field.
  493. func (u *SubscriptionPlanUpsert) ClearOriginalPrice() *SubscriptionPlanUpsert {
  494. u.SetNull(subscriptionplan.FieldOriginalPrice)
  495. return u
  496. }
  497. // SetCurrency sets the "currency" field.
  498. func (u *SubscriptionPlanUpsert) SetCurrency(v string) *SubscriptionPlanUpsert {
  499. u.Set(subscriptionplan.FieldCurrency, v)
  500. return u
  501. }
  502. // UpdateCurrency sets the "currency" field to the value that was provided on create.
  503. func (u *SubscriptionPlanUpsert) UpdateCurrency() *SubscriptionPlanUpsert {
  504. u.SetExcluded(subscriptionplan.FieldCurrency)
  505. return u
  506. }
  507. // SetValidityDays sets the "validity_days" field.
  508. func (u *SubscriptionPlanUpsert) SetValidityDays(v int) *SubscriptionPlanUpsert {
  509. u.Set(subscriptionplan.FieldValidityDays, v)
  510. return u
  511. }
  512. // UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
  513. func (u *SubscriptionPlanUpsert) UpdateValidityDays() *SubscriptionPlanUpsert {
  514. u.SetExcluded(subscriptionplan.FieldValidityDays)
  515. return u
  516. }
  517. // AddValidityDays adds v to the "validity_days" field.
  518. func (u *SubscriptionPlanUpsert) AddValidityDays(v int) *SubscriptionPlanUpsert {
  519. u.Add(subscriptionplan.FieldValidityDays, v)
  520. return u
  521. }
  522. // SetValidityUnit sets the "validity_unit" field.
  523. func (u *SubscriptionPlanUpsert) SetValidityUnit(v string) *SubscriptionPlanUpsert {
  524. u.Set(subscriptionplan.FieldValidityUnit, v)
  525. return u
  526. }
  527. // UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
  528. func (u *SubscriptionPlanUpsert) UpdateValidityUnit() *SubscriptionPlanUpsert {
  529. u.SetExcluded(subscriptionplan.FieldValidityUnit)
  530. return u
  531. }
  532. // SetFeatures sets the "features" field.
  533. func (u *SubscriptionPlanUpsert) SetFeatures(v string) *SubscriptionPlanUpsert {
  534. u.Set(subscriptionplan.FieldFeatures, v)
  535. return u
  536. }
  537. // UpdateFeatures sets the "features" field to the value that was provided on create.
  538. func (u *SubscriptionPlanUpsert) UpdateFeatures() *SubscriptionPlanUpsert {
  539. u.SetExcluded(subscriptionplan.FieldFeatures)
  540. return u
  541. }
  542. // SetProductName sets the "product_name" field.
  543. func (u *SubscriptionPlanUpsert) SetProductName(v string) *SubscriptionPlanUpsert {
  544. u.Set(subscriptionplan.FieldProductName, v)
  545. return u
  546. }
  547. // UpdateProductName sets the "product_name" field to the value that was provided on create.
  548. func (u *SubscriptionPlanUpsert) UpdateProductName() *SubscriptionPlanUpsert {
  549. u.SetExcluded(subscriptionplan.FieldProductName)
  550. return u
  551. }
  552. // SetForSale sets the "for_sale" field.
  553. func (u *SubscriptionPlanUpsert) SetForSale(v bool) *SubscriptionPlanUpsert {
  554. u.Set(subscriptionplan.FieldForSale, v)
  555. return u
  556. }
  557. // UpdateForSale sets the "for_sale" field to the value that was provided on create.
  558. func (u *SubscriptionPlanUpsert) UpdateForSale() *SubscriptionPlanUpsert {
  559. u.SetExcluded(subscriptionplan.FieldForSale)
  560. return u
  561. }
  562. // SetSortOrder sets the "sort_order" field.
  563. func (u *SubscriptionPlanUpsert) SetSortOrder(v int) *SubscriptionPlanUpsert {
  564. u.Set(subscriptionplan.FieldSortOrder, v)
  565. return u
  566. }
  567. // UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
  568. func (u *SubscriptionPlanUpsert) UpdateSortOrder() *SubscriptionPlanUpsert {
  569. u.SetExcluded(subscriptionplan.FieldSortOrder)
  570. return u
  571. }
  572. // AddSortOrder adds v to the "sort_order" field.
  573. func (u *SubscriptionPlanUpsert) AddSortOrder(v int) *SubscriptionPlanUpsert {
  574. u.Add(subscriptionplan.FieldSortOrder, v)
  575. return u
  576. }
  577. // SetUpdatedAt sets the "updated_at" field.
  578. func (u *SubscriptionPlanUpsert) SetUpdatedAt(v time.Time) *SubscriptionPlanUpsert {
  579. u.Set(subscriptionplan.FieldUpdatedAt, v)
  580. return u
  581. }
  582. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  583. func (u *SubscriptionPlanUpsert) UpdateUpdatedAt() *SubscriptionPlanUpsert {
  584. u.SetExcluded(subscriptionplan.FieldUpdatedAt)
  585. return u
  586. }
  587. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  588. // Using this option is equivalent to using:
  589. //
  590. // client.SubscriptionPlan.Create().
  591. // OnConflict(
  592. // sql.ResolveWithNewValues(),
  593. // ).
  594. // Exec(ctx)
  595. func (u *SubscriptionPlanUpsertOne) UpdateNewValues() *SubscriptionPlanUpsertOne {
  596. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  597. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  598. if _, exists := u.create.mutation.CreatedAt(); exists {
  599. s.SetIgnore(subscriptionplan.FieldCreatedAt)
  600. }
  601. }))
  602. return u
  603. }
  604. // Ignore sets each column to itself in case of conflict.
  605. // Using this option is equivalent to using:
  606. //
  607. // client.SubscriptionPlan.Create().
  608. // OnConflict(sql.ResolveWithIgnore()).
  609. // Exec(ctx)
  610. func (u *SubscriptionPlanUpsertOne) Ignore() *SubscriptionPlanUpsertOne {
  611. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  612. return u
  613. }
  614. // DoNothing configures the conflict_action to `DO NOTHING`.
  615. // Supported only by SQLite and PostgreSQL.
  616. func (u *SubscriptionPlanUpsertOne) DoNothing() *SubscriptionPlanUpsertOne {
  617. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  618. return u
  619. }
  620. // Update allows overriding fields `UPDATE` values. See the SubscriptionPlanCreate.OnConflict
  621. // documentation for more info.
  622. func (u *SubscriptionPlanUpsertOne) Update(set func(*SubscriptionPlanUpsert)) *SubscriptionPlanUpsertOne {
  623. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  624. set(&SubscriptionPlanUpsert{UpdateSet: update})
  625. }))
  626. return u
  627. }
  628. // SetGroupID sets the "group_id" field.
  629. func (u *SubscriptionPlanUpsertOne) SetGroupID(v int64) *SubscriptionPlanUpsertOne {
  630. return u.Update(func(s *SubscriptionPlanUpsert) {
  631. s.SetGroupID(v)
  632. })
  633. }
  634. // AddGroupID adds v to the "group_id" field.
  635. func (u *SubscriptionPlanUpsertOne) AddGroupID(v int64) *SubscriptionPlanUpsertOne {
  636. return u.Update(func(s *SubscriptionPlanUpsert) {
  637. s.AddGroupID(v)
  638. })
  639. }
  640. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  641. func (u *SubscriptionPlanUpsertOne) UpdateGroupID() *SubscriptionPlanUpsertOne {
  642. return u.Update(func(s *SubscriptionPlanUpsert) {
  643. s.UpdateGroupID()
  644. })
  645. }
  646. // SetName sets the "name" field.
  647. func (u *SubscriptionPlanUpsertOne) SetName(v string) *SubscriptionPlanUpsertOne {
  648. return u.Update(func(s *SubscriptionPlanUpsert) {
  649. s.SetName(v)
  650. })
  651. }
  652. // UpdateName sets the "name" field to the value that was provided on create.
  653. func (u *SubscriptionPlanUpsertOne) UpdateName() *SubscriptionPlanUpsertOne {
  654. return u.Update(func(s *SubscriptionPlanUpsert) {
  655. s.UpdateName()
  656. })
  657. }
  658. // SetDescription sets the "description" field.
  659. func (u *SubscriptionPlanUpsertOne) SetDescription(v string) *SubscriptionPlanUpsertOne {
  660. return u.Update(func(s *SubscriptionPlanUpsert) {
  661. s.SetDescription(v)
  662. })
  663. }
  664. // UpdateDescription sets the "description" field to the value that was provided on create.
  665. func (u *SubscriptionPlanUpsertOne) UpdateDescription() *SubscriptionPlanUpsertOne {
  666. return u.Update(func(s *SubscriptionPlanUpsert) {
  667. s.UpdateDescription()
  668. })
  669. }
  670. // SetPrice sets the "price" field.
  671. func (u *SubscriptionPlanUpsertOne) SetPrice(v float64) *SubscriptionPlanUpsertOne {
  672. return u.Update(func(s *SubscriptionPlanUpsert) {
  673. s.SetPrice(v)
  674. })
  675. }
  676. // AddPrice adds v to the "price" field.
  677. func (u *SubscriptionPlanUpsertOne) AddPrice(v float64) *SubscriptionPlanUpsertOne {
  678. return u.Update(func(s *SubscriptionPlanUpsert) {
  679. s.AddPrice(v)
  680. })
  681. }
  682. // UpdatePrice sets the "price" field to the value that was provided on create.
  683. func (u *SubscriptionPlanUpsertOne) UpdatePrice() *SubscriptionPlanUpsertOne {
  684. return u.Update(func(s *SubscriptionPlanUpsert) {
  685. s.UpdatePrice()
  686. })
  687. }
  688. // SetOriginalPrice sets the "original_price" field.
  689. func (u *SubscriptionPlanUpsertOne) SetOriginalPrice(v float64) *SubscriptionPlanUpsertOne {
  690. return u.Update(func(s *SubscriptionPlanUpsert) {
  691. s.SetOriginalPrice(v)
  692. })
  693. }
  694. // AddOriginalPrice adds v to the "original_price" field.
  695. func (u *SubscriptionPlanUpsertOne) AddOriginalPrice(v float64) *SubscriptionPlanUpsertOne {
  696. return u.Update(func(s *SubscriptionPlanUpsert) {
  697. s.AddOriginalPrice(v)
  698. })
  699. }
  700. // UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
  701. func (u *SubscriptionPlanUpsertOne) UpdateOriginalPrice() *SubscriptionPlanUpsertOne {
  702. return u.Update(func(s *SubscriptionPlanUpsert) {
  703. s.UpdateOriginalPrice()
  704. })
  705. }
  706. // ClearOriginalPrice clears the value of the "original_price" field.
  707. func (u *SubscriptionPlanUpsertOne) ClearOriginalPrice() *SubscriptionPlanUpsertOne {
  708. return u.Update(func(s *SubscriptionPlanUpsert) {
  709. s.ClearOriginalPrice()
  710. })
  711. }
  712. // SetCurrency sets the "currency" field.
  713. func (u *SubscriptionPlanUpsertOne) SetCurrency(v string) *SubscriptionPlanUpsertOne {
  714. return u.Update(func(s *SubscriptionPlanUpsert) {
  715. s.SetCurrency(v)
  716. })
  717. }
  718. // UpdateCurrency sets the "currency" field to the value that was provided on create.
  719. func (u *SubscriptionPlanUpsertOne) UpdateCurrency() *SubscriptionPlanUpsertOne {
  720. return u.Update(func(s *SubscriptionPlanUpsert) {
  721. s.UpdateCurrency()
  722. })
  723. }
  724. // SetValidityDays sets the "validity_days" field.
  725. func (u *SubscriptionPlanUpsertOne) SetValidityDays(v int) *SubscriptionPlanUpsertOne {
  726. return u.Update(func(s *SubscriptionPlanUpsert) {
  727. s.SetValidityDays(v)
  728. })
  729. }
  730. // AddValidityDays adds v to the "validity_days" field.
  731. func (u *SubscriptionPlanUpsertOne) AddValidityDays(v int) *SubscriptionPlanUpsertOne {
  732. return u.Update(func(s *SubscriptionPlanUpsert) {
  733. s.AddValidityDays(v)
  734. })
  735. }
  736. // UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
  737. func (u *SubscriptionPlanUpsertOne) UpdateValidityDays() *SubscriptionPlanUpsertOne {
  738. return u.Update(func(s *SubscriptionPlanUpsert) {
  739. s.UpdateValidityDays()
  740. })
  741. }
  742. // SetValidityUnit sets the "validity_unit" field.
  743. func (u *SubscriptionPlanUpsertOne) SetValidityUnit(v string) *SubscriptionPlanUpsertOne {
  744. return u.Update(func(s *SubscriptionPlanUpsert) {
  745. s.SetValidityUnit(v)
  746. })
  747. }
  748. // UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
  749. func (u *SubscriptionPlanUpsertOne) UpdateValidityUnit() *SubscriptionPlanUpsertOne {
  750. return u.Update(func(s *SubscriptionPlanUpsert) {
  751. s.UpdateValidityUnit()
  752. })
  753. }
  754. // SetFeatures sets the "features" field.
  755. func (u *SubscriptionPlanUpsertOne) SetFeatures(v string) *SubscriptionPlanUpsertOne {
  756. return u.Update(func(s *SubscriptionPlanUpsert) {
  757. s.SetFeatures(v)
  758. })
  759. }
  760. // UpdateFeatures sets the "features" field to the value that was provided on create.
  761. func (u *SubscriptionPlanUpsertOne) UpdateFeatures() *SubscriptionPlanUpsertOne {
  762. return u.Update(func(s *SubscriptionPlanUpsert) {
  763. s.UpdateFeatures()
  764. })
  765. }
  766. // SetProductName sets the "product_name" field.
  767. func (u *SubscriptionPlanUpsertOne) SetProductName(v string) *SubscriptionPlanUpsertOne {
  768. return u.Update(func(s *SubscriptionPlanUpsert) {
  769. s.SetProductName(v)
  770. })
  771. }
  772. // UpdateProductName sets the "product_name" field to the value that was provided on create.
  773. func (u *SubscriptionPlanUpsertOne) UpdateProductName() *SubscriptionPlanUpsertOne {
  774. return u.Update(func(s *SubscriptionPlanUpsert) {
  775. s.UpdateProductName()
  776. })
  777. }
  778. // SetForSale sets the "for_sale" field.
  779. func (u *SubscriptionPlanUpsertOne) SetForSale(v bool) *SubscriptionPlanUpsertOne {
  780. return u.Update(func(s *SubscriptionPlanUpsert) {
  781. s.SetForSale(v)
  782. })
  783. }
  784. // UpdateForSale sets the "for_sale" field to the value that was provided on create.
  785. func (u *SubscriptionPlanUpsertOne) UpdateForSale() *SubscriptionPlanUpsertOne {
  786. return u.Update(func(s *SubscriptionPlanUpsert) {
  787. s.UpdateForSale()
  788. })
  789. }
  790. // SetSortOrder sets the "sort_order" field.
  791. func (u *SubscriptionPlanUpsertOne) SetSortOrder(v int) *SubscriptionPlanUpsertOne {
  792. return u.Update(func(s *SubscriptionPlanUpsert) {
  793. s.SetSortOrder(v)
  794. })
  795. }
  796. // AddSortOrder adds v to the "sort_order" field.
  797. func (u *SubscriptionPlanUpsertOne) AddSortOrder(v int) *SubscriptionPlanUpsertOne {
  798. return u.Update(func(s *SubscriptionPlanUpsert) {
  799. s.AddSortOrder(v)
  800. })
  801. }
  802. // UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
  803. func (u *SubscriptionPlanUpsertOne) UpdateSortOrder() *SubscriptionPlanUpsertOne {
  804. return u.Update(func(s *SubscriptionPlanUpsert) {
  805. s.UpdateSortOrder()
  806. })
  807. }
  808. // SetUpdatedAt sets the "updated_at" field.
  809. func (u *SubscriptionPlanUpsertOne) SetUpdatedAt(v time.Time) *SubscriptionPlanUpsertOne {
  810. return u.Update(func(s *SubscriptionPlanUpsert) {
  811. s.SetUpdatedAt(v)
  812. })
  813. }
  814. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  815. func (u *SubscriptionPlanUpsertOne) UpdateUpdatedAt() *SubscriptionPlanUpsertOne {
  816. return u.Update(func(s *SubscriptionPlanUpsert) {
  817. s.UpdateUpdatedAt()
  818. })
  819. }
  820. // Exec executes the query.
  821. func (u *SubscriptionPlanUpsertOne) Exec(ctx context.Context) error {
  822. if len(u.create.conflict) == 0 {
  823. return errors.New("ent: missing options for SubscriptionPlanCreate.OnConflict")
  824. }
  825. return u.create.Exec(ctx)
  826. }
  827. // ExecX is like Exec, but panics if an error occurs.
  828. func (u *SubscriptionPlanUpsertOne) ExecX(ctx context.Context) {
  829. if err := u.create.Exec(ctx); err != nil {
  830. panic(err)
  831. }
  832. }
  833. // Exec executes the UPSERT query and returns the inserted/updated ID.
  834. func (u *SubscriptionPlanUpsertOne) ID(ctx context.Context) (id int64, err error) {
  835. node, err := u.create.Save(ctx)
  836. if err != nil {
  837. return id, err
  838. }
  839. return node.ID, nil
  840. }
  841. // IDX is like ID, but panics if an error occurs.
  842. func (u *SubscriptionPlanUpsertOne) IDX(ctx context.Context) int64 {
  843. id, err := u.ID(ctx)
  844. if err != nil {
  845. panic(err)
  846. }
  847. return id
  848. }
  849. // SubscriptionPlanCreateBulk is the builder for creating many SubscriptionPlan entities in bulk.
  850. type SubscriptionPlanCreateBulk struct {
  851. config
  852. err error
  853. builders []*SubscriptionPlanCreate
  854. conflict []sql.ConflictOption
  855. }
  856. // Save creates the SubscriptionPlan entities in the database.
  857. func (_c *SubscriptionPlanCreateBulk) Save(ctx context.Context) ([]*SubscriptionPlan, error) {
  858. if _c.err != nil {
  859. return nil, _c.err
  860. }
  861. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  862. nodes := make([]*SubscriptionPlan, len(_c.builders))
  863. mutators := make([]Mutator, len(_c.builders))
  864. for i := range _c.builders {
  865. func(i int, root context.Context) {
  866. builder := _c.builders[i]
  867. builder.defaults()
  868. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  869. mutation, ok := m.(*SubscriptionPlanMutation)
  870. if !ok {
  871. return nil, fmt.Errorf("unexpected mutation type %T", m)
  872. }
  873. if err := builder.check(); err != nil {
  874. return nil, err
  875. }
  876. builder.mutation = mutation
  877. var err error
  878. nodes[i], specs[i] = builder.createSpec()
  879. if i < len(mutators)-1 {
  880. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  881. } else {
  882. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  883. spec.OnConflict = _c.conflict
  884. // Invoke the actual operation on the latest mutation in the chain.
  885. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  886. if sqlgraph.IsConstraintError(err) {
  887. err = &ConstraintError{msg: err.Error(), wrap: err}
  888. }
  889. }
  890. }
  891. if err != nil {
  892. return nil, err
  893. }
  894. mutation.id = &nodes[i].ID
  895. if specs[i].ID.Value != nil {
  896. id := specs[i].ID.Value.(int64)
  897. nodes[i].ID = int64(id)
  898. }
  899. mutation.done = true
  900. return nodes[i], nil
  901. })
  902. for i := len(builder.hooks) - 1; i >= 0; i-- {
  903. mut = builder.hooks[i](mut)
  904. }
  905. mutators[i] = mut
  906. }(i, ctx)
  907. }
  908. if len(mutators) > 0 {
  909. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  910. return nil, err
  911. }
  912. }
  913. return nodes, nil
  914. }
  915. // SaveX is like Save, but panics if an error occurs.
  916. func (_c *SubscriptionPlanCreateBulk) SaveX(ctx context.Context) []*SubscriptionPlan {
  917. v, err := _c.Save(ctx)
  918. if err != nil {
  919. panic(err)
  920. }
  921. return v
  922. }
  923. // Exec executes the query.
  924. func (_c *SubscriptionPlanCreateBulk) Exec(ctx context.Context) error {
  925. _, err := _c.Save(ctx)
  926. return err
  927. }
  928. // ExecX is like Exec, but panics if an error occurs.
  929. func (_c *SubscriptionPlanCreateBulk) ExecX(ctx context.Context) {
  930. if err := _c.Exec(ctx); err != nil {
  931. panic(err)
  932. }
  933. }
  934. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  935. // of the `INSERT` statement. For example:
  936. //
  937. // client.SubscriptionPlan.CreateBulk(builders...).
  938. // OnConflict(
  939. // // Update the row with the new values
  940. // // the was proposed for insertion.
  941. // sql.ResolveWithNewValues(),
  942. // ).
  943. // // Override some of the fields with custom
  944. // // update values.
  945. // Update(func(u *ent.SubscriptionPlanUpsert) {
  946. // SetGroupID(v+v).
  947. // }).
  948. // Exec(ctx)
  949. func (_c *SubscriptionPlanCreateBulk) OnConflict(opts ...sql.ConflictOption) *SubscriptionPlanUpsertBulk {
  950. _c.conflict = opts
  951. return &SubscriptionPlanUpsertBulk{
  952. create: _c,
  953. }
  954. }
  955. // OnConflictColumns calls `OnConflict` and configures the columns
  956. // as conflict target. Using this option is equivalent to using:
  957. //
  958. // client.SubscriptionPlan.Create().
  959. // OnConflict(sql.ConflictColumns(columns...)).
  960. // Exec(ctx)
  961. func (_c *SubscriptionPlanCreateBulk) OnConflictColumns(columns ...string) *SubscriptionPlanUpsertBulk {
  962. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  963. return &SubscriptionPlanUpsertBulk{
  964. create: _c,
  965. }
  966. }
  967. // SubscriptionPlanUpsertBulk is the builder for "upsert"-ing
  968. // a bulk of SubscriptionPlan nodes.
  969. type SubscriptionPlanUpsertBulk struct {
  970. create *SubscriptionPlanCreateBulk
  971. }
  972. // UpdateNewValues updates the mutable fields using the new values that
  973. // were set on create. Using this option is equivalent to using:
  974. //
  975. // client.SubscriptionPlan.Create().
  976. // OnConflict(
  977. // sql.ResolveWithNewValues(),
  978. // ).
  979. // Exec(ctx)
  980. func (u *SubscriptionPlanUpsertBulk) UpdateNewValues() *SubscriptionPlanUpsertBulk {
  981. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  982. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  983. for _, b := range u.create.builders {
  984. if _, exists := b.mutation.CreatedAt(); exists {
  985. s.SetIgnore(subscriptionplan.FieldCreatedAt)
  986. }
  987. }
  988. }))
  989. return u
  990. }
  991. // Ignore sets each column to itself in case of conflict.
  992. // Using this option is equivalent to using:
  993. //
  994. // client.SubscriptionPlan.Create().
  995. // OnConflict(sql.ResolveWithIgnore()).
  996. // Exec(ctx)
  997. func (u *SubscriptionPlanUpsertBulk) Ignore() *SubscriptionPlanUpsertBulk {
  998. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  999. return u
  1000. }
  1001. // DoNothing configures the conflict_action to `DO NOTHING`.
  1002. // Supported only by SQLite and PostgreSQL.
  1003. func (u *SubscriptionPlanUpsertBulk) DoNothing() *SubscriptionPlanUpsertBulk {
  1004. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1005. return u
  1006. }
  1007. // Update allows overriding fields `UPDATE` values. See the SubscriptionPlanCreateBulk.OnConflict
  1008. // documentation for more info.
  1009. func (u *SubscriptionPlanUpsertBulk) Update(set func(*SubscriptionPlanUpsert)) *SubscriptionPlanUpsertBulk {
  1010. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1011. set(&SubscriptionPlanUpsert{UpdateSet: update})
  1012. }))
  1013. return u
  1014. }
  1015. // SetGroupID sets the "group_id" field.
  1016. func (u *SubscriptionPlanUpsertBulk) SetGroupID(v int64) *SubscriptionPlanUpsertBulk {
  1017. return u.Update(func(s *SubscriptionPlanUpsert) {
  1018. s.SetGroupID(v)
  1019. })
  1020. }
  1021. // AddGroupID adds v to the "group_id" field.
  1022. func (u *SubscriptionPlanUpsertBulk) AddGroupID(v int64) *SubscriptionPlanUpsertBulk {
  1023. return u.Update(func(s *SubscriptionPlanUpsert) {
  1024. s.AddGroupID(v)
  1025. })
  1026. }
  1027. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  1028. func (u *SubscriptionPlanUpsertBulk) UpdateGroupID() *SubscriptionPlanUpsertBulk {
  1029. return u.Update(func(s *SubscriptionPlanUpsert) {
  1030. s.UpdateGroupID()
  1031. })
  1032. }
  1033. // SetName sets the "name" field.
  1034. func (u *SubscriptionPlanUpsertBulk) SetName(v string) *SubscriptionPlanUpsertBulk {
  1035. return u.Update(func(s *SubscriptionPlanUpsert) {
  1036. s.SetName(v)
  1037. })
  1038. }
  1039. // UpdateName sets the "name" field to the value that was provided on create.
  1040. func (u *SubscriptionPlanUpsertBulk) UpdateName() *SubscriptionPlanUpsertBulk {
  1041. return u.Update(func(s *SubscriptionPlanUpsert) {
  1042. s.UpdateName()
  1043. })
  1044. }
  1045. // SetDescription sets the "description" field.
  1046. func (u *SubscriptionPlanUpsertBulk) SetDescription(v string) *SubscriptionPlanUpsertBulk {
  1047. return u.Update(func(s *SubscriptionPlanUpsert) {
  1048. s.SetDescription(v)
  1049. })
  1050. }
  1051. // UpdateDescription sets the "description" field to the value that was provided on create.
  1052. func (u *SubscriptionPlanUpsertBulk) UpdateDescription() *SubscriptionPlanUpsertBulk {
  1053. return u.Update(func(s *SubscriptionPlanUpsert) {
  1054. s.UpdateDescription()
  1055. })
  1056. }
  1057. // SetPrice sets the "price" field.
  1058. func (u *SubscriptionPlanUpsertBulk) SetPrice(v float64) *SubscriptionPlanUpsertBulk {
  1059. return u.Update(func(s *SubscriptionPlanUpsert) {
  1060. s.SetPrice(v)
  1061. })
  1062. }
  1063. // AddPrice adds v to the "price" field.
  1064. func (u *SubscriptionPlanUpsertBulk) AddPrice(v float64) *SubscriptionPlanUpsertBulk {
  1065. return u.Update(func(s *SubscriptionPlanUpsert) {
  1066. s.AddPrice(v)
  1067. })
  1068. }
  1069. // UpdatePrice sets the "price" field to the value that was provided on create.
  1070. func (u *SubscriptionPlanUpsertBulk) UpdatePrice() *SubscriptionPlanUpsertBulk {
  1071. return u.Update(func(s *SubscriptionPlanUpsert) {
  1072. s.UpdatePrice()
  1073. })
  1074. }
  1075. // SetOriginalPrice sets the "original_price" field.
  1076. func (u *SubscriptionPlanUpsertBulk) SetOriginalPrice(v float64) *SubscriptionPlanUpsertBulk {
  1077. return u.Update(func(s *SubscriptionPlanUpsert) {
  1078. s.SetOriginalPrice(v)
  1079. })
  1080. }
  1081. // AddOriginalPrice adds v to the "original_price" field.
  1082. func (u *SubscriptionPlanUpsertBulk) AddOriginalPrice(v float64) *SubscriptionPlanUpsertBulk {
  1083. return u.Update(func(s *SubscriptionPlanUpsert) {
  1084. s.AddOriginalPrice(v)
  1085. })
  1086. }
  1087. // UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
  1088. func (u *SubscriptionPlanUpsertBulk) UpdateOriginalPrice() *SubscriptionPlanUpsertBulk {
  1089. return u.Update(func(s *SubscriptionPlanUpsert) {
  1090. s.UpdateOriginalPrice()
  1091. })
  1092. }
  1093. // ClearOriginalPrice clears the value of the "original_price" field.
  1094. func (u *SubscriptionPlanUpsertBulk) ClearOriginalPrice() *SubscriptionPlanUpsertBulk {
  1095. return u.Update(func(s *SubscriptionPlanUpsert) {
  1096. s.ClearOriginalPrice()
  1097. })
  1098. }
  1099. // SetCurrency sets the "currency" field.
  1100. func (u *SubscriptionPlanUpsertBulk) SetCurrency(v string) *SubscriptionPlanUpsertBulk {
  1101. return u.Update(func(s *SubscriptionPlanUpsert) {
  1102. s.SetCurrency(v)
  1103. })
  1104. }
  1105. // UpdateCurrency sets the "currency" field to the value that was provided on create.
  1106. func (u *SubscriptionPlanUpsertBulk) UpdateCurrency() *SubscriptionPlanUpsertBulk {
  1107. return u.Update(func(s *SubscriptionPlanUpsert) {
  1108. s.UpdateCurrency()
  1109. })
  1110. }
  1111. // SetValidityDays sets the "validity_days" field.
  1112. func (u *SubscriptionPlanUpsertBulk) SetValidityDays(v int) *SubscriptionPlanUpsertBulk {
  1113. return u.Update(func(s *SubscriptionPlanUpsert) {
  1114. s.SetValidityDays(v)
  1115. })
  1116. }
  1117. // AddValidityDays adds v to the "validity_days" field.
  1118. func (u *SubscriptionPlanUpsertBulk) AddValidityDays(v int) *SubscriptionPlanUpsertBulk {
  1119. return u.Update(func(s *SubscriptionPlanUpsert) {
  1120. s.AddValidityDays(v)
  1121. })
  1122. }
  1123. // UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
  1124. func (u *SubscriptionPlanUpsertBulk) UpdateValidityDays() *SubscriptionPlanUpsertBulk {
  1125. return u.Update(func(s *SubscriptionPlanUpsert) {
  1126. s.UpdateValidityDays()
  1127. })
  1128. }
  1129. // SetValidityUnit sets the "validity_unit" field.
  1130. func (u *SubscriptionPlanUpsertBulk) SetValidityUnit(v string) *SubscriptionPlanUpsertBulk {
  1131. return u.Update(func(s *SubscriptionPlanUpsert) {
  1132. s.SetValidityUnit(v)
  1133. })
  1134. }
  1135. // UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
  1136. func (u *SubscriptionPlanUpsertBulk) UpdateValidityUnit() *SubscriptionPlanUpsertBulk {
  1137. return u.Update(func(s *SubscriptionPlanUpsert) {
  1138. s.UpdateValidityUnit()
  1139. })
  1140. }
  1141. // SetFeatures sets the "features" field.
  1142. func (u *SubscriptionPlanUpsertBulk) SetFeatures(v string) *SubscriptionPlanUpsertBulk {
  1143. return u.Update(func(s *SubscriptionPlanUpsert) {
  1144. s.SetFeatures(v)
  1145. })
  1146. }
  1147. // UpdateFeatures sets the "features" field to the value that was provided on create.
  1148. func (u *SubscriptionPlanUpsertBulk) UpdateFeatures() *SubscriptionPlanUpsertBulk {
  1149. return u.Update(func(s *SubscriptionPlanUpsert) {
  1150. s.UpdateFeatures()
  1151. })
  1152. }
  1153. // SetProductName sets the "product_name" field.
  1154. func (u *SubscriptionPlanUpsertBulk) SetProductName(v string) *SubscriptionPlanUpsertBulk {
  1155. return u.Update(func(s *SubscriptionPlanUpsert) {
  1156. s.SetProductName(v)
  1157. })
  1158. }
  1159. // UpdateProductName sets the "product_name" field to the value that was provided on create.
  1160. func (u *SubscriptionPlanUpsertBulk) UpdateProductName() *SubscriptionPlanUpsertBulk {
  1161. return u.Update(func(s *SubscriptionPlanUpsert) {
  1162. s.UpdateProductName()
  1163. })
  1164. }
  1165. // SetForSale sets the "for_sale" field.
  1166. func (u *SubscriptionPlanUpsertBulk) SetForSale(v bool) *SubscriptionPlanUpsertBulk {
  1167. return u.Update(func(s *SubscriptionPlanUpsert) {
  1168. s.SetForSale(v)
  1169. })
  1170. }
  1171. // UpdateForSale sets the "for_sale" field to the value that was provided on create.
  1172. func (u *SubscriptionPlanUpsertBulk) UpdateForSale() *SubscriptionPlanUpsertBulk {
  1173. return u.Update(func(s *SubscriptionPlanUpsert) {
  1174. s.UpdateForSale()
  1175. })
  1176. }
  1177. // SetSortOrder sets the "sort_order" field.
  1178. func (u *SubscriptionPlanUpsertBulk) SetSortOrder(v int) *SubscriptionPlanUpsertBulk {
  1179. return u.Update(func(s *SubscriptionPlanUpsert) {
  1180. s.SetSortOrder(v)
  1181. })
  1182. }
  1183. // AddSortOrder adds v to the "sort_order" field.
  1184. func (u *SubscriptionPlanUpsertBulk) AddSortOrder(v int) *SubscriptionPlanUpsertBulk {
  1185. return u.Update(func(s *SubscriptionPlanUpsert) {
  1186. s.AddSortOrder(v)
  1187. })
  1188. }
  1189. // UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
  1190. func (u *SubscriptionPlanUpsertBulk) UpdateSortOrder() *SubscriptionPlanUpsertBulk {
  1191. return u.Update(func(s *SubscriptionPlanUpsert) {
  1192. s.UpdateSortOrder()
  1193. })
  1194. }
  1195. // SetUpdatedAt sets the "updated_at" field.
  1196. func (u *SubscriptionPlanUpsertBulk) SetUpdatedAt(v time.Time) *SubscriptionPlanUpsertBulk {
  1197. return u.Update(func(s *SubscriptionPlanUpsert) {
  1198. s.SetUpdatedAt(v)
  1199. })
  1200. }
  1201. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1202. func (u *SubscriptionPlanUpsertBulk) UpdateUpdatedAt() *SubscriptionPlanUpsertBulk {
  1203. return u.Update(func(s *SubscriptionPlanUpsert) {
  1204. s.UpdateUpdatedAt()
  1205. })
  1206. }
  1207. // Exec executes the query.
  1208. func (u *SubscriptionPlanUpsertBulk) Exec(ctx context.Context) error {
  1209. if u.create.err != nil {
  1210. return u.create.err
  1211. }
  1212. for i, b := range u.create.builders {
  1213. if len(b.conflict) != 0 {
  1214. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SubscriptionPlanCreateBulk instead", i)
  1215. }
  1216. }
  1217. if len(u.create.conflict) == 0 {
  1218. return errors.New("ent: missing options for SubscriptionPlanCreateBulk.OnConflict")
  1219. }
  1220. return u.create.Exec(ctx)
  1221. }
  1222. // ExecX is like Exec, but panics if an error occurs.
  1223. func (u *SubscriptionPlanUpsertBulk) ExecX(ctx context.Context) {
  1224. if err := u.create.Exec(ctx); err != nil {
  1225. panic(err)
  1226. }
  1227. }