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