github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/fiatcurrency.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/fiatcurrency"
    11  	"github.com/google/uuid"
    12  	"github.com/shopspring/decimal"
    13  )
    14  
    15  // FiatCurrency is the model entity for the FiatCurrency schema.
    16  type FiatCurrency 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  	// FiatID holds the value of the "fiat_id" field.
    29  	FiatID uuid.UUID `json:"fiat_id,omitempty"`
    30  	// FeedType holds the value of the "feed_type" field.
    31  	FeedType string `json:"feed_type,omitempty"`
    32  	// MarketValueLow holds the value of the "market_value_low" field.
    33  	MarketValueLow decimal.Decimal `json:"market_value_low,omitempty"`
    34  	// MarketValueHigh holds the value of the "market_value_high" field.
    35  	MarketValueHigh decimal.Decimal `json:"market_value_high,omitempty"`
    36  }
    37  
    38  // scanValues returns the types for scanning values from sql.Rows.
    39  func (*FiatCurrency) scanValues(columns []string) ([]interface{}, error) {
    40  	values := make([]interface{}, len(columns))
    41  	for i := range columns {
    42  		switch columns[i] {
    43  		case fiatcurrency.FieldMarketValueLow, fiatcurrency.FieldMarketValueHigh:
    44  			values[i] = new(decimal.Decimal)
    45  		case fiatcurrency.FieldID, fiatcurrency.FieldCreatedAt, fiatcurrency.FieldUpdatedAt, fiatcurrency.FieldDeletedAt:
    46  			values[i] = new(sql.NullInt64)
    47  		case fiatcurrency.FieldFeedType:
    48  			values[i] = new(sql.NullString)
    49  		case fiatcurrency.FieldEntID, fiatcurrency.FieldFiatID:
    50  			values[i] = new(uuid.UUID)
    51  		default:
    52  			return nil, fmt.Errorf("unexpected column %q for type FiatCurrency", columns[i])
    53  		}
    54  	}
    55  	return values, nil
    56  }
    57  
    58  // assignValues assigns the values that were returned from sql.Rows (after scanning)
    59  // to the FiatCurrency fields.
    60  func (fc *FiatCurrency) assignValues(columns []string, values []interface{}) error {
    61  	if m, n := len(values), len(columns); m < n {
    62  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
    63  	}
    64  	for i := range columns {
    65  		switch columns[i] {
    66  		case fiatcurrency.FieldID:
    67  			value, ok := values[i].(*sql.NullInt64)
    68  			if !ok {
    69  				return fmt.Errorf("unexpected type %T for field id", value)
    70  			}
    71  			fc.ID = uint32(value.Int64)
    72  		case fiatcurrency.FieldCreatedAt:
    73  			if value, ok := values[i].(*sql.NullInt64); !ok {
    74  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
    75  			} else if value.Valid {
    76  				fc.CreatedAt = uint32(value.Int64)
    77  			}
    78  		case fiatcurrency.FieldUpdatedAt:
    79  			if value, ok := values[i].(*sql.NullInt64); !ok {
    80  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
    81  			} else if value.Valid {
    82  				fc.UpdatedAt = uint32(value.Int64)
    83  			}
    84  		case fiatcurrency.FieldDeletedAt:
    85  			if value, ok := values[i].(*sql.NullInt64); !ok {
    86  				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
    87  			} else if value.Valid {
    88  				fc.DeletedAt = uint32(value.Int64)
    89  			}
    90  		case fiatcurrency.FieldEntID:
    91  			if value, ok := values[i].(*uuid.UUID); !ok {
    92  				return fmt.Errorf("unexpected type %T for field ent_id", values[i])
    93  			} else if value != nil {
    94  				fc.EntID = *value
    95  			}
    96  		case fiatcurrency.FieldFiatID:
    97  			if value, ok := values[i].(*uuid.UUID); !ok {
    98  				return fmt.Errorf("unexpected type %T for field fiat_id", values[i])
    99  			} else if value != nil {
   100  				fc.FiatID = *value
   101  			}
   102  		case fiatcurrency.FieldFeedType:
   103  			if value, ok := values[i].(*sql.NullString); !ok {
   104  				return fmt.Errorf("unexpected type %T for field feed_type", values[i])
   105  			} else if value.Valid {
   106  				fc.FeedType = value.String
   107  			}
   108  		case fiatcurrency.FieldMarketValueLow:
   109  			if value, ok := values[i].(*decimal.Decimal); !ok {
   110  				return fmt.Errorf("unexpected type %T for field market_value_low", values[i])
   111  			} else if value != nil {
   112  				fc.MarketValueLow = *value
   113  			}
   114  		case fiatcurrency.FieldMarketValueHigh:
   115  			if value, ok := values[i].(*decimal.Decimal); !ok {
   116  				return fmt.Errorf("unexpected type %T for field market_value_high", values[i])
   117  			} else if value != nil {
   118  				fc.MarketValueHigh = *value
   119  			}
   120  		}
   121  	}
   122  	return nil
   123  }
   124  
   125  // Update returns a builder for updating this FiatCurrency.
   126  // Note that you need to call FiatCurrency.Unwrap() before calling this method if this FiatCurrency
   127  // was returned from a transaction, and the transaction was committed or rolled back.
   128  func (fc *FiatCurrency) Update() *FiatCurrencyUpdateOne {
   129  	return (&FiatCurrencyClient{config: fc.config}).UpdateOne(fc)
   130  }
   131  
   132  // Unwrap unwraps the FiatCurrency entity that was returned from a transaction after it was closed,
   133  // so that all future queries will be executed through the driver which created the transaction.
   134  func (fc *FiatCurrency) Unwrap() *FiatCurrency {
   135  	_tx, ok := fc.config.driver.(*txDriver)
   136  	if !ok {
   137  		panic("ent: FiatCurrency is not a transactional entity")
   138  	}
   139  	fc.config.driver = _tx.drv
   140  	return fc
   141  }
   142  
   143  // String implements the fmt.Stringer.
   144  func (fc *FiatCurrency) String() string {
   145  	var builder strings.Builder
   146  	builder.WriteString("FiatCurrency(")
   147  	builder.WriteString(fmt.Sprintf("id=%v, ", fc.ID))
   148  	builder.WriteString("created_at=")
   149  	builder.WriteString(fmt.Sprintf("%v", fc.CreatedAt))
   150  	builder.WriteString(", ")
   151  	builder.WriteString("updated_at=")
   152  	builder.WriteString(fmt.Sprintf("%v", fc.UpdatedAt))
   153  	builder.WriteString(", ")
   154  	builder.WriteString("deleted_at=")
   155  	builder.WriteString(fmt.Sprintf("%v", fc.DeletedAt))
   156  	builder.WriteString(", ")
   157  	builder.WriteString("ent_id=")
   158  	builder.WriteString(fmt.Sprintf("%v", fc.EntID))
   159  	builder.WriteString(", ")
   160  	builder.WriteString("fiat_id=")
   161  	builder.WriteString(fmt.Sprintf("%v", fc.FiatID))
   162  	builder.WriteString(", ")
   163  	builder.WriteString("feed_type=")
   164  	builder.WriteString(fc.FeedType)
   165  	builder.WriteString(", ")
   166  	builder.WriteString("market_value_low=")
   167  	builder.WriteString(fmt.Sprintf("%v", fc.MarketValueLow))
   168  	builder.WriteString(", ")
   169  	builder.WriteString("market_value_high=")
   170  	builder.WriteString(fmt.Sprintf("%v", fc.MarketValueHigh))
   171  	builder.WriteByte(')')
   172  	return builder.String()
   173  }
   174  
   175  // FiatCurrencies is a parsable slice of FiatCurrency.
   176  type FiatCurrencies []*FiatCurrency
   177  
   178  func (fc FiatCurrencies) config(cfg config) {
   179  	for _i := range fc {
   180  		fc[_i].config = cfg
   181  	}
   182  }