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