paymentauditlog_create.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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/paymentauditlog"
  12. )
  13. // PaymentAuditLogCreate is the builder for creating a PaymentAuditLog entity.
  14. type PaymentAuditLogCreate struct {
  15. config
  16. mutation *PaymentAuditLogMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetOrderID sets the "order_id" field.
  21. func (_c *PaymentAuditLogCreate) SetOrderID(v string) *PaymentAuditLogCreate {
  22. _c.mutation.SetOrderID(v)
  23. return _c
  24. }
  25. // SetAction sets the "action" field.
  26. func (_c *PaymentAuditLogCreate) SetAction(v string) *PaymentAuditLogCreate {
  27. _c.mutation.SetAction(v)
  28. return _c
  29. }
  30. // SetDetail sets the "detail" field.
  31. func (_c *PaymentAuditLogCreate) SetDetail(v string) *PaymentAuditLogCreate {
  32. _c.mutation.SetDetail(v)
  33. return _c
  34. }
  35. // SetNillableDetail sets the "detail" field if the given value is not nil.
  36. func (_c *PaymentAuditLogCreate) SetNillableDetail(v *string) *PaymentAuditLogCreate {
  37. if v != nil {
  38. _c.SetDetail(*v)
  39. }
  40. return _c
  41. }
  42. // SetOperator sets the "operator" field.
  43. func (_c *PaymentAuditLogCreate) SetOperator(v string) *PaymentAuditLogCreate {
  44. _c.mutation.SetOperator(v)
  45. return _c
  46. }
  47. // SetNillableOperator sets the "operator" field if the given value is not nil.
  48. func (_c *PaymentAuditLogCreate) SetNillableOperator(v *string) *PaymentAuditLogCreate {
  49. if v != nil {
  50. _c.SetOperator(*v)
  51. }
  52. return _c
  53. }
  54. // SetCreatedAt sets the "created_at" field.
  55. func (_c *PaymentAuditLogCreate) SetCreatedAt(v time.Time) *PaymentAuditLogCreate {
  56. _c.mutation.SetCreatedAt(v)
  57. return _c
  58. }
  59. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  60. func (_c *PaymentAuditLogCreate) SetNillableCreatedAt(v *time.Time) *PaymentAuditLogCreate {
  61. if v != nil {
  62. _c.SetCreatedAt(*v)
  63. }
  64. return _c
  65. }
  66. // Mutation returns the PaymentAuditLogMutation object of the builder.
  67. func (_c *PaymentAuditLogCreate) Mutation() *PaymentAuditLogMutation {
  68. return _c.mutation
  69. }
  70. // Save creates the PaymentAuditLog in the database.
  71. func (_c *PaymentAuditLogCreate) Save(ctx context.Context) (*PaymentAuditLog, error) {
  72. _c.defaults()
  73. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  74. }
  75. // SaveX calls Save and panics if Save returns an error.
  76. func (_c *PaymentAuditLogCreate) SaveX(ctx context.Context) *PaymentAuditLog {
  77. v, err := _c.Save(ctx)
  78. if err != nil {
  79. panic(err)
  80. }
  81. return v
  82. }
  83. // Exec executes the query.
  84. func (_c *PaymentAuditLogCreate) Exec(ctx context.Context) error {
  85. _, err := _c.Save(ctx)
  86. return err
  87. }
  88. // ExecX is like Exec, but panics if an error occurs.
  89. func (_c *PaymentAuditLogCreate) ExecX(ctx context.Context) {
  90. if err := _c.Exec(ctx); err != nil {
  91. panic(err)
  92. }
  93. }
  94. // defaults sets the default values of the builder before save.
  95. func (_c *PaymentAuditLogCreate) defaults() {
  96. if _, ok := _c.mutation.Detail(); !ok {
  97. v := paymentauditlog.DefaultDetail
  98. _c.mutation.SetDetail(v)
  99. }
  100. if _, ok := _c.mutation.Operator(); !ok {
  101. v := paymentauditlog.DefaultOperator
  102. _c.mutation.SetOperator(v)
  103. }
  104. if _, ok := _c.mutation.CreatedAt(); !ok {
  105. v := paymentauditlog.DefaultCreatedAt()
  106. _c.mutation.SetCreatedAt(v)
  107. }
  108. }
  109. // check runs all checks and user-defined validators on the builder.
  110. func (_c *PaymentAuditLogCreate) check() error {
  111. if _, ok := _c.mutation.OrderID(); !ok {
  112. return &ValidationError{Name: "order_id", err: errors.New(`ent: missing required field "PaymentAuditLog.order_id"`)}
  113. }
  114. if v, ok := _c.mutation.OrderID(); ok {
  115. if err := paymentauditlog.OrderIDValidator(v); err != nil {
  116. return &ValidationError{Name: "order_id", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.order_id": %w`, err)}
  117. }
  118. }
  119. if _, ok := _c.mutation.Action(); !ok {
  120. return &ValidationError{Name: "action", err: errors.New(`ent: missing required field "PaymentAuditLog.action"`)}
  121. }
  122. if v, ok := _c.mutation.Action(); ok {
  123. if err := paymentauditlog.ActionValidator(v); err != nil {
  124. return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.action": %w`, err)}
  125. }
  126. }
  127. if _, ok := _c.mutation.Detail(); !ok {
  128. return &ValidationError{Name: "detail", err: errors.New(`ent: missing required field "PaymentAuditLog.detail"`)}
  129. }
  130. if _, ok := _c.mutation.Operator(); !ok {
  131. return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "PaymentAuditLog.operator"`)}
  132. }
  133. if v, ok := _c.mutation.Operator(); ok {
  134. if err := paymentauditlog.OperatorValidator(v); err != nil {
  135. return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.operator": %w`, err)}
  136. }
  137. }
  138. if _, ok := _c.mutation.CreatedAt(); !ok {
  139. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "PaymentAuditLog.created_at"`)}
  140. }
  141. return nil
  142. }
  143. func (_c *PaymentAuditLogCreate) sqlSave(ctx context.Context) (*PaymentAuditLog, error) {
  144. if err := _c.check(); err != nil {
  145. return nil, err
  146. }
  147. _node, _spec := _c.createSpec()
  148. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  149. if sqlgraph.IsConstraintError(err) {
  150. err = &ConstraintError{msg: err.Error(), wrap: err}
  151. }
  152. return nil, err
  153. }
  154. id := _spec.ID.Value.(int64)
  155. _node.ID = int64(id)
  156. _c.mutation.id = &_node.ID
  157. _c.mutation.done = true
  158. return _node, nil
  159. }
  160. func (_c *PaymentAuditLogCreate) createSpec() (*PaymentAuditLog, *sqlgraph.CreateSpec) {
  161. var (
  162. _node = &PaymentAuditLog{config: _c.config}
  163. _spec = sqlgraph.NewCreateSpec(paymentauditlog.Table, sqlgraph.NewFieldSpec(paymentauditlog.FieldID, field.TypeInt64))
  164. )
  165. _spec.OnConflict = _c.conflict
  166. if value, ok := _c.mutation.OrderID(); ok {
  167. _spec.SetField(paymentauditlog.FieldOrderID, field.TypeString, value)
  168. _node.OrderID = value
  169. }
  170. if value, ok := _c.mutation.Action(); ok {
  171. _spec.SetField(paymentauditlog.FieldAction, field.TypeString, value)
  172. _node.Action = value
  173. }
  174. if value, ok := _c.mutation.Detail(); ok {
  175. _spec.SetField(paymentauditlog.FieldDetail, field.TypeString, value)
  176. _node.Detail = value
  177. }
  178. if value, ok := _c.mutation.Operator(); ok {
  179. _spec.SetField(paymentauditlog.FieldOperator, field.TypeString, value)
  180. _node.Operator = value
  181. }
  182. if value, ok := _c.mutation.CreatedAt(); ok {
  183. _spec.SetField(paymentauditlog.FieldCreatedAt, field.TypeTime, value)
  184. _node.CreatedAt = value
  185. }
  186. return _node, _spec
  187. }
  188. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  189. // of the `INSERT` statement. For example:
  190. //
  191. // client.PaymentAuditLog.Create().
  192. // SetOrderID(v).
  193. // OnConflict(
  194. // // Update the row with the new values
  195. // // the was proposed for insertion.
  196. // sql.ResolveWithNewValues(),
  197. // ).
  198. // // Override some of the fields with custom
  199. // // update values.
  200. // Update(func(u *ent.PaymentAuditLogUpsert) {
  201. // SetOrderID(v+v).
  202. // }).
  203. // Exec(ctx)
  204. func (_c *PaymentAuditLogCreate) OnConflict(opts ...sql.ConflictOption) *PaymentAuditLogUpsertOne {
  205. _c.conflict = opts
  206. return &PaymentAuditLogUpsertOne{
  207. create: _c,
  208. }
  209. }
  210. // OnConflictColumns calls `OnConflict` and configures the columns
  211. // as conflict target. Using this option is equivalent to using:
  212. //
  213. // client.PaymentAuditLog.Create().
  214. // OnConflict(sql.ConflictColumns(columns...)).
  215. // Exec(ctx)
  216. func (_c *PaymentAuditLogCreate) OnConflictColumns(columns ...string) *PaymentAuditLogUpsertOne {
  217. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  218. return &PaymentAuditLogUpsertOne{
  219. create: _c,
  220. }
  221. }
  222. type (
  223. // PaymentAuditLogUpsertOne is the builder for "upsert"-ing
  224. // one PaymentAuditLog node.
  225. PaymentAuditLogUpsertOne struct {
  226. create *PaymentAuditLogCreate
  227. }
  228. // PaymentAuditLogUpsert is the "OnConflict" setter.
  229. PaymentAuditLogUpsert struct {
  230. *sql.UpdateSet
  231. }
  232. )
  233. // SetOrderID sets the "order_id" field.
  234. func (u *PaymentAuditLogUpsert) SetOrderID(v string) *PaymentAuditLogUpsert {
  235. u.Set(paymentauditlog.FieldOrderID, v)
  236. return u
  237. }
  238. // UpdateOrderID sets the "order_id" field to the value that was provided on create.
  239. func (u *PaymentAuditLogUpsert) UpdateOrderID() *PaymentAuditLogUpsert {
  240. u.SetExcluded(paymentauditlog.FieldOrderID)
  241. return u
  242. }
  243. // SetAction sets the "action" field.
  244. func (u *PaymentAuditLogUpsert) SetAction(v string) *PaymentAuditLogUpsert {
  245. u.Set(paymentauditlog.FieldAction, v)
  246. return u
  247. }
  248. // UpdateAction sets the "action" field to the value that was provided on create.
  249. func (u *PaymentAuditLogUpsert) UpdateAction() *PaymentAuditLogUpsert {
  250. u.SetExcluded(paymentauditlog.FieldAction)
  251. return u
  252. }
  253. // SetDetail sets the "detail" field.
  254. func (u *PaymentAuditLogUpsert) SetDetail(v string) *PaymentAuditLogUpsert {
  255. u.Set(paymentauditlog.FieldDetail, v)
  256. return u
  257. }
  258. // UpdateDetail sets the "detail" field to the value that was provided on create.
  259. func (u *PaymentAuditLogUpsert) UpdateDetail() *PaymentAuditLogUpsert {
  260. u.SetExcluded(paymentauditlog.FieldDetail)
  261. return u
  262. }
  263. // SetOperator sets the "operator" field.
  264. func (u *PaymentAuditLogUpsert) SetOperator(v string) *PaymentAuditLogUpsert {
  265. u.Set(paymentauditlog.FieldOperator, v)
  266. return u
  267. }
  268. // UpdateOperator sets the "operator" field to the value that was provided on create.
  269. func (u *PaymentAuditLogUpsert) UpdateOperator() *PaymentAuditLogUpsert {
  270. u.SetExcluded(paymentauditlog.FieldOperator)
  271. return u
  272. }
  273. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  274. // Using this option is equivalent to using:
  275. //
  276. // client.PaymentAuditLog.Create().
  277. // OnConflict(
  278. // sql.ResolveWithNewValues(),
  279. // ).
  280. // Exec(ctx)
  281. func (u *PaymentAuditLogUpsertOne) UpdateNewValues() *PaymentAuditLogUpsertOne {
  282. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  283. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  284. if _, exists := u.create.mutation.CreatedAt(); exists {
  285. s.SetIgnore(paymentauditlog.FieldCreatedAt)
  286. }
  287. }))
  288. return u
  289. }
  290. // Ignore sets each column to itself in case of conflict.
  291. // Using this option is equivalent to using:
  292. //
  293. // client.PaymentAuditLog.Create().
  294. // OnConflict(sql.ResolveWithIgnore()).
  295. // Exec(ctx)
  296. func (u *PaymentAuditLogUpsertOne) Ignore() *PaymentAuditLogUpsertOne {
  297. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  298. return u
  299. }
  300. // DoNothing configures the conflict_action to `DO NOTHING`.
  301. // Supported only by SQLite and PostgreSQL.
  302. func (u *PaymentAuditLogUpsertOne) DoNothing() *PaymentAuditLogUpsertOne {
  303. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  304. return u
  305. }
  306. // Update allows overriding fields `UPDATE` values. See the PaymentAuditLogCreate.OnConflict
  307. // documentation for more info.
  308. func (u *PaymentAuditLogUpsertOne) Update(set func(*PaymentAuditLogUpsert)) *PaymentAuditLogUpsertOne {
  309. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  310. set(&PaymentAuditLogUpsert{UpdateSet: update})
  311. }))
  312. return u
  313. }
  314. // SetOrderID sets the "order_id" field.
  315. func (u *PaymentAuditLogUpsertOne) SetOrderID(v string) *PaymentAuditLogUpsertOne {
  316. return u.Update(func(s *PaymentAuditLogUpsert) {
  317. s.SetOrderID(v)
  318. })
  319. }
  320. // UpdateOrderID sets the "order_id" field to the value that was provided on create.
  321. func (u *PaymentAuditLogUpsertOne) UpdateOrderID() *PaymentAuditLogUpsertOne {
  322. return u.Update(func(s *PaymentAuditLogUpsert) {
  323. s.UpdateOrderID()
  324. })
  325. }
  326. // SetAction sets the "action" field.
  327. func (u *PaymentAuditLogUpsertOne) SetAction(v string) *PaymentAuditLogUpsertOne {
  328. return u.Update(func(s *PaymentAuditLogUpsert) {
  329. s.SetAction(v)
  330. })
  331. }
  332. // UpdateAction sets the "action" field to the value that was provided on create.
  333. func (u *PaymentAuditLogUpsertOne) UpdateAction() *PaymentAuditLogUpsertOne {
  334. return u.Update(func(s *PaymentAuditLogUpsert) {
  335. s.UpdateAction()
  336. })
  337. }
  338. // SetDetail sets the "detail" field.
  339. func (u *PaymentAuditLogUpsertOne) SetDetail(v string) *PaymentAuditLogUpsertOne {
  340. return u.Update(func(s *PaymentAuditLogUpsert) {
  341. s.SetDetail(v)
  342. })
  343. }
  344. // UpdateDetail sets the "detail" field to the value that was provided on create.
  345. func (u *PaymentAuditLogUpsertOne) UpdateDetail() *PaymentAuditLogUpsertOne {
  346. return u.Update(func(s *PaymentAuditLogUpsert) {
  347. s.UpdateDetail()
  348. })
  349. }
  350. // SetOperator sets the "operator" field.
  351. func (u *PaymentAuditLogUpsertOne) SetOperator(v string) *PaymentAuditLogUpsertOne {
  352. return u.Update(func(s *PaymentAuditLogUpsert) {
  353. s.SetOperator(v)
  354. })
  355. }
  356. // UpdateOperator sets the "operator" field to the value that was provided on create.
  357. func (u *PaymentAuditLogUpsertOne) UpdateOperator() *PaymentAuditLogUpsertOne {
  358. return u.Update(func(s *PaymentAuditLogUpsert) {
  359. s.UpdateOperator()
  360. })
  361. }
  362. // Exec executes the query.
  363. func (u *PaymentAuditLogUpsertOne) Exec(ctx context.Context) error {
  364. if len(u.create.conflict) == 0 {
  365. return errors.New("ent: missing options for PaymentAuditLogCreate.OnConflict")
  366. }
  367. return u.create.Exec(ctx)
  368. }
  369. // ExecX is like Exec, but panics if an error occurs.
  370. func (u *PaymentAuditLogUpsertOne) ExecX(ctx context.Context) {
  371. if err := u.create.Exec(ctx); err != nil {
  372. panic(err)
  373. }
  374. }
  375. // Exec executes the UPSERT query and returns the inserted/updated ID.
  376. func (u *PaymentAuditLogUpsertOne) ID(ctx context.Context) (id int64, err error) {
  377. node, err := u.create.Save(ctx)
  378. if err != nil {
  379. return id, err
  380. }
  381. return node.ID, nil
  382. }
  383. // IDX is like ID, but panics if an error occurs.
  384. func (u *PaymentAuditLogUpsertOne) IDX(ctx context.Context) int64 {
  385. id, err := u.ID(ctx)
  386. if err != nil {
  387. panic(err)
  388. }
  389. return id
  390. }
  391. // PaymentAuditLogCreateBulk is the builder for creating many PaymentAuditLog entities in bulk.
  392. type PaymentAuditLogCreateBulk struct {
  393. config
  394. err error
  395. builders []*PaymentAuditLogCreate
  396. conflict []sql.ConflictOption
  397. }
  398. // Save creates the PaymentAuditLog entities in the database.
  399. func (_c *PaymentAuditLogCreateBulk) Save(ctx context.Context) ([]*PaymentAuditLog, error) {
  400. if _c.err != nil {
  401. return nil, _c.err
  402. }
  403. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  404. nodes := make([]*PaymentAuditLog, len(_c.builders))
  405. mutators := make([]Mutator, len(_c.builders))
  406. for i := range _c.builders {
  407. func(i int, root context.Context) {
  408. builder := _c.builders[i]
  409. builder.defaults()
  410. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  411. mutation, ok := m.(*PaymentAuditLogMutation)
  412. if !ok {
  413. return nil, fmt.Errorf("unexpected mutation type %T", m)
  414. }
  415. if err := builder.check(); err != nil {
  416. return nil, err
  417. }
  418. builder.mutation = mutation
  419. var err error
  420. nodes[i], specs[i] = builder.createSpec()
  421. if i < len(mutators)-1 {
  422. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  423. } else {
  424. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  425. spec.OnConflict = _c.conflict
  426. // Invoke the actual operation on the latest mutation in the chain.
  427. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  428. if sqlgraph.IsConstraintError(err) {
  429. err = &ConstraintError{msg: err.Error(), wrap: err}
  430. }
  431. }
  432. }
  433. if err != nil {
  434. return nil, err
  435. }
  436. mutation.id = &nodes[i].ID
  437. if specs[i].ID.Value != nil {
  438. id := specs[i].ID.Value.(int64)
  439. nodes[i].ID = int64(id)
  440. }
  441. mutation.done = true
  442. return nodes[i], nil
  443. })
  444. for i := len(builder.hooks) - 1; i >= 0; i-- {
  445. mut = builder.hooks[i](mut)
  446. }
  447. mutators[i] = mut
  448. }(i, ctx)
  449. }
  450. if len(mutators) > 0 {
  451. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  452. return nil, err
  453. }
  454. }
  455. return nodes, nil
  456. }
  457. // SaveX is like Save, but panics if an error occurs.
  458. func (_c *PaymentAuditLogCreateBulk) SaveX(ctx context.Context) []*PaymentAuditLog {
  459. v, err := _c.Save(ctx)
  460. if err != nil {
  461. panic(err)
  462. }
  463. return v
  464. }
  465. // Exec executes the query.
  466. func (_c *PaymentAuditLogCreateBulk) Exec(ctx context.Context) error {
  467. _, err := _c.Save(ctx)
  468. return err
  469. }
  470. // ExecX is like Exec, but panics if an error occurs.
  471. func (_c *PaymentAuditLogCreateBulk) ExecX(ctx context.Context) {
  472. if err := _c.Exec(ctx); err != nil {
  473. panic(err)
  474. }
  475. }
  476. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  477. // of the `INSERT` statement. For example:
  478. //
  479. // client.PaymentAuditLog.CreateBulk(builders...).
  480. // OnConflict(
  481. // // Update the row with the new values
  482. // // the was proposed for insertion.
  483. // sql.ResolveWithNewValues(),
  484. // ).
  485. // // Override some of the fields with custom
  486. // // update values.
  487. // Update(func(u *ent.PaymentAuditLogUpsert) {
  488. // SetOrderID(v+v).
  489. // }).
  490. // Exec(ctx)
  491. func (_c *PaymentAuditLogCreateBulk) OnConflict(opts ...sql.ConflictOption) *PaymentAuditLogUpsertBulk {
  492. _c.conflict = opts
  493. return &PaymentAuditLogUpsertBulk{
  494. create: _c,
  495. }
  496. }
  497. // OnConflictColumns calls `OnConflict` and configures the columns
  498. // as conflict target. Using this option is equivalent to using:
  499. //
  500. // client.PaymentAuditLog.Create().
  501. // OnConflict(sql.ConflictColumns(columns...)).
  502. // Exec(ctx)
  503. func (_c *PaymentAuditLogCreateBulk) OnConflictColumns(columns ...string) *PaymentAuditLogUpsertBulk {
  504. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  505. return &PaymentAuditLogUpsertBulk{
  506. create: _c,
  507. }
  508. }
  509. // PaymentAuditLogUpsertBulk is the builder for "upsert"-ing
  510. // a bulk of PaymentAuditLog nodes.
  511. type PaymentAuditLogUpsertBulk struct {
  512. create *PaymentAuditLogCreateBulk
  513. }
  514. // UpdateNewValues updates the mutable fields using the new values that
  515. // were set on create. Using this option is equivalent to using:
  516. //
  517. // client.PaymentAuditLog.Create().
  518. // OnConflict(
  519. // sql.ResolveWithNewValues(),
  520. // ).
  521. // Exec(ctx)
  522. func (u *PaymentAuditLogUpsertBulk) UpdateNewValues() *PaymentAuditLogUpsertBulk {
  523. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  524. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  525. for _, b := range u.create.builders {
  526. if _, exists := b.mutation.CreatedAt(); exists {
  527. s.SetIgnore(paymentauditlog.FieldCreatedAt)
  528. }
  529. }
  530. }))
  531. return u
  532. }
  533. // Ignore sets each column to itself in case of conflict.
  534. // Using this option is equivalent to using:
  535. //
  536. // client.PaymentAuditLog.Create().
  537. // OnConflict(sql.ResolveWithIgnore()).
  538. // Exec(ctx)
  539. func (u *PaymentAuditLogUpsertBulk) Ignore() *PaymentAuditLogUpsertBulk {
  540. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  541. return u
  542. }
  543. // DoNothing configures the conflict_action to `DO NOTHING`.
  544. // Supported only by SQLite and PostgreSQL.
  545. func (u *PaymentAuditLogUpsertBulk) DoNothing() *PaymentAuditLogUpsertBulk {
  546. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  547. return u
  548. }
  549. // Update allows overriding fields `UPDATE` values. See the PaymentAuditLogCreateBulk.OnConflict
  550. // documentation for more info.
  551. func (u *PaymentAuditLogUpsertBulk) Update(set func(*PaymentAuditLogUpsert)) *PaymentAuditLogUpsertBulk {
  552. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  553. set(&PaymentAuditLogUpsert{UpdateSet: update})
  554. }))
  555. return u
  556. }
  557. // SetOrderID sets the "order_id" field.
  558. func (u *PaymentAuditLogUpsertBulk) SetOrderID(v string) *PaymentAuditLogUpsertBulk {
  559. return u.Update(func(s *PaymentAuditLogUpsert) {
  560. s.SetOrderID(v)
  561. })
  562. }
  563. // UpdateOrderID sets the "order_id" field to the value that was provided on create.
  564. func (u *PaymentAuditLogUpsertBulk) UpdateOrderID() *PaymentAuditLogUpsertBulk {
  565. return u.Update(func(s *PaymentAuditLogUpsert) {
  566. s.UpdateOrderID()
  567. })
  568. }
  569. // SetAction sets the "action" field.
  570. func (u *PaymentAuditLogUpsertBulk) SetAction(v string) *PaymentAuditLogUpsertBulk {
  571. return u.Update(func(s *PaymentAuditLogUpsert) {
  572. s.SetAction(v)
  573. })
  574. }
  575. // UpdateAction sets the "action" field to the value that was provided on create.
  576. func (u *PaymentAuditLogUpsertBulk) UpdateAction() *PaymentAuditLogUpsertBulk {
  577. return u.Update(func(s *PaymentAuditLogUpsert) {
  578. s.UpdateAction()
  579. })
  580. }
  581. // SetDetail sets the "detail" field.
  582. func (u *PaymentAuditLogUpsertBulk) SetDetail(v string) *PaymentAuditLogUpsertBulk {
  583. return u.Update(func(s *PaymentAuditLogUpsert) {
  584. s.SetDetail(v)
  585. })
  586. }
  587. // UpdateDetail sets the "detail" field to the value that was provided on create.
  588. func (u *PaymentAuditLogUpsertBulk) UpdateDetail() *PaymentAuditLogUpsertBulk {
  589. return u.Update(func(s *PaymentAuditLogUpsert) {
  590. s.UpdateDetail()
  591. })
  592. }
  593. // SetOperator sets the "operator" field.
  594. func (u *PaymentAuditLogUpsertBulk) SetOperator(v string) *PaymentAuditLogUpsertBulk {
  595. return u.Update(func(s *PaymentAuditLogUpsert) {
  596. s.SetOperator(v)
  597. })
  598. }
  599. // UpdateOperator sets the "operator" field to the value that was provided on create.
  600. func (u *PaymentAuditLogUpsertBulk) UpdateOperator() *PaymentAuditLogUpsertBulk {
  601. return u.Update(func(s *PaymentAuditLogUpsert) {
  602. s.UpdateOperator()
  603. })
  604. }
  605. // Exec executes the query.
  606. func (u *PaymentAuditLogUpsertBulk) Exec(ctx context.Context) error {
  607. if u.create.err != nil {
  608. return u.create.err
  609. }
  610. for i, b := range u.create.builders {
  611. if len(b.conflict) != 0 {
  612. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the PaymentAuditLogCreateBulk instead", i)
  613. }
  614. }
  615. if len(u.create.conflict) == 0 {
  616. return errors.New("ent: missing options for PaymentAuditLogCreateBulk.OnConflict")
  617. }
  618. return u.create.Exec(ctx)
  619. }
  620. // ExecX is like Exec, but panics if an error occurs.
  621. func (u *PaymentAuditLogUpsertBulk) ExecX(ctx context.Context) {
  622. if err := u.create.Exec(ctx); err != nil {
  623. panic(err)
  624. }
  625. }