batchimageevent_create.go 22 KB

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