github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/currencyhistory_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/currencyhistory"
    14  	"github.com/NpoolPlatform/chain-middleware/pkg/db/ent/predicate"
    15  	"github.com/google/uuid"
    16  	"github.com/shopspring/decimal"
    17  )
    18  
    19  // CurrencyHistoryUpdate is the builder for updating CurrencyHistory entities.
    20  type CurrencyHistoryUpdate struct {
    21  	config
    22  	hooks     []Hook
    23  	mutation  *CurrencyHistoryMutation
    24  	modifiers []func(*sql.UpdateBuilder)
    25  }
    26  
    27  // Where appends a list predicates to the CurrencyHistoryUpdate builder.
    28  func (chu *CurrencyHistoryUpdate) Where(ps ...predicate.CurrencyHistory) *CurrencyHistoryUpdate {
    29  	chu.mutation.Where(ps...)
    30  	return chu
    31  }
    32  
    33  // SetCreatedAt sets the "created_at" field.
    34  func (chu *CurrencyHistoryUpdate) SetCreatedAt(u uint32) *CurrencyHistoryUpdate {
    35  	chu.mutation.ResetCreatedAt()
    36  	chu.mutation.SetCreatedAt(u)
    37  	return chu
    38  }
    39  
    40  // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
    41  func (chu *CurrencyHistoryUpdate) SetNillableCreatedAt(u *uint32) *CurrencyHistoryUpdate {
    42  	if u != nil {
    43  		chu.SetCreatedAt(*u)
    44  	}
    45  	return chu
    46  }
    47  
    48  // AddCreatedAt adds u to the "created_at" field.
    49  func (chu *CurrencyHistoryUpdate) AddCreatedAt(u int32) *CurrencyHistoryUpdate {
    50  	chu.mutation.AddCreatedAt(u)
    51  	return chu
    52  }
    53  
    54  // SetUpdatedAt sets the "updated_at" field.
    55  func (chu *CurrencyHistoryUpdate) SetUpdatedAt(u uint32) *CurrencyHistoryUpdate {
    56  	chu.mutation.ResetUpdatedAt()
    57  	chu.mutation.SetUpdatedAt(u)
    58  	return chu
    59  }
    60  
    61  // AddUpdatedAt adds u to the "updated_at" field.
    62  func (chu *CurrencyHistoryUpdate) AddUpdatedAt(u int32) *CurrencyHistoryUpdate {
    63  	chu.mutation.AddUpdatedAt(u)
    64  	return chu
    65  }
    66  
    67  // SetDeletedAt sets the "deleted_at" field.
    68  func (chu *CurrencyHistoryUpdate) SetDeletedAt(u uint32) *CurrencyHistoryUpdate {
    69  	chu.mutation.ResetDeletedAt()
    70  	chu.mutation.SetDeletedAt(u)
    71  	return chu
    72  }
    73  
    74  // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
    75  func (chu *CurrencyHistoryUpdate) SetNillableDeletedAt(u *uint32) *CurrencyHistoryUpdate {
    76  	if u != nil {
    77  		chu.SetDeletedAt(*u)
    78  	}
    79  	return chu
    80  }
    81  
    82  // AddDeletedAt adds u to the "deleted_at" field.
    83  func (chu *CurrencyHistoryUpdate) AddDeletedAt(u int32) *CurrencyHistoryUpdate {
    84  	chu.mutation.AddDeletedAt(u)
    85  	return chu
    86  }
    87  
    88  // SetEntID sets the "ent_id" field.
    89  func (chu *CurrencyHistoryUpdate) SetEntID(u uuid.UUID) *CurrencyHistoryUpdate {
    90  	chu.mutation.SetEntID(u)
    91  	return chu
    92  }
    93  
    94  // SetNillableEntID sets the "ent_id" field if the given value is not nil.
    95  func (chu *CurrencyHistoryUpdate) SetNillableEntID(u *uuid.UUID) *CurrencyHistoryUpdate {
    96  	if u != nil {
    97  		chu.SetEntID(*u)
    98  	}
    99  	return chu
   100  }
   101  
   102  // SetCoinTypeID sets the "coin_type_id" field.
   103  func (chu *CurrencyHistoryUpdate) SetCoinTypeID(u uuid.UUID) *CurrencyHistoryUpdate {
   104  	chu.mutation.SetCoinTypeID(u)
   105  	return chu
   106  }
   107  
   108  // SetNillableCoinTypeID sets the "coin_type_id" field if the given value is not nil.
   109  func (chu *CurrencyHistoryUpdate) SetNillableCoinTypeID(u *uuid.UUID) *CurrencyHistoryUpdate {
   110  	if u != nil {
   111  		chu.SetCoinTypeID(*u)
   112  	}
   113  	return chu
   114  }
   115  
   116  // ClearCoinTypeID clears the value of the "coin_type_id" field.
   117  func (chu *CurrencyHistoryUpdate) ClearCoinTypeID() *CurrencyHistoryUpdate {
   118  	chu.mutation.ClearCoinTypeID()
   119  	return chu
   120  }
   121  
   122  // SetFeedType sets the "feed_type" field.
   123  func (chu *CurrencyHistoryUpdate) SetFeedType(s string) *CurrencyHistoryUpdate {
   124  	chu.mutation.SetFeedType(s)
   125  	return chu
   126  }
   127  
   128  // SetNillableFeedType sets the "feed_type" field if the given value is not nil.
   129  func (chu *CurrencyHistoryUpdate) SetNillableFeedType(s *string) *CurrencyHistoryUpdate {
   130  	if s != nil {
   131  		chu.SetFeedType(*s)
   132  	}
   133  	return chu
   134  }
   135  
   136  // ClearFeedType clears the value of the "feed_type" field.
   137  func (chu *CurrencyHistoryUpdate) ClearFeedType() *CurrencyHistoryUpdate {
   138  	chu.mutation.ClearFeedType()
   139  	return chu
   140  }
   141  
   142  // SetMarketValueHigh sets the "market_value_high" field.
   143  func (chu *CurrencyHistoryUpdate) SetMarketValueHigh(d decimal.Decimal) *CurrencyHistoryUpdate {
   144  	chu.mutation.SetMarketValueHigh(d)
   145  	return chu
   146  }
   147  
   148  // SetNillableMarketValueHigh sets the "market_value_high" field if the given value is not nil.
   149  func (chu *CurrencyHistoryUpdate) SetNillableMarketValueHigh(d *decimal.Decimal) *CurrencyHistoryUpdate {
   150  	if d != nil {
   151  		chu.SetMarketValueHigh(*d)
   152  	}
   153  	return chu
   154  }
   155  
   156  // ClearMarketValueHigh clears the value of the "market_value_high" field.
   157  func (chu *CurrencyHistoryUpdate) ClearMarketValueHigh() *CurrencyHistoryUpdate {
   158  	chu.mutation.ClearMarketValueHigh()
   159  	return chu
   160  }
   161  
   162  // SetMarketValueLow sets the "market_value_low" field.
   163  func (chu *CurrencyHistoryUpdate) SetMarketValueLow(d decimal.Decimal) *CurrencyHistoryUpdate {
   164  	chu.mutation.SetMarketValueLow(d)
   165  	return chu
   166  }
   167  
   168  // SetNillableMarketValueLow sets the "market_value_low" field if the given value is not nil.
   169  func (chu *CurrencyHistoryUpdate) SetNillableMarketValueLow(d *decimal.Decimal) *CurrencyHistoryUpdate {
   170  	if d != nil {
   171  		chu.SetMarketValueLow(*d)
   172  	}
   173  	return chu
   174  }
   175  
   176  // ClearMarketValueLow clears the value of the "market_value_low" field.
   177  func (chu *CurrencyHistoryUpdate) ClearMarketValueLow() *CurrencyHistoryUpdate {
   178  	chu.mutation.ClearMarketValueLow()
   179  	return chu
   180  }
   181  
   182  // Mutation returns the CurrencyHistoryMutation object of the builder.
   183  func (chu *CurrencyHistoryUpdate) Mutation() *CurrencyHistoryMutation {
   184  	return chu.mutation
   185  }
   186  
   187  // Save executes the query and returns the number of nodes affected by the update operation.
   188  func (chu *CurrencyHistoryUpdate) Save(ctx context.Context) (int, error) {
   189  	var (
   190  		err      error
   191  		affected int
   192  	)
   193  	if err := chu.defaults(); err != nil {
   194  		return 0, err
   195  	}
   196  	if len(chu.hooks) == 0 {
   197  		affected, err = chu.sqlSave(ctx)
   198  	} else {
   199  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   200  			mutation, ok := m.(*CurrencyHistoryMutation)
   201  			if !ok {
   202  				return nil, fmt.Errorf("unexpected mutation type %T", m)
   203  			}
   204  			chu.mutation = mutation
   205  			affected, err = chu.sqlSave(ctx)
   206  			mutation.done = true
   207  			return affected, err
   208  		})
   209  		for i := len(chu.hooks) - 1; i >= 0; i-- {
   210  			if chu.hooks[i] == nil {
   211  				return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
   212  			}
   213  			mut = chu.hooks[i](mut)
   214  		}
   215  		if _, err := mut.Mutate(ctx, chu.mutation); err != nil {
   216  			return 0, err
   217  		}
   218  	}
   219  	return affected, err
   220  }
   221  
   222  // SaveX is like Save, but panics if an error occurs.
   223  func (chu *CurrencyHistoryUpdate) SaveX(ctx context.Context) int {
   224  	affected, err := chu.Save(ctx)
   225  	if err != nil {
   226  		panic(err)
   227  	}
   228  	return affected
   229  }
   230  
   231  // Exec executes the query.
   232  func (chu *CurrencyHistoryUpdate) Exec(ctx context.Context) error {
   233  	_, err := chu.Save(ctx)
   234  	return err
   235  }
   236  
   237  // ExecX is like Exec, but panics if an error occurs.
   238  func (chu *CurrencyHistoryUpdate) ExecX(ctx context.Context) {
   239  	if err := chu.Exec(ctx); err != nil {
   240  		panic(err)
   241  	}
   242  }
   243  
   244  // defaults sets the default values of the builder before save.
   245  func (chu *CurrencyHistoryUpdate) defaults() error {
   246  	if _, ok := chu.mutation.UpdatedAt(); !ok {
   247  		if currencyhistory.UpdateDefaultUpdatedAt == nil {
   248  			return fmt.Errorf("ent: uninitialized currencyhistory.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
   249  		}
   250  		v := currencyhistory.UpdateDefaultUpdatedAt()
   251  		chu.mutation.SetUpdatedAt(v)
   252  	}
   253  	return nil
   254  }
   255  
   256  // Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
   257  func (chu *CurrencyHistoryUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CurrencyHistoryUpdate {
   258  	chu.modifiers = append(chu.modifiers, modifiers...)
   259  	return chu
   260  }
   261  
   262  func (chu *CurrencyHistoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
   263  	_spec := &sqlgraph.UpdateSpec{
   264  		Node: &sqlgraph.NodeSpec{
   265  			Table:   currencyhistory.Table,
   266  			Columns: currencyhistory.Columns,
   267  			ID: &sqlgraph.FieldSpec{
   268  				Type:   field.TypeUint32,
   269  				Column: currencyhistory.FieldID,
   270  			},
   271  		},
   272  	}
   273  	if ps := chu.mutation.predicates; len(ps) > 0 {
   274  		_spec.Predicate = func(selector *sql.Selector) {
   275  			for i := range ps {
   276  				ps[i](selector)
   277  			}
   278  		}
   279  	}
   280  	if value, ok := chu.mutation.CreatedAt(); ok {
   281  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   282  			Type:   field.TypeUint32,
   283  			Value:  value,
   284  			Column: currencyhistory.FieldCreatedAt,
   285  		})
   286  	}
   287  	if value, ok := chu.mutation.AddedCreatedAt(); ok {
   288  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   289  			Type:   field.TypeUint32,
   290  			Value:  value,
   291  			Column: currencyhistory.FieldCreatedAt,
   292  		})
   293  	}
   294  	if value, ok := chu.mutation.UpdatedAt(); ok {
   295  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   296  			Type:   field.TypeUint32,
   297  			Value:  value,
   298  			Column: currencyhistory.FieldUpdatedAt,
   299  		})
   300  	}
   301  	if value, ok := chu.mutation.AddedUpdatedAt(); ok {
   302  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   303  			Type:   field.TypeUint32,
   304  			Value:  value,
   305  			Column: currencyhistory.FieldUpdatedAt,
   306  		})
   307  	}
   308  	if value, ok := chu.mutation.DeletedAt(); ok {
   309  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   310  			Type:   field.TypeUint32,
   311  			Value:  value,
   312  			Column: currencyhistory.FieldDeletedAt,
   313  		})
   314  	}
   315  	if value, ok := chu.mutation.AddedDeletedAt(); ok {
   316  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   317  			Type:   field.TypeUint32,
   318  			Value:  value,
   319  			Column: currencyhistory.FieldDeletedAt,
   320  		})
   321  	}
   322  	if value, ok := chu.mutation.EntID(); ok {
   323  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   324  			Type:   field.TypeUUID,
   325  			Value:  value,
   326  			Column: currencyhistory.FieldEntID,
   327  		})
   328  	}
   329  	if value, ok := chu.mutation.CoinTypeID(); ok {
   330  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   331  			Type:   field.TypeUUID,
   332  			Value:  value,
   333  			Column: currencyhistory.FieldCoinTypeID,
   334  		})
   335  	}
   336  	if chu.mutation.CoinTypeIDCleared() {
   337  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   338  			Type:   field.TypeUUID,
   339  			Column: currencyhistory.FieldCoinTypeID,
   340  		})
   341  	}
   342  	if value, ok := chu.mutation.FeedType(); ok {
   343  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   344  			Type:   field.TypeString,
   345  			Value:  value,
   346  			Column: currencyhistory.FieldFeedType,
   347  		})
   348  	}
   349  	if chu.mutation.FeedTypeCleared() {
   350  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   351  			Type:   field.TypeString,
   352  			Column: currencyhistory.FieldFeedType,
   353  		})
   354  	}
   355  	if value, ok := chu.mutation.MarketValueHigh(); ok {
   356  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   357  			Type:   field.TypeOther,
   358  			Value:  value,
   359  			Column: currencyhistory.FieldMarketValueHigh,
   360  		})
   361  	}
   362  	if chu.mutation.MarketValueHighCleared() {
   363  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   364  			Type:   field.TypeOther,
   365  			Column: currencyhistory.FieldMarketValueHigh,
   366  		})
   367  	}
   368  	if value, ok := chu.mutation.MarketValueLow(); ok {
   369  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   370  			Type:   field.TypeOther,
   371  			Value:  value,
   372  			Column: currencyhistory.FieldMarketValueLow,
   373  		})
   374  	}
   375  	if chu.mutation.MarketValueLowCleared() {
   376  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   377  			Type:   field.TypeOther,
   378  			Column: currencyhistory.FieldMarketValueLow,
   379  		})
   380  	}
   381  	_spec.Modifiers = chu.modifiers
   382  	if n, err = sqlgraph.UpdateNodes(ctx, chu.driver, _spec); err != nil {
   383  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   384  			err = &NotFoundError{currencyhistory.Label}
   385  		} else if sqlgraph.IsConstraintError(err) {
   386  			err = &ConstraintError{msg: err.Error(), wrap: err}
   387  		}
   388  		return 0, err
   389  	}
   390  	return n, nil
   391  }
   392  
   393  // CurrencyHistoryUpdateOne is the builder for updating a single CurrencyHistory entity.
   394  type CurrencyHistoryUpdateOne struct {
   395  	config
   396  	fields    []string
   397  	hooks     []Hook
   398  	mutation  *CurrencyHistoryMutation
   399  	modifiers []func(*sql.UpdateBuilder)
   400  }
   401  
   402  // SetCreatedAt sets the "created_at" field.
   403  func (chuo *CurrencyHistoryUpdateOne) SetCreatedAt(u uint32) *CurrencyHistoryUpdateOne {
   404  	chuo.mutation.ResetCreatedAt()
   405  	chuo.mutation.SetCreatedAt(u)
   406  	return chuo
   407  }
   408  
   409  // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
   410  func (chuo *CurrencyHistoryUpdateOne) SetNillableCreatedAt(u *uint32) *CurrencyHistoryUpdateOne {
   411  	if u != nil {
   412  		chuo.SetCreatedAt(*u)
   413  	}
   414  	return chuo
   415  }
   416  
   417  // AddCreatedAt adds u to the "created_at" field.
   418  func (chuo *CurrencyHistoryUpdateOne) AddCreatedAt(u int32) *CurrencyHistoryUpdateOne {
   419  	chuo.mutation.AddCreatedAt(u)
   420  	return chuo
   421  }
   422  
   423  // SetUpdatedAt sets the "updated_at" field.
   424  func (chuo *CurrencyHistoryUpdateOne) SetUpdatedAt(u uint32) *CurrencyHistoryUpdateOne {
   425  	chuo.mutation.ResetUpdatedAt()
   426  	chuo.mutation.SetUpdatedAt(u)
   427  	return chuo
   428  }
   429  
   430  // AddUpdatedAt adds u to the "updated_at" field.
   431  func (chuo *CurrencyHistoryUpdateOne) AddUpdatedAt(u int32) *CurrencyHistoryUpdateOne {
   432  	chuo.mutation.AddUpdatedAt(u)
   433  	return chuo
   434  }
   435  
   436  // SetDeletedAt sets the "deleted_at" field.
   437  func (chuo *CurrencyHistoryUpdateOne) SetDeletedAt(u uint32) *CurrencyHistoryUpdateOne {
   438  	chuo.mutation.ResetDeletedAt()
   439  	chuo.mutation.SetDeletedAt(u)
   440  	return chuo
   441  }
   442  
   443  // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
   444  func (chuo *CurrencyHistoryUpdateOne) SetNillableDeletedAt(u *uint32) *CurrencyHistoryUpdateOne {
   445  	if u != nil {
   446  		chuo.SetDeletedAt(*u)
   447  	}
   448  	return chuo
   449  }
   450  
   451  // AddDeletedAt adds u to the "deleted_at" field.
   452  func (chuo *CurrencyHistoryUpdateOne) AddDeletedAt(u int32) *CurrencyHistoryUpdateOne {
   453  	chuo.mutation.AddDeletedAt(u)
   454  	return chuo
   455  }
   456  
   457  // SetEntID sets the "ent_id" field.
   458  func (chuo *CurrencyHistoryUpdateOne) SetEntID(u uuid.UUID) *CurrencyHistoryUpdateOne {
   459  	chuo.mutation.SetEntID(u)
   460  	return chuo
   461  }
   462  
   463  // SetNillableEntID sets the "ent_id" field if the given value is not nil.
   464  func (chuo *CurrencyHistoryUpdateOne) SetNillableEntID(u *uuid.UUID) *CurrencyHistoryUpdateOne {
   465  	if u != nil {
   466  		chuo.SetEntID(*u)
   467  	}
   468  	return chuo
   469  }
   470  
   471  // SetCoinTypeID sets the "coin_type_id" field.
   472  func (chuo *CurrencyHistoryUpdateOne) SetCoinTypeID(u uuid.UUID) *CurrencyHistoryUpdateOne {
   473  	chuo.mutation.SetCoinTypeID(u)
   474  	return chuo
   475  }
   476  
   477  // SetNillableCoinTypeID sets the "coin_type_id" field if the given value is not nil.
   478  func (chuo *CurrencyHistoryUpdateOne) SetNillableCoinTypeID(u *uuid.UUID) *CurrencyHistoryUpdateOne {
   479  	if u != nil {
   480  		chuo.SetCoinTypeID(*u)
   481  	}
   482  	return chuo
   483  }
   484  
   485  // ClearCoinTypeID clears the value of the "coin_type_id" field.
   486  func (chuo *CurrencyHistoryUpdateOne) ClearCoinTypeID() *CurrencyHistoryUpdateOne {
   487  	chuo.mutation.ClearCoinTypeID()
   488  	return chuo
   489  }
   490  
   491  // SetFeedType sets the "feed_type" field.
   492  func (chuo *CurrencyHistoryUpdateOne) SetFeedType(s string) *CurrencyHistoryUpdateOne {
   493  	chuo.mutation.SetFeedType(s)
   494  	return chuo
   495  }
   496  
   497  // SetNillableFeedType sets the "feed_type" field if the given value is not nil.
   498  func (chuo *CurrencyHistoryUpdateOne) SetNillableFeedType(s *string) *CurrencyHistoryUpdateOne {
   499  	if s != nil {
   500  		chuo.SetFeedType(*s)
   501  	}
   502  	return chuo
   503  }
   504  
   505  // ClearFeedType clears the value of the "feed_type" field.
   506  func (chuo *CurrencyHistoryUpdateOne) ClearFeedType() *CurrencyHistoryUpdateOne {
   507  	chuo.mutation.ClearFeedType()
   508  	return chuo
   509  }
   510  
   511  // SetMarketValueHigh sets the "market_value_high" field.
   512  func (chuo *CurrencyHistoryUpdateOne) SetMarketValueHigh(d decimal.Decimal) *CurrencyHistoryUpdateOne {
   513  	chuo.mutation.SetMarketValueHigh(d)
   514  	return chuo
   515  }
   516  
   517  // SetNillableMarketValueHigh sets the "market_value_high" field if the given value is not nil.
   518  func (chuo *CurrencyHistoryUpdateOne) SetNillableMarketValueHigh(d *decimal.Decimal) *CurrencyHistoryUpdateOne {
   519  	if d != nil {
   520  		chuo.SetMarketValueHigh(*d)
   521  	}
   522  	return chuo
   523  }
   524  
   525  // ClearMarketValueHigh clears the value of the "market_value_high" field.
   526  func (chuo *CurrencyHistoryUpdateOne) ClearMarketValueHigh() *CurrencyHistoryUpdateOne {
   527  	chuo.mutation.ClearMarketValueHigh()
   528  	return chuo
   529  }
   530  
   531  // SetMarketValueLow sets the "market_value_low" field.
   532  func (chuo *CurrencyHistoryUpdateOne) SetMarketValueLow(d decimal.Decimal) *CurrencyHistoryUpdateOne {
   533  	chuo.mutation.SetMarketValueLow(d)
   534  	return chuo
   535  }
   536  
   537  // SetNillableMarketValueLow sets the "market_value_low" field if the given value is not nil.
   538  func (chuo *CurrencyHistoryUpdateOne) SetNillableMarketValueLow(d *decimal.Decimal) *CurrencyHistoryUpdateOne {
   539  	if d != nil {
   540  		chuo.SetMarketValueLow(*d)
   541  	}
   542  	return chuo
   543  }
   544  
   545  // ClearMarketValueLow clears the value of the "market_value_low" field.
   546  func (chuo *CurrencyHistoryUpdateOne) ClearMarketValueLow() *CurrencyHistoryUpdateOne {
   547  	chuo.mutation.ClearMarketValueLow()
   548  	return chuo
   549  }
   550  
   551  // Mutation returns the CurrencyHistoryMutation object of the builder.
   552  func (chuo *CurrencyHistoryUpdateOne) Mutation() *CurrencyHistoryMutation {
   553  	return chuo.mutation
   554  }
   555  
   556  // Select allows selecting one or more fields (columns) of the returned entity.
   557  // The default is selecting all fields defined in the entity schema.
   558  func (chuo *CurrencyHistoryUpdateOne) Select(field string, fields ...string) *CurrencyHistoryUpdateOne {
   559  	chuo.fields = append([]string{field}, fields...)
   560  	return chuo
   561  }
   562  
   563  // Save executes the query and returns the updated CurrencyHistory entity.
   564  func (chuo *CurrencyHistoryUpdateOne) Save(ctx context.Context) (*CurrencyHistory, error) {
   565  	var (
   566  		err  error
   567  		node *CurrencyHistory
   568  	)
   569  	if err := chuo.defaults(); err != nil {
   570  		return nil, err
   571  	}
   572  	if len(chuo.hooks) == 0 {
   573  		node, err = chuo.sqlSave(ctx)
   574  	} else {
   575  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   576  			mutation, ok := m.(*CurrencyHistoryMutation)
   577  			if !ok {
   578  				return nil, fmt.Errorf("unexpected mutation type %T", m)
   579  			}
   580  			chuo.mutation = mutation
   581  			node, err = chuo.sqlSave(ctx)
   582  			mutation.done = true
   583  			return node, err
   584  		})
   585  		for i := len(chuo.hooks) - 1; i >= 0; i-- {
   586  			if chuo.hooks[i] == nil {
   587  				return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
   588  			}
   589  			mut = chuo.hooks[i](mut)
   590  		}
   591  		v, err := mut.Mutate(ctx, chuo.mutation)
   592  		if err != nil {
   593  			return nil, err
   594  		}
   595  		nv, ok := v.(*CurrencyHistory)
   596  		if !ok {
   597  			return nil, fmt.Errorf("unexpected node type %T returned from CurrencyHistoryMutation", v)
   598  		}
   599  		node = nv
   600  	}
   601  	return node, err
   602  }
   603  
   604  // SaveX is like Save, but panics if an error occurs.
   605  func (chuo *CurrencyHistoryUpdateOne) SaveX(ctx context.Context) *CurrencyHistory {
   606  	node, err := chuo.Save(ctx)
   607  	if err != nil {
   608  		panic(err)
   609  	}
   610  	return node
   611  }
   612  
   613  // Exec executes the query on the entity.
   614  func (chuo *CurrencyHistoryUpdateOne) Exec(ctx context.Context) error {
   615  	_, err := chuo.Save(ctx)
   616  	return err
   617  }
   618  
   619  // ExecX is like Exec, but panics if an error occurs.
   620  func (chuo *CurrencyHistoryUpdateOne) ExecX(ctx context.Context) {
   621  	if err := chuo.Exec(ctx); err != nil {
   622  		panic(err)
   623  	}
   624  }
   625  
   626  // defaults sets the default values of the builder before save.
   627  func (chuo *CurrencyHistoryUpdateOne) defaults() error {
   628  	if _, ok := chuo.mutation.UpdatedAt(); !ok {
   629  		if currencyhistory.UpdateDefaultUpdatedAt == nil {
   630  			return fmt.Errorf("ent: uninitialized currencyhistory.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
   631  		}
   632  		v := currencyhistory.UpdateDefaultUpdatedAt()
   633  		chuo.mutation.SetUpdatedAt(v)
   634  	}
   635  	return nil
   636  }
   637  
   638  // Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
   639  func (chuo *CurrencyHistoryUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CurrencyHistoryUpdateOne {
   640  	chuo.modifiers = append(chuo.modifiers, modifiers...)
   641  	return chuo
   642  }
   643  
   644  func (chuo *CurrencyHistoryUpdateOne) sqlSave(ctx context.Context) (_node *CurrencyHistory, err error) {
   645  	_spec := &sqlgraph.UpdateSpec{
   646  		Node: &sqlgraph.NodeSpec{
   647  			Table:   currencyhistory.Table,
   648  			Columns: currencyhistory.Columns,
   649  			ID: &sqlgraph.FieldSpec{
   650  				Type:   field.TypeUint32,
   651  				Column: currencyhistory.FieldID,
   652  			},
   653  		},
   654  	}
   655  	id, ok := chuo.mutation.ID()
   656  	if !ok {
   657  		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CurrencyHistory.id" for update`)}
   658  	}
   659  	_spec.Node.ID.Value = id
   660  	if fields := chuo.fields; len(fields) > 0 {
   661  		_spec.Node.Columns = make([]string, 0, len(fields))
   662  		_spec.Node.Columns = append(_spec.Node.Columns, currencyhistory.FieldID)
   663  		for _, f := range fields {
   664  			if !currencyhistory.ValidColumn(f) {
   665  				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
   666  			}
   667  			if f != currencyhistory.FieldID {
   668  				_spec.Node.Columns = append(_spec.Node.Columns, f)
   669  			}
   670  		}
   671  	}
   672  	if ps := chuo.mutation.predicates; len(ps) > 0 {
   673  		_spec.Predicate = func(selector *sql.Selector) {
   674  			for i := range ps {
   675  				ps[i](selector)
   676  			}
   677  		}
   678  	}
   679  	if value, ok := chuo.mutation.CreatedAt(); ok {
   680  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   681  			Type:   field.TypeUint32,
   682  			Value:  value,
   683  			Column: currencyhistory.FieldCreatedAt,
   684  		})
   685  	}
   686  	if value, ok := chuo.mutation.AddedCreatedAt(); ok {
   687  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   688  			Type:   field.TypeUint32,
   689  			Value:  value,
   690  			Column: currencyhistory.FieldCreatedAt,
   691  		})
   692  	}
   693  	if value, ok := chuo.mutation.UpdatedAt(); ok {
   694  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   695  			Type:   field.TypeUint32,
   696  			Value:  value,
   697  			Column: currencyhistory.FieldUpdatedAt,
   698  		})
   699  	}
   700  	if value, ok := chuo.mutation.AddedUpdatedAt(); ok {
   701  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   702  			Type:   field.TypeUint32,
   703  			Value:  value,
   704  			Column: currencyhistory.FieldUpdatedAt,
   705  		})
   706  	}
   707  	if value, ok := chuo.mutation.DeletedAt(); ok {
   708  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   709  			Type:   field.TypeUint32,
   710  			Value:  value,
   711  			Column: currencyhistory.FieldDeletedAt,
   712  		})
   713  	}
   714  	if value, ok := chuo.mutation.AddedDeletedAt(); ok {
   715  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   716  			Type:   field.TypeUint32,
   717  			Value:  value,
   718  			Column: currencyhistory.FieldDeletedAt,
   719  		})
   720  	}
   721  	if value, ok := chuo.mutation.EntID(); ok {
   722  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   723  			Type:   field.TypeUUID,
   724  			Value:  value,
   725  			Column: currencyhistory.FieldEntID,
   726  		})
   727  	}
   728  	if value, ok := chuo.mutation.CoinTypeID(); ok {
   729  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   730  			Type:   field.TypeUUID,
   731  			Value:  value,
   732  			Column: currencyhistory.FieldCoinTypeID,
   733  		})
   734  	}
   735  	if chuo.mutation.CoinTypeIDCleared() {
   736  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   737  			Type:   field.TypeUUID,
   738  			Column: currencyhistory.FieldCoinTypeID,
   739  		})
   740  	}
   741  	if value, ok := chuo.mutation.FeedType(); ok {
   742  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   743  			Type:   field.TypeString,
   744  			Value:  value,
   745  			Column: currencyhistory.FieldFeedType,
   746  		})
   747  	}
   748  	if chuo.mutation.FeedTypeCleared() {
   749  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   750  			Type:   field.TypeString,
   751  			Column: currencyhistory.FieldFeedType,
   752  		})
   753  	}
   754  	if value, ok := chuo.mutation.MarketValueHigh(); ok {
   755  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   756  			Type:   field.TypeOther,
   757  			Value:  value,
   758  			Column: currencyhistory.FieldMarketValueHigh,
   759  		})
   760  	}
   761  	if chuo.mutation.MarketValueHighCleared() {
   762  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   763  			Type:   field.TypeOther,
   764  			Column: currencyhistory.FieldMarketValueHigh,
   765  		})
   766  	}
   767  	if value, ok := chuo.mutation.MarketValueLow(); ok {
   768  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   769  			Type:   field.TypeOther,
   770  			Value:  value,
   771  			Column: currencyhistory.FieldMarketValueLow,
   772  		})
   773  	}
   774  	if chuo.mutation.MarketValueLowCleared() {
   775  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   776  			Type:   field.TypeOther,
   777  			Column: currencyhistory.FieldMarketValueLow,
   778  		})
   779  	}
   780  	_spec.Modifiers = chuo.modifiers
   781  	_node = &CurrencyHistory{config: chuo.config}
   782  	_spec.Assign = _node.assignValues
   783  	_spec.ScanValues = _node.scanValues
   784  	if err = sqlgraph.UpdateNode(ctx, chuo.driver, _spec); err != nil {
   785  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   786  			err = &NotFoundError{currencyhistory.Label}
   787  		} else if sqlgraph.IsConstraintError(err) {
   788  			err = &ConstraintError{msg: err.Error(), wrap: err}
   789  		}
   790  		return nil, err
   791  	}
   792  	return _node, nil
   793  }