github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/tran.go (about)

     1  // Code generated by ent, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  
     9  	"entgo.io/ent/dialect/sql"
    10  	"github.com/NpoolPlatform/chain-middleware/pkg/db/ent/tran"
    11  	"github.com/google/uuid"
    12  	"github.com/shopspring/decimal"
    13  )
    14  
    15  // Tran is the model entity for the Tran schema.
    16  type Tran struct {
    17  	config `json:"-"`
    18  	// ID of the ent.
    19  	ID uint32 `json:"id,omitempty"`
    20  	// CreatedAt holds the value of the "created_at" field.
    21  	CreatedAt uint32 `json:"created_at,omitempty"`
    22  	// UpdatedAt holds the value of the "updated_at" field.
    23  	UpdatedAt uint32 `json:"updated_at,omitempty"`
    24  	// DeletedAt holds the value of the "deleted_at" field.
    25  	DeletedAt uint32 `json:"deleted_at,omitempty"`
    26  	// EntID holds the value of the "ent_id" field.
    27  	EntID uuid.UUID `json:"ent_id,omitempty"`
    28  	// CoinTypeID holds the value of the "coin_type_id" field.
    29  	CoinTypeID uuid.UUID `json:"coin_type_id,omitempty"`
    30  	// FromAccountID holds the value of the "from_account_id" field.
    31  	FromAccountID uuid.UUID `json:"from_account_id,omitempty"`
    32  	// ToAccountID holds the value of the "to_account_id" field.
    33  	ToAccountID uuid.UUID `json:"to_account_id,omitempty"`
    34  	// Amount holds the value of the "amount" field.
    35  	Amount decimal.Decimal `json:"amount,omitempty"`
    36  	// FeeAmount holds the value of the "fee_amount" field.
    37  	FeeAmount decimal.Decimal `json:"fee_amount,omitempty"`
    38  	// ChainTxID holds the value of the "chain_tx_id" field.
    39  	ChainTxID string `json:"chain_tx_id,omitempty"`
    40  	// State holds the value of the "state" field.
    41  	State string `json:"state,omitempty"`
    42  	// Extra holds the value of the "extra" field.
    43  	Extra string `json:"extra,omitempty"`
    44  	// Type holds the value of the "type" field.
    45  	Type string `json:"type,omitempty"`
    46  }
    47  
    48  // scanValues returns the types for scanning values from sql.Rows.
    49  func (*Tran) scanValues(columns []string) ([]interface{}, error) {
    50  	values := make([]interface{}, len(columns))
    51  	for i := range columns {
    52  		switch columns[i] {
    53  		case tran.FieldAmount, tran.FieldFeeAmount:
    54  			values[i] = new(decimal.Decimal)
    55  		case tran.FieldID, tran.FieldCreatedAt, tran.FieldUpdatedAt, tran.FieldDeletedAt:
    56  			values[i] = new(sql.NullInt64)
    57  		case tran.FieldChainTxID, tran.FieldState, tran.FieldExtra, tran.FieldType:
    58  			values[i] = new(sql.NullString)
    59  		case tran.FieldEntID, tran.FieldCoinTypeID, tran.FieldFromAccountID, tran.FieldToAccountID:
    60  			values[i] = new(uuid.UUID)
    61  		default:
    62  			return nil, fmt.Errorf("unexpected column %q for type Tran", columns[i])
    63  		}
    64  	}
    65  	return values, nil
    66  }
    67  
    68  // assignValues assigns the values that were returned from sql.Rows (after scanning)
    69  // to the Tran fields.
    70  func (t *Tran) assignValues(columns []string, values []interface{}) error {
    71  	if m, n := len(values), len(columns); m < n {
    72  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
    73  	}
    74  	for i := range columns {
    75  		switch columns[i] {
    76  		case tran.FieldID:
    77  			value, ok := values[i].(*sql.NullInt64)
    78  			if !ok {
    79  				return fmt.Errorf("unexpected type %T for field id", value)
    80  			}
    81  			t.ID = uint32(value.Int64)
    82  		case tran.FieldCreatedAt:
    83  			if value, ok := values[i].(*sql.NullInt64); !ok {
    84  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
    85  			} else if value.Valid {
    86  				t.CreatedAt = uint32(value.Int64)
    87  			}
    88  		case tran.FieldUpdatedAt:
    89  			if value, ok := values[i].(*sql.NullInt64); !ok {
    90  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
    91  			} else if value.Valid {
    92  				t.UpdatedAt = uint32(value.Int64)
    93  			}
    94  		case tran.FieldDeletedAt:
    95  			if value, ok := values[i].(*sql.NullInt64); !ok {
    96  				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
    97  			} else if value.Valid {
    98  				t.DeletedAt = uint32(value.Int64)
    99  			}
   100  		case tran.FieldEntID:
   101  			if value, ok := values[i].(*uuid.UUID); !ok {
   102  				return fmt.Errorf("unexpected type %T for field ent_id", values[i])
   103  			} else if value != nil {
   104  				t.EntID = *value
   105  			}
   106  		case tran.FieldCoinTypeID:
   107  			if value, ok := values[i].(*uuid.UUID); !ok {
   108  				return fmt.Errorf("unexpected type %T for field coin_type_id", values[i])
   109  			} else if value != nil {
   110  				t.CoinTypeID = *value
   111  			}
   112  		case tran.FieldFromAccountID:
   113  			if value, ok := values[i].(*uuid.UUID); !ok {
   114  				return fmt.Errorf("unexpected type %T for field from_account_id", values[i])
   115  			} else if value != nil {
   116  				t.FromAccountID = *value
   117  			}
   118  		case tran.FieldToAccountID:
   119  			if value, ok := values[i].(*uuid.UUID); !ok {
   120  				return fmt.Errorf("unexpected type %T for field to_account_id", values[i])
   121  			} else if value != nil {
   122  				t.ToAccountID = *value
   123  			}
   124  		case tran.FieldAmount:
   125  			if value, ok := values[i].(*decimal.Decimal); !ok {
   126  				return fmt.Errorf("unexpected type %T for field amount", values[i])
   127  			} else if value != nil {
   128  				t.Amount = *value
   129  			}
   130  		case tran.FieldFeeAmount:
   131  			if value, ok := values[i].(*decimal.Decimal); !ok {
   132  				return fmt.Errorf("unexpected type %T for field fee_amount", values[i])
   133  			} else if value != nil {
   134  				t.FeeAmount = *value
   135  			}
   136  		case tran.FieldChainTxID:
   137  			if value, ok := values[i].(*sql.NullString); !ok {
   138  				return fmt.Errorf("unexpected type %T for field chain_tx_id", values[i])
   139  			} else if value.Valid {
   140  				t.ChainTxID = value.String
   141  			}
   142  		case tran.FieldState:
   143  			if value, ok := values[i].(*sql.NullString); !ok {
   144  				return fmt.Errorf("unexpected type %T for field state", values[i])
   145  			} else if value.Valid {
   146  				t.State = value.String
   147  			}
   148  		case tran.FieldExtra:
   149  			if value, ok := values[i].(*sql.NullString); !ok {
   150  				return fmt.Errorf("unexpected type %T for field extra", values[i])
   151  			} else if value.Valid {
   152  				t.Extra = value.String
   153  			}
   154  		case tran.FieldType:
   155  			if value, ok := values[i].(*sql.NullString); !ok {
   156  				return fmt.Errorf("unexpected type %T for field type", values[i])
   157  			} else if value.Valid {
   158  				t.Type = value.String
   159  			}
   160  		}
   161  	}
   162  	return nil
   163  }
   164  
   165  // Update returns a builder for updating this Tran.
   166  // Note that you need to call Tran.Unwrap() before calling this method if this Tran
   167  // was returned from a transaction, and the transaction was committed or rolled back.
   168  func (t *Tran) Update() *TranUpdateOne {
   169  	return (&TranClient{config: t.config}).UpdateOne(t)
   170  }
   171  
   172  // Unwrap unwraps the Tran entity that was returned from a transaction after it was closed,
   173  // so that all future queries will be executed through the driver which created the transaction.
   174  func (t *Tran) Unwrap() *Tran {
   175  	_tx, ok := t.config.driver.(*txDriver)
   176  	if !ok {
   177  		panic("ent: Tran is not a transactional entity")
   178  	}
   179  	t.config.driver = _tx.drv
   180  	return t
   181  }
   182  
   183  // String implements the fmt.Stringer.
   184  func (t *Tran) String() string {
   185  	var builder strings.Builder
   186  	builder.WriteString("Tran(")
   187  	builder.WriteString(fmt.Sprintf("id=%v, ", t.ID))
   188  	builder.WriteString("created_at=")
   189  	builder.WriteString(fmt.Sprintf("%v", t.CreatedAt))
   190  	builder.WriteString(", ")
   191  	builder.WriteString("updated_at=")
   192  	builder.WriteString(fmt.Sprintf("%v", t.UpdatedAt))
   193  	builder.WriteString(", ")
   194  	builder.WriteString("deleted_at=")
   195  	builder.WriteString(fmt.Sprintf("%v", t.DeletedAt))
   196  	builder.WriteString(", ")
   197  	builder.WriteString("ent_id=")
   198  	builder.WriteString(fmt.Sprintf("%v", t.EntID))
   199  	builder.WriteString(", ")
   200  	builder.WriteString("coin_type_id=")
   201  	builder.WriteString(fmt.Sprintf("%v", t.CoinTypeID))
   202  	builder.WriteString(", ")
   203  	builder.WriteString("from_account_id=")
   204  	builder.WriteString(fmt.Sprintf("%v", t.FromAccountID))
   205  	builder.WriteString(", ")
   206  	builder.WriteString("to_account_id=")
   207  	builder.WriteString(fmt.Sprintf("%v", t.ToAccountID))
   208  	builder.WriteString(", ")
   209  	builder.WriteString("amount=")
   210  	builder.WriteString(fmt.Sprintf("%v", t.Amount))
   211  	builder.WriteString(", ")
   212  	builder.WriteString("fee_amount=")
   213  	builder.WriteString(fmt.Sprintf("%v", t.FeeAmount))
   214  	builder.WriteString(", ")
   215  	builder.WriteString("chain_tx_id=")
   216  	builder.WriteString(t.ChainTxID)
   217  	builder.WriteString(", ")
   218  	builder.WriteString("state=")
   219  	builder.WriteString(t.State)
   220  	builder.WriteString(", ")
   221  	builder.WriteString("extra=")
   222  	builder.WriteString(t.Extra)
   223  	builder.WriteString(", ")
   224  	builder.WriteString("type=")
   225  	builder.WriteString(t.Type)
   226  	builder.WriteByte(')')
   227  	return builder.String()
   228  }
   229  
   230  // Trans is a parsable slice of Tran.
   231  type Trans []*Tran
   232  
   233  func (t Trans) config(cfg config) {
   234  	for _i := range t {
   235  		t[_i].config = cfg
   236  	}
   237  }