redeemcode_create.go 36 KB

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