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