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