github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/exchangerate_update.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/exchangerate"
    14  	"github.com/NpoolPlatform/chain-middleware/pkg/db/ent/predicate"
    15  	"github.com/google/uuid"
    16  	"github.com/shopspring/decimal"
    17  )
    18  
    19  // ExchangeRateUpdate is the builder for updating ExchangeRate entities.
    20  type ExchangeRateUpdate struct {
    21  	config
    22  	hooks     []Hook
    23  	mutation  *ExchangeRateMutation
    24  	modifiers []func(*sql.UpdateBuilder)
    25  }
    26  
    27  // Where appends a list predicates to the ExchangeRateUpdate builder.
    28  func (eru *ExchangeRateUpdate) Where(ps ...predicate.ExchangeRate) *ExchangeRateUpdate {
    29  	eru.mutation.Where(ps...)
    30  	return eru
    31  }
    32  
    33  // SetCreatedAt sets the "created_at" field.
    34  func (eru *ExchangeRateUpdate) SetCreatedAt(u uint32) *ExchangeRateUpdate {
    35  	eru.mutation.ResetCreatedAt()
    36  	eru.mutation.SetCreatedAt(u)
    37  	return eru
    38  }
    39  
    40  // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
    41  func (eru *ExchangeRateUpdate) SetNillableCreatedAt(u *uint32) *ExchangeRateUpdate {
    42  	if u != nil {
    43  		eru.SetCreatedAt(*u)
    44  	}
    45  	return eru
    46  }
    47  
    48  // AddCreatedAt adds u to the "created_at" field.
    49  func (eru *ExchangeRateUpdate) AddCreatedAt(u int32) *ExchangeRateUpdate {
    50  	eru.mutation.AddCreatedAt(u)
    51  	return eru
    52  }
    53  
    54  // SetUpdatedAt sets the "updated_at" field.
    55  func (eru *ExchangeRateUpdate) SetUpdatedAt(u uint32) *ExchangeRateUpdate {
    56  	eru.mutation.ResetUpdatedAt()
    57  	eru.mutation.SetUpdatedAt(u)
    58  	return eru
    59  }
    60  
    61  // AddUpdatedAt adds u to the "updated_at" field.
    62  func (eru *ExchangeRateUpdate) AddUpdatedAt(u int32) *ExchangeRateUpdate {
    63  	eru.mutation.AddUpdatedAt(u)
    64  	return eru
    65  }
    66  
    67  // SetDeletedAt sets the "deleted_at" field.
    68  func (eru *ExchangeRateUpdate) SetDeletedAt(u uint32) *ExchangeRateUpdate {
    69  	eru.mutation.ResetDeletedAt()
    70  	eru.mutation.SetDeletedAt(u)
    71  	return eru
    72  }
    73  
    74  // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
    75  func (eru *ExchangeRateUpdate) SetNillableDeletedAt(u *uint32) *ExchangeRateUpdate {
    76  	if u != nil {
    77  		eru.SetDeletedAt(*u)
    78  	}
    79  	return eru
    80  }
    81  
    82  // AddDeletedAt adds u to the "deleted_at" field.
    83  func (eru *ExchangeRateUpdate) AddDeletedAt(u int32) *ExchangeRateUpdate {
    84  	eru.mutation.AddDeletedAt(u)
    85  	return eru
    86  }
    87  
    88  // SetEntID sets the "ent_id" field.
    89  func (eru *ExchangeRateUpdate) SetEntID(u uuid.UUID) *ExchangeRateUpdate {
    90  	eru.mutation.SetEntID(u)
    91  	return eru
    92  }
    93  
    94  // SetNillableEntID sets the "ent_id" field if the given value is not nil.
    95  func (eru *ExchangeRateUpdate) SetNillableEntID(u *uuid.UUID) *ExchangeRateUpdate {
    96  	if u != nil {
    97  		eru.SetEntID(*u)
    98  	}
    99  	return eru
   100  }
   101  
   102  // SetAppID sets the "app_id" field.
   103  func (eru *ExchangeRateUpdate) SetAppID(u uuid.UUID) *ExchangeRateUpdate {
   104  	eru.mutation.SetAppID(u)
   105  	return eru
   106  }
   107  
   108  // SetNillableAppID sets the "app_id" field if the given value is not nil.
   109  func (eru *ExchangeRateUpdate) SetNillableAppID(u *uuid.UUID) *ExchangeRateUpdate {
   110  	if u != nil {
   111  		eru.SetAppID(*u)
   112  	}
   113  	return eru
   114  }
   115  
   116  // ClearAppID clears the value of the "app_id" field.
   117  func (eru *ExchangeRateUpdate) ClearAppID() *ExchangeRateUpdate {
   118  	eru.mutation.ClearAppID()
   119  	return eru
   120  }
   121  
   122  // SetCoinTypeID sets the "coin_type_id" field.
   123  func (eru *ExchangeRateUpdate) SetCoinTypeID(u uuid.UUID) *ExchangeRateUpdate {
   124  	eru.mutation.SetCoinTypeID(u)
   125  	return eru
   126  }
   127  
   128  // SetNillableCoinTypeID sets the "coin_type_id" field if the given value is not nil.
   129  func (eru *ExchangeRateUpdate) SetNillableCoinTypeID(u *uuid.UUID) *ExchangeRateUpdate {
   130  	if u != nil {
   131  		eru.SetCoinTypeID(*u)
   132  	}
   133  	return eru
   134  }
   135  
   136  // ClearCoinTypeID clears the value of the "coin_type_id" field.
   137  func (eru *ExchangeRateUpdate) ClearCoinTypeID() *ExchangeRateUpdate {
   138  	eru.mutation.ClearCoinTypeID()
   139  	return eru
   140  }
   141  
   142  // SetMarketValue sets the "market_value" field.
   143  func (eru *ExchangeRateUpdate) SetMarketValue(d decimal.Decimal) *ExchangeRateUpdate {
   144  	eru.mutation.SetMarketValue(d)
   145  	return eru
   146  }
   147  
   148  // SetNillableMarketValue sets the "market_value" field if the given value is not nil.
   149  func (eru *ExchangeRateUpdate) SetNillableMarketValue(d *decimal.Decimal) *ExchangeRateUpdate {
   150  	if d != nil {
   151  		eru.SetMarketValue(*d)
   152  	}
   153  	return eru
   154  }
   155  
   156  // ClearMarketValue clears the value of the "market_value" field.
   157  func (eru *ExchangeRateUpdate) ClearMarketValue() *ExchangeRateUpdate {
   158  	eru.mutation.ClearMarketValue()
   159  	return eru
   160  }
   161  
   162  // SetSettleValue sets the "settle_value" field.
   163  func (eru *ExchangeRateUpdate) SetSettleValue(d decimal.Decimal) *ExchangeRateUpdate {
   164  	eru.mutation.SetSettleValue(d)
   165  	return eru
   166  }
   167  
   168  // SetNillableSettleValue sets the "settle_value" field if the given value is not nil.
   169  func (eru *ExchangeRateUpdate) SetNillableSettleValue(d *decimal.Decimal) *ExchangeRateUpdate {
   170  	if d != nil {
   171  		eru.SetSettleValue(*d)
   172  	}
   173  	return eru
   174  }
   175  
   176  // ClearSettleValue clears the value of the "settle_value" field.
   177  func (eru *ExchangeRateUpdate) ClearSettleValue() *ExchangeRateUpdate {
   178  	eru.mutation.ClearSettleValue()
   179  	return eru
   180  }
   181  
   182  // SetSettlePercent sets the "settle_percent" field.
   183  func (eru *ExchangeRateUpdate) SetSettlePercent(u uint32) *ExchangeRateUpdate {
   184  	eru.mutation.ResetSettlePercent()
   185  	eru.mutation.SetSettlePercent(u)
   186  	return eru
   187  }
   188  
   189  // SetNillableSettlePercent sets the "settle_percent" field if the given value is not nil.
   190  func (eru *ExchangeRateUpdate) SetNillableSettlePercent(u *uint32) *ExchangeRateUpdate {
   191  	if u != nil {
   192  		eru.SetSettlePercent(*u)
   193  	}
   194  	return eru
   195  }
   196  
   197  // AddSettlePercent adds u to the "settle_percent" field.
   198  func (eru *ExchangeRateUpdate) AddSettlePercent(u int32) *ExchangeRateUpdate {
   199  	eru.mutation.AddSettlePercent(u)
   200  	return eru
   201  }
   202  
   203  // ClearSettlePercent clears the value of the "settle_percent" field.
   204  func (eru *ExchangeRateUpdate) ClearSettlePercent() *ExchangeRateUpdate {
   205  	eru.mutation.ClearSettlePercent()
   206  	return eru
   207  }
   208  
   209  // SetSettleTips sets the "settle_tips" field.
   210  func (eru *ExchangeRateUpdate) SetSettleTips(s []string) *ExchangeRateUpdate {
   211  	eru.mutation.SetSettleTips(s)
   212  	return eru
   213  }
   214  
   215  // ClearSettleTips clears the value of the "settle_tips" field.
   216  func (eru *ExchangeRateUpdate) ClearSettleTips() *ExchangeRateUpdate {
   217  	eru.mutation.ClearSettleTips()
   218  	return eru
   219  }
   220  
   221  // SetSetter sets the "setter" field.
   222  func (eru *ExchangeRateUpdate) SetSetter(u uuid.UUID) *ExchangeRateUpdate {
   223  	eru.mutation.SetSetter(u)
   224  	return eru
   225  }
   226  
   227  // SetNillableSetter sets the "setter" field if the given value is not nil.
   228  func (eru *ExchangeRateUpdate) SetNillableSetter(u *uuid.UUID) *ExchangeRateUpdate {
   229  	if u != nil {
   230  		eru.SetSetter(*u)
   231  	}
   232  	return eru
   233  }
   234  
   235  // ClearSetter clears the value of the "setter" field.
   236  func (eru *ExchangeRateUpdate) ClearSetter() *ExchangeRateUpdate {
   237  	eru.mutation.ClearSetter()
   238  	return eru
   239  }
   240  
   241  // Mutation returns the ExchangeRateMutation object of the builder.
   242  func (eru *ExchangeRateUpdate) Mutation() *ExchangeRateMutation {
   243  	return eru.mutation
   244  }
   245  
   246  // Save executes the query and returns the number of nodes affected by the update operation.
   247  func (eru *ExchangeRateUpdate) Save(ctx context.Context) (int, error) {
   248  	var (
   249  		err      error
   250  		affected int
   251  	)
   252  	if err := eru.defaults(); err != nil {
   253  		return 0, err
   254  	}
   255  	if len(eru.hooks) == 0 {
   256  		affected, err = eru.sqlSave(ctx)
   257  	} else {
   258  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   259  			mutation, ok := m.(*ExchangeRateMutation)
   260  			if !ok {
   261  				return nil, fmt.Errorf("unexpected mutation type %T", m)
   262  			}
   263  			eru.mutation = mutation
   264  			affected, err = eru.sqlSave(ctx)
   265  			mutation.done = true
   266  			return affected, err
   267  		})
   268  		for i := len(eru.hooks) - 1; i >= 0; i-- {
   269  			if eru.hooks[i] == nil {
   270  				return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
   271  			}
   272  			mut = eru.hooks[i](mut)
   273  		}
   274  		if _, err := mut.Mutate(ctx, eru.mutation); err != nil {
   275  			return 0, err
   276  		}
   277  	}
   278  	return affected, err
   279  }
   280  
   281  // SaveX is like Save, but panics if an error occurs.
   282  func (eru *ExchangeRateUpdate) SaveX(ctx context.Context) int {
   283  	affected, err := eru.Save(ctx)
   284  	if err != nil {
   285  		panic(err)
   286  	}
   287  	return affected
   288  }
   289  
   290  // Exec executes the query.
   291  func (eru *ExchangeRateUpdate) Exec(ctx context.Context) error {
   292  	_, err := eru.Save(ctx)
   293  	return err
   294  }
   295  
   296  // ExecX is like Exec, but panics if an error occurs.
   297  func (eru *ExchangeRateUpdate) ExecX(ctx context.Context) {
   298  	if err := eru.Exec(ctx); err != nil {
   299  		panic(err)
   300  	}
   301  }
   302  
   303  // defaults sets the default values of the builder before save.
   304  func (eru *ExchangeRateUpdate) defaults() error {
   305  	if _, ok := eru.mutation.UpdatedAt(); !ok {
   306  		if exchangerate.UpdateDefaultUpdatedAt == nil {
   307  			return fmt.Errorf("ent: uninitialized exchangerate.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
   308  		}
   309  		v := exchangerate.UpdateDefaultUpdatedAt()
   310  		eru.mutation.SetUpdatedAt(v)
   311  	}
   312  	return nil
   313  }
   314  
   315  // Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
   316  func (eru *ExchangeRateUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ExchangeRateUpdate {
   317  	eru.modifiers = append(eru.modifiers, modifiers...)
   318  	return eru
   319  }
   320  
   321  func (eru *ExchangeRateUpdate) sqlSave(ctx context.Context) (n int, err error) {
   322  	_spec := &sqlgraph.UpdateSpec{
   323  		Node: &sqlgraph.NodeSpec{
   324  			Table:   exchangerate.Table,
   325  			Columns: exchangerate.Columns,
   326  			ID: &sqlgraph.FieldSpec{
   327  				Type:   field.TypeUint32,
   328  				Column: exchangerate.FieldID,
   329  			},
   330  		},
   331  	}
   332  	if ps := eru.mutation.predicates; len(ps) > 0 {
   333  		_spec.Predicate = func(selector *sql.Selector) {
   334  			for i := range ps {
   335  				ps[i](selector)
   336  			}
   337  		}
   338  	}
   339  	if value, ok := eru.mutation.CreatedAt(); ok {
   340  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   341  			Type:   field.TypeUint32,
   342  			Value:  value,
   343  			Column: exchangerate.FieldCreatedAt,
   344  		})
   345  	}
   346  	if value, ok := eru.mutation.AddedCreatedAt(); ok {
   347  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   348  			Type:   field.TypeUint32,
   349  			Value:  value,
   350  			Column: exchangerate.FieldCreatedAt,
   351  		})
   352  	}
   353  	if value, ok := eru.mutation.UpdatedAt(); ok {
   354  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   355  			Type:   field.TypeUint32,
   356  			Value:  value,
   357  			Column: exchangerate.FieldUpdatedAt,
   358  		})
   359  	}
   360  	if value, ok := eru.mutation.AddedUpdatedAt(); ok {
   361  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   362  			Type:   field.TypeUint32,
   363  			Value:  value,
   364  			Column: exchangerate.FieldUpdatedAt,
   365  		})
   366  	}
   367  	if value, ok := eru.mutation.DeletedAt(); ok {
   368  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   369  			Type:   field.TypeUint32,
   370  			Value:  value,
   371  			Column: exchangerate.FieldDeletedAt,
   372  		})
   373  	}
   374  	if value, ok := eru.mutation.AddedDeletedAt(); ok {
   375  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   376  			Type:   field.TypeUint32,
   377  			Value:  value,
   378  			Column: exchangerate.FieldDeletedAt,
   379  		})
   380  	}
   381  	if value, ok := eru.mutation.EntID(); ok {
   382  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   383  			Type:   field.TypeUUID,
   384  			Value:  value,
   385  			Column: exchangerate.FieldEntID,
   386  		})
   387  	}
   388  	if value, ok := eru.mutation.AppID(); ok {
   389  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   390  			Type:   field.TypeUUID,
   391  			Value:  value,
   392  			Column: exchangerate.FieldAppID,
   393  		})
   394  	}
   395  	if eru.mutation.AppIDCleared() {
   396  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   397  			Type:   field.TypeUUID,
   398  			Column: exchangerate.FieldAppID,
   399  		})
   400  	}
   401  	if value, ok := eru.mutation.CoinTypeID(); ok {
   402  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   403  			Type:   field.TypeUUID,
   404  			Value:  value,
   405  			Column: exchangerate.FieldCoinTypeID,
   406  		})
   407  	}
   408  	if eru.mutation.CoinTypeIDCleared() {
   409  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   410  			Type:   field.TypeUUID,
   411  			Column: exchangerate.FieldCoinTypeID,
   412  		})
   413  	}
   414  	if value, ok := eru.mutation.MarketValue(); ok {
   415  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   416  			Type:   field.TypeOther,
   417  			Value:  value,
   418  			Column: exchangerate.FieldMarketValue,
   419  		})
   420  	}
   421  	if eru.mutation.MarketValueCleared() {
   422  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   423  			Type:   field.TypeOther,
   424  			Column: exchangerate.FieldMarketValue,
   425  		})
   426  	}
   427  	if value, ok := eru.mutation.SettleValue(); ok {
   428  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   429  			Type:   field.TypeOther,
   430  			Value:  value,
   431  			Column: exchangerate.FieldSettleValue,
   432  		})
   433  	}
   434  	if eru.mutation.SettleValueCleared() {
   435  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   436  			Type:   field.TypeOther,
   437  			Column: exchangerate.FieldSettleValue,
   438  		})
   439  	}
   440  	if value, ok := eru.mutation.SettlePercent(); ok {
   441  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   442  			Type:   field.TypeUint32,
   443  			Value:  value,
   444  			Column: exchangerate.FieldSettlePercent,
   445  		})
   446  	}
   447  	if value, ok := eru.mutation.AddedSettlePercent(); ok {
   448  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   449  			Type:   field.TypeUint32,
   450  			Value:  value,
   451  			Column: exchangerate.FieldSettlePercent,
   452  		})
   453  	}
   454  	if eru.mutation.SettlePercentCleared() {
   455  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   456  			Type:   field.TypeUint32,
   457  			Column: exchangerate.FieldSettlePercent,
   458  		})
   459  	}
   460  	if value, ok := eru.mutation.SettleTips(); ok {
   461  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   462  			Type:   field.TypeJSON,
   463  			Value:  value,
   464  			Column: exchangerate.FieldSettleTips,
   465  		})
   466  	}
   467  	if eru.mutation.SettleTipsCleared() {
   468  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   469  			Type:   field.TypeJSON,
   470  			Column: exchangerate.FieldSettleTips,
   471  		})
   472  	}
   473  	if value, ok := eru.mutation.Setter(); ok {
   474  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   475  			Type:   field.TypeUUID,
   476  			Value:  value,
   477  			Column: exchangerate.FieldSetter,
   478  		})
   479  	}
   480  	if eru.mutation.SetterCleared() {
   481  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   482  			Type:   field.TypeUUID,
   483  			Column: exchangerate.FieldSetter,
   484  		})
   485  	}
   486  	_spec.Modifiers = eru.modifiers
   487  	if n, err = sqlgraph.UpdateNodes(ctx, eru.driver, _spec); err != nil {
   488  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   489  			err = &NotFoundError{exchangerate.Label}
   490  		} else if sqlgraph.IsConstraintError(err) {
   491  			err = &ConstraintError{msg: err.Error(), wrap: err}
   492  		}
   493  		return 0, err
   494  	}
   495  	return n, nil
   496  }
   497  
   498  // ExchangeRateUpdateOne is the builder for updating a single ExchangeRate entity.
   499  type ExchangeRateUpdateOne struct {
   500  	config
   501  	fields    []string
   502  	hooks     []Hook
   503  	mutation  *ExchangeRateMutation
   504  	modifiers []func(*sql.UpdateBuilder)
   505  }
   506  
   507  // SetCreatedAt sets the "created_at" field.
   508  func (eruo *ExchangeRateUpdateOne) SetCreatedAt(u uint32) *ExchangeRateUpdateOne {
   509  	eruo.mutation.ResetCreatedAt()
   510  	eruo.mutation.SetCreatedAt(u)
   511  	return eruo
   512  }
   513  
   514  // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
   515  func (eruo *ExchangeRateUpdateOne) SetNillableCreatedAt(u *uint32) *ExchangeRateUpdateOne {
   516  	if u != nil {
   517  		eruo.SetCreatedAt(*u)
   518  	}
   519  	return eruo
   520  }
   521  
   522  // AddCreatedAt adds u to the "created_at" field.
   523  func (eruo *ExchangeRateUpdateOne) AddCreatedAt(u int32) *ExchangeRateUpdateOne {
   524  	eruo.mutation.AddCreatedAt(u)
   525  	return eruo
   526  }
   527  
   528  // SetUpdatedAt sets the "updated_at" field.
   529  func (eruo *ExchangeRateUpdateOne) SetUpdatedAt(u uint32) *ExchangeRateUpdateOne {
   530  	eruo.mutation.ResetUpdatedAt()
   531  	eruo.mutation.SetUpdatedAt(u)
   532  	return eruo
   533  }
   534  
   535  // AddUpdatedAt adds u to the "updated_at" field.
   536  func (eruo *ExchangeRateUpdateOne) AddUpdatedAt(u int32) *ExchangeRateUpdateOne {
   537  	eruo.mutation.AddUpdatedAt(u)
   538  	return eruo
   539  }
   540  
   541  // SetDeletedAt sets the "deleted_at" field.
   542  func (eruo *ExchangeRateUpdateOne) SetDeletedAt(u uint32) *ExchangeRateUpdateOne {
   543  	eruo.mutation.ResetDeletedAt()
   544  	eruo.mutation.SetDeletedAt(u)
   545  	return eruo
   546  }
   547  
   548  // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
   549  func (eruo *ExchangeRateUpdateOne) SetNillableDeletedAt(u *uint32) *ExchangeRateUpdateOne {
   550  	if u != nil {
   551  		eruo.SetDeletedAt(*u)
   552  	}
   553  	return eruo
   554  }
   555  
   556  // AddDeletedAt adds u to the "deleted_at" field.
   557  func (eruo *ExchangeRateUpdateOne) AddDeletedAt(u int32) *ExchangeRateUpdateOne {
   558  	eruo.mutation.AddDeletedAt(u)
   559  	return eruo
   560  }
   561  
   562  // SetEntID sets the "ent_id" field.
   563  func (eruo *ExchangeRateUpdateOne) SetEntID(u uuid.UUID) *ExchangeRateUpdateOne {
   564  	eruo.mutation.SetEntID(u)
   565  	return eruo
   566  }
   567  
   568  // SetNillableEntID sets the "ent_id" field if the given value is not nil.
   569  func (eruo *ExchangeRateUpdateOne) SetNillableEntID(u *uuid.UUID) *ExchangeRateUpdateOne {
   570  	if u != nil {
   571  		eruo.SetEntID(*u)
   572  	}
   573  	return eruo
   574  }
   575  
   576  // SetAppID sets the "app_id" field.
   577  func (eruo *ExchangeRateUpdateOne) SetAppID(u uuid.UUID) *ExchangeRateUpdateOne {
   578  	eruo.mutation.SetAppID(u)
   579  	return eruo
   580  }
   581  
   582  // SetNillableAppID sets the "app_id" field if the given value is not nil.
   583  func (eruo *ExchangeRateUpdateOne) SetNillableAppID(u *uuid.UUID) *ExchangeRateUpdateOne {
   584  	if u != nil {
   585  		eruo.SetAppID(*u)
   586  	}
   587  	return eruo
   588  }
   589  
   590  // ClearAppID clears the value of the "app_id" field.
   591  func (eruo *ExchangeRateUpdateOne) ClearAppID() *ExchangeRateUpdateOne {
   592  	eruo.mutation.ClearAppID()
   593  	return eruo
   594  }
   595  
   596  // SetCoinTypeID sets the "coin_type_id" field.
   597  func (eruo *ExchangeRateUpdateOne) SetCoinTypeID(u uuid.UUID) *ExchangeRateUpdateOne {
   598  	eruo.mutation.SetCoinTypeID(u)
   599  	return eruo
   600  }
   601  
   602  // SetNillableCoinTypeID sets the "coin_type_id" field if the given value is not nil.
   603  func (eruo *ExchangeRateUpdateOne) SetNillableCoinTypeID(u *uuid.UUID) *ExchangeRateUpdateOne {
   604  	if u != nil {
   605  		eruo.SetCoinTypeID(*u)
   606  	}
   607  	return eruo
   608  }
   609  
   610  // ClearCoinTypeID clears the value of the "coin_type_id" field.
   611  func (eruo *ExchangeRateUpdateOne) ClearCoinTypeID() *ExchangeRateUpdateOne {
   612  	eruo.mutation.ClearCoinTypeID()
   613  	return eruo
   614  }
   615  
   616  // SetMarketValue sets the "market_value" field.
   617  func (eruo *ExchangeRateUpdateOne) SetMarketValue(d decimal.Decimal) *ExchangeRateUpdateOne {
   618  	eruo.mutation.SetMarketValue(d)
   619  	return eruo
   620  }
   621  
   622  // SetNillableMarketValue sets the "market_value" field if the given value is not nil.
   623  func (eruo *ExchangeRateUpdateOne) SetNillableMarketValue(d *decimal.Decimal) *ExchangeRateUpdateOne {
   624  	if d != nil {
   625  		eruo.SetMarketValue(*d)
   626  	}
   627  	return eruo
   628  }
   629  
   630  // ClearMarketValue clears the value of the "market_value" field.
   631  func (eruo *ExchangeRateUpdateOne) ClearMarketValue() *ExchangeRateUpdateOne {
   632  	eruo.mutation.ClearMarketValue()
   633  	return eruo
   634  }
   635  
   636  // SetSettleValue sets the "settle_value" field.
   637  func (eruo *ExchangeRateUpdateOne) SetSettleValue(d decimal.Decimal) *ExchangeRateUpdateOne {
   638  	eruo.mutation.SetSettleValue(d)
   639  	return eruo
   640  }
   641  
   642  // SetNillableSettleValue sets the "settle_value" field if the given value is not nil.
   643  func (eruo *ExchangeRateUpdateOne) SetNillableSettleValue(d *decimal.Decimal) *ExchangeRateUpdateOne {
   644  	if d != nil {
   645  		eruo.SetSettleValue(*d)
   646  	}
   647  	return eruo
   648  }
   649  
   650  // ClearSettleValue clears the value of the "settle_value" field.
   651  func (eruo *ExchangeRateUpdateOne) ClearSettleValue() *ExchangeRateUpdateOne {
   652  	eruo.mutation.ClearSettleValue()
   653  	return eruo
   654  }
   655  
   656  // SetSettlePercent sets the "settle_percent" field.
   657  func (eruo *ExchangeRateUpdateOne) SetSettlePercent(u uint32) *ExchangeRateUpdateOne {
   658  	eruo.mutation.ResetSettlePercent()
   659  	eruo.mutation.SetSettlePercent(u)
   660  	return eruo
   661  }
   662  
   663  // SetNillableSettlePercent sets the "settle_percent" field if the given value is not nil.
   664  func (eruo *ExchangeRateUpdateOne) SetNillableSettlePercent(u *uint32) *ExchangeRateUpdateOne {
   665  	if u != nil {
   666  		eruo.SetSettlePercent(*u)
   667  	}
   668  	return eruo
   669  }
   670  
   671  // AddSettlePercent adds u to the "settle_percent" field.
   672  func (eruo *ExchangeRateUpdateOne) AddSettlePercent(u int32) *ExchangeRateUpdateOne {
   673  	eruo.mutation.AddSettlePercent(u)
   674  	return eruo
   675  }
   676  
   677  // ClearSettlePercent clears the value of the "settle_percent" field.
   678  func (eruo *ExchangeRateUpdateOne) ClearSettlePercent() *ExchangeRateUpdateOne {
   679  	eruo.mutation.ClearSettlePercent()
   680  	return eruo
   681  }
   682  
   683  // SetSettleTips sets the "settle_tips" field.
   684  func (eruo *ExchangeRateUpdateOne) SetSettleTips(s []string) *ExchangeRateUpdateOne {
   685  	eruo.mutation.SetSettleTips(s)
   686  	return eruo
   687  }
   688  
   689  // ClearSettleTips clears the value of the "settle_tips" field.
   690  func (eruo *ExchangeRateUpdateOne) ClearSettleTips() *ExchangeRateUpdateOne {
   691  	eruo.mutation.ClearSettleTips()
   692  	return eruo
   693  }
   694  
   695  // SetSetter sets the "setter" field.
   696  func (eruo *ExchangeRateUpdateOne) SetSetter(u uuid.UUID) *ExchangeRateUpdateOne {
   697  	eruo.mutation.SetSetter(u)
   698  	return eruo
   699  }
   700  
   701  // SetNillableSetter sets the "setter" field if the given value is not nil.
   702  func (eruo *ExchangeRateUpdateOne) SetNillableSetter(u *uuid.UUID) *ExchangeRateUpdateOne {
   703  	if u != nil {
   704  		eruo.SetSetter(*u)
   705  	}
   706  	return eruo
   707  }
   708  
   709  // ClearSetter clears the value of the "setter" field.
   710  func (eruo *ExchangeRateUpdateOne) ClearSetter() *ExchangeRateUpdateOne {
   711  	eruo.mutation.ClearSetter()
   712  	return eruo
   713  }
   714  
   715  // Mutation returns the ExchangeRateMutation object of the builder.
   716  func (eruo *ExchangeRateUpdateOne) Mutation() *ExchangeRateMutation {
   717  	return eruo.mutation
   718  }
   719  
   720  // Select allows selecting one or more fields (columns) of the returned entity.
   721  // The default is selecting all fields defined in the entity schema.
   722  func (eruo *ExchangeRateUpdateOne) Select(field string, fields ...string) *ExchangeRateUpdateOne {
   723  	eruo.fields = append([]string{field}, fields...)
   724  	return eruo
   725  }
   726  
   727  // Save executes the query and returns the updated ExchangeRate entity.
   728  func (eruo *ExchangeRateUpdateOne) Save(ctx context.Context) (*ExchangeRate, error) {
   729  	var (
   730  		err  error
   731  		node *ExchangeRate
   732  	)
   733  	if err := eruo.defaults(); err != nil {
   734  		return nil, err
   735  	}
   736  	if len(eruo.hooks) == 0 {
   737  		node, err = eruo.sqlSave(ctx)
   738  	} else {
   739  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   740  			mutation, ok := m.(*ExchangeRateMutation)
   741  			if !ok {
   742  				return nil, fmt.Errorf("unexpected mutation type %T", m)
   743  			}
   744  			eruo.mutation = mutation
   745  			node, err = eruo.sqlSave(ctx)
   746  			mutation.done = true
   747  			return node, err
   748  		})
   749  		for i := len(eruo.hooks) - 1; i >= 0; i-- {
   750  			if eruo.hooks[i] == nil {
   751  				return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
   752  			}
   753  			mut = eruo.hooks[i](mut)
   754  		}
   755  		v, err := mut.Mutate(ctx, eruo.mutation)
   756  		if err != nil {
   757  			return nil, err
   758  		}
   759  		nv, ok := v.(*ExchangeRate)
   760  		if !ok {
   761  			return nil, fmt.Errorf("unexpected node type %T returned from ExchangeRateMutation", v)
   762  		}
   763  		node = nv
   764  	}
   765  	return node, err
   766  }
   767  
   768  // SaveX is like Save, but panics if an error occurs.
   769  func (eruo *ExchangeRateUpdateOne) SaveX(ctx context.Context) *ExchangeRate {
   770  	node, err := eruo.Save(ctx)
   771  	if err != nil {
   772  		panic(err)
   773  	}
   774  	return node
   775  }
   776  
   777  // Exec executes the query on the entity.
   778  func (eruo *ExchangeRateUpdateOne) Exec(ctx context.Context) error {
   779  	_, err := eruo.Save(ctx)
   780  	return err
   781  }
   782  
   783  // ExecX is like Exec, but panics if an error occurs.
   784  func (eruo *ExchangeRateUpdateOne) ExecX(ctx context.Context) {
   785  	if err := eruo.Exec(ctx); err != nil {
   786  		panic(err)
   787  	}
   788  }
   789  
   790  // defaults sets the default values of the builder before save.
   791  func (eruo *ExchangeRateUpdateOne) defaults() error {
   792  	if _, ok := eruo.mutation.UpdatedAt(); !ok {
   793  		if exchangerate.UpdateDefaultUpdatedAt == nil {
   794  			return fmt.Errorf("ent: uninitialized exchangerate.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
   795  		}
   796  		v := exchangerate.UpdateDefaultUpdatedAt()
   797  		eruo.mutation.SetUpdatedAt(v)
   798  	}
   799  	return nil
   800  }
   801  
   802  // Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
   803  func (eruo *ExchangeRateUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ExchangeRateUpdateOne {
   804  	eruo.modifiers = append(eruo.modifiers, modifiers...)
   805  	return eruo
   806  }
   807  
   808  func (eruo *ExchangeRateUpdateOne) sqlSave(ctx context.Context) (_node *ExchangeRate, err error) {
   809  	_spec := &sqlgraph.UpdateSpec{
   810  		Node: &sqlgraph.NodeSpec{
   811  			Table:   exchangerate.Table,
   812  			Columns: exchangerate.Columns,
   813  			ID: &sqlgraph.FieldSpec{
   814  				Type:   field.TypeUint32,
   815  				Column: exchangerate.FieldID,
   816  			},
   817  		},
   818  	}
   819  	id, ok := eruo.mutation.ID()
   820  	if !ok {
   821  		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ExchangeRate.id" for update`)}
   822  	}
   823  	_spec.Node.ID.Value = id
   824  	if fields := eruo.fields; len(fields) > 0 {
   825  		_spec.Node.Columns = make([]string, 0, len(fields))
   826  		_spec.Node.Columns = append(_spec.Node.Columns, exchangerate.FieldID)
   827  		for _, f := range fields {
   828  			if !exchangerate.ValidColumn(f) {
   829  				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
   830  			}
   831  			if f != exchangerate.FieldID {
   832  				_spec.Node.Columns = append(_spec.Node.Columns, f)
   833  			}
   834  		}
   835  	}
   836  	if ps := eruo.mutation.predicates; len(ps) > 0 {
   837  		_spec.Predicate = func(selector *sql.Selector) {
   838  			for i := range ps {
   839  				ps[i](selector)
   840  			}
   841  		}
   842  	}
   843  	if value, ok := eruo.mutation.CreatedAt(); ok {
   844  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   845  			Type:   field.TypeUint32,
   846  			Value:  value,
   847  			Column: exchangerate.FieldCreatedAt,
   848  		})
   849  	}
   850  	if value, ok := eruo.mutation.AddedCreatedAt(); ok {
   851  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   852  			Type:   field.TypeUint32,
   853  			Value:  value,
   854  			Column: exchangerate.FieldCreatedAt,
   855  		})
   856  	}
   857  	if value, ok := eruo.mutation.UpdatedAt(); ok {
   858  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   859  			Type:   field.TypeUint32,
   860  			Value:  value,
   861  			Column: exchangerate.FieldUpdatedAt,
   862  		})
   863  	}
   864  	if value, ok := eruo.mutation.AddedUpdatedAt(); ok {
   865  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   866  			Type:   field.TypeUint32,
   867  			Value:  value,
   868  			Column: exchangerate.FieldUpdatedAt,
   869  		})
   870  	}
   871  	if value, ok := eruo.mutation.DeletedAt(); ok {
   872  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   873  			Type:   field.TypeUint32,
   874  			Value:  value,
   875  			Column: exchangerate.FieldDeletedAt,
   876  		})
   877  	}
   878  	if value, ok := eruo.mutation.AddedDeletedAt(); ok {
   879  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   880  			Type:   field.TypeUint32,
   881  			Value:  value,
   882  			Column: exchangerate.FieldDeletedAt,
   883  		})
   884  	}
   885  	if value, ok := eruo.mutation.EntID(); ok {
   886  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   887  			Type:   field.TypeUUID,
   888  			Value:  value,
   889  			Column: exchangerate.FieldEntID,
   890  		})
   891  	}
   892  	if value, ok := eruo.mutation.AppID(); ok {
   893  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   894  			Type:   field.TypeUUID,
   895  			Value:  value,
   896  			Column: exchangerate.FieldAppID,
   897  		})
   898  	}
   899  	if eruo.mutation.AppIDCleared() {
   900  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   901  			Type:   field.TypeUUID,
   902  			Column: exchangerate.FieldAppID,
   903  		})
   904  	}
   905  	if value, ok := eruo.mutation.CoinTypeID(); ok {
   906  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   907  			Type:   field.TypeUUID,
   908  			Value:  value,
   909  			Column: exchangerate.FieldCoinTypeID,
   910  		})
   911  	}
   912  	if eruo.mutation.CoinTypeIDCleared() {
   913  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   914  			Type:   field.TypeUUID,
   915  			Column: exchangerate.FieldCoinTypeID,
   916  		})
   917  	}
   918  	if value, ok := eruo.mutation.MarketValue(); ok {
   919  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   920  			Type:   field.TypeOther,
   921  			Value:  value,
   922  			Column: exchangerate.FieldMarketValue,
   923  		})
   924  	}
   925  	if eruo.mutation.MarketValueCleared() {
   926  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   927  			Type:   field.TypeOther,
   928  			Column: exchangerate.FieldMarketValue,
   929  		})
   930  	}
   931  	if value, ok := eruo.mutation.SettleValue(); ok {
   932  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   933  			Type:   field.TypeOther,
   934  			Value:  value,
   935  			Column: exchangerate.FieldSettleValue,
   936  		})
   937  	}
   938  	if eruo.mutation.SettleValueCleared() {
   939  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   940  			Type:   field.TypeOther,
   941  			Column: exchangerate.FieldSettleValue,
   942  		})
   943  	}
   944  	if value, ok := eruo.mutation.SettlePercent(); ok {
   945  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   946  			Type:   field.TypeUint32,
   947  			Value:  value,
   948  			Column: exchangerate.FieldSettlePercent,
   949  		})
   950  	}
   951  	if value, ok := eruo.mutation.AddedSettlePercent(); ok {
   952  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   953  			Type:   field.TypeUint32,
   954  			Value:  value,
   955  			Column: exchangerate.FieldSettlePercent,
   956  		})
   957  	}
   958  	if eruo.mutation.SettlePercentCleared() {
   959  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   960  			Type:   field.TypeUint32,
   961  			Column: exchangerate.FieldSettlePercent,
   962  		})
   963  	}
   964  	if value, ok := eruo.mutation.SettleTips(); ok {
   965  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   966  			Type:   field.TypeJSON,
   967  			Value:  value,
   968  			Column: exchangerate.FieldSettleTips,
   969  		})
   970  	}
   971  	if eruo.mutation.SettleTipsCleared() {
   972  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   973  			Type:   field.TypeJSON,
   974  			Column: exchangerate.FieldSettleTips,
   975  		})
   976  	}
   977  	if value, ok := eruo.mutation.Setter(); ok {
   978  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   979  			Type:   field.TypeUUID,
   980  			Value:  value,
   981  			Column: exchangerate.FieldSetter,
   982  		})
   983  	}
   984  	if eruo.mutation.SetterCleared() {
   985  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   986  			Type:   field.TypeUUID,
   987  			Column: exchangerate.FieldSetter,
   988  		})
   989  	}
   990  	_spec.Modifiers = eruo.modifiers
   991  	_node = &ExchangeRate{config: eruo.config}
   992  	_spec.Assign = _node.assignValues
   993  	_spec.ScanValues = _node.scanValues
   994  	if err = sqlgraph.UpdateNode(ctx, eruo.driver, _spec); err != nil {
   995  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   996  			err = &NotFoundError{exchangerate.Label}
   997  		} else if sqlgraph.IsConstraintError(err) {
   998  			err = &ConstraintError{msg: err.Error(), wrap: err}
   999  		}
  1000  		return nil, err
  1001  	}
  1002  	return _node, nil
  1003  }