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