github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/fiat_create.go (about)

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