github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/chainbase.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/chainbase"
    11  	"github.com/google/uuid"
    12  )
    13  
    14  // ChainBase is the model entity for the ChainBase schema.
    15  type ChainBase 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  	// Name holds the value of the "name" field.
    28  	Name string `json:"name,omitempty"`
    29  	// Logo holds the value of the "logo" field.
    30  	Logo string `json:"logo,omitempty"`
    31  	// NativeUnit holds the value of the "native_unit" field.
    32  	NativeUnit string `json:"native_unit,omitempty"`
    33  	// AtomicUnit holds the value of the "atomic_unit" field.
    34  	AtomicUnit string `json:"atomic_unit,omitempty"`
    35  	// UnitExp holds the value of the "unit_exp" field.
    36  	UnitExp uint32 `json:"unit_exp,omitempty"`
    37  	// Env holds the value of the "env" field.
    38  	Env string `json:"env,omitempty"`
    39  	// ChainID holds the value of the "chain_id" field.
    40  	ChainID string `json:"chain_id,omitempty"`
    41  	// Nickname holds the value of the "nickname" field.
    42  	Nickname string `json:"nickname,omitempty"`
    43  	// GasType holds the value of the "gas_type" field.
    44  	GasType string `json:"gas_type,omitempty"`
    45  }
    46  
    47  // scanValues returns the types for scanning values from sql.Rows.
    48  func (*ChainBase) scanValues(columns []string) ([]interface{}, error) {
    49  	values := make([]interface{}, len(columns))
    50  	for i := range columns {
    51  		switch columns[i] {
    52  		case chainbase.FieldID, chainbase.FieldCreatedAt, chainbase.FieldUpdatedAt, chainbase.FieldDeletedAt, chainbase.FieldUnitExp:
    53  			values[i] = new(sql.NullInt64)
    54  		case chainbase.FieldName, chainbase.FieldLogo, chainbase.FieldNativeUnit, chainbase.FieldAtomicUnit, chainbase.FieldEnv, chainbase.FieldChainID, chainbase.FieldNickname, chainbase.FieldGasType:
    55  			values[i] = new(sql.NullString)
    56  		case chainbase.FieldEntID:
    57  			values[i] = new(uuid.UUID)
    58  		default:
    59  			return nil, fmt.Errorf("unexpected column %q for type ChainBase", columns[i])
    60  		}
    61  	}
    62  	return values, nil
    63  }
    64  
    65  // assignValues assigns the values that were returned from sql.Rows (after scanning)
    66  // to the ChainBase fields.
    67  func (cb *ChainBase) assignValues(columns []string, values []interface{}) error {
    68  	if m, n := len(values), len(columns); m < n {
    69  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
    70  	}
    71  	for i := range columns {
    72  		switch columns[i] {
    73  		case chainbase.FieldID:
    74  			value, ok := values[i].(*sql.NullInt64)
    75  			if !ok {
    76  				return fmt.Errorf("unexpected type %T for field id", value)
    77  			}
    78  			cb.ID = uint32(value.Int64)
    79  		case chainbase.FieldCreatedAt:
    80  			if value, ok := values[i].(*sql.NullInt64); !ok {
    81  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
    82  			} else if value.Valid {
    83  				cb.CreatedAt = uint32(value.Int64)
    84  			}
    85  		case chainbase.FieldUpdatedAt:
    86  			if value, ok := values[i].(*sql.NullInt64); !ok {
    87  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
    88  			} else if value.Valid {
    89  				cb.UpdatedAt = uint32(value.Int64)
    90  			}
    91  		case chainbase.FieldDeletedAt:
    92  			if value, ok := values[i].(*sql.NullInt64); !ok {
    93  				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
    94  			} else if value.Valid {
    95  				cb.DeletedAt = uint32(value.Int64)
    96  			}
    97  		case chainbase.FieldEntID:
    98  			if value, ok := values[i].(*uuid.UUID); !ok {
    99  				return fmt.Errorf("unexpected type %T for field ent_id", values[i])
   100  			} else if value != nil {
   101  				cb.EntID = *value
   102  			}
   103  		case chainbase.FieldName:
   104  			if value, ok := values[i].(*sql.NullString); !ok {
   105  				return fmt.Errorf("unexpected type %T for field name", values[i])
   106  			} else if value.Valid {
   107  				cb.Name = value.String
   108  			}
   109  		case chainbase.FieldLogo:
   110  			if value, ok := values[i].(*sql.NullString); !ok {
   111  				return fmt.Errorf("unexpected type %T for field logo", values[i])
   112  			} else if value.Valid {
   113  				cb.Logo = value.String
   114  			}
   115  		case chainbase.FieldNativeUnit:
   116  			if value, ok := values[i].(*sql.NullString); !ok {
   117  				return fmt.Errorf("unexpected type %T for field native_unit", values[i])
   118  			} else if value.Valid {
   119  				cb.NativeUnit = value.String
   120  			}
   121  		case chainbase.FieldAtomicUnit:
   122  			if value, ok := values[i].(*sql.NullString); !ok {
   123  				return fmt.Errorf("unexpected type %T for field atomic_unit", values[i])
   124  			} else if value.Valid {
   125  				cb.AtomicUnit = value.String
   126  			}
   127  		case chainbase.FieldUnitExp:
   128  			if value, ok := values[i].(*sql.NullInt64); !ok {
   129  				return fmt.Errorf("unexpected type %T for field unit_exp", values[i])
   130  			} else if value.Valid {
   131  				cb.UnitExp = uint32(value.Int64)
   132  			}
   133  		case chainbase.FieldEnv:
   134  			if value, ok := values[i].(*sql.NullString); !ok {
   135  				return fmt.Errorf("unexpected type %T for field env", values[i])
   136  			} else if value.Valid {
   137  				cb.Env = value.String
   138  			}
   139  		case chainbase.FieldChainID:
   140  			if value, ok := values[i].(*sql.NullString); !ok {
   141  				return fmt.Errorf("unexpected type %T for field chain_id", values[i])
   142  			} else if value.Valid {
   143  				cb.ChainID = value.String
   144  			}
   145  		case chainbase.FieldNickname:
   146  			if value, ok := values[i].(*sql.NullString); !ok {
   147  				return fmt.Errorf("unexpected type %T for field nickname", values[i])
   148  			} else if value.Valid {
   149  				cb.Nickname = value.String
   150  			}
   151  		case chainbase.FieldGasType:
   152  			if value, ok := values[i].(*sql.NullString); !ok {
   153  				return fmt.Errorf("unexpected type %T for field gas_type", values[i])
   154  			} else if value.Valid {
   155  				cb.GasType = value.String
   156  			}
   157  		}
   158  	}
   159  	return nil
   160  }
   161  
   162  // Update returns a builder for updating this ChainBase.
   163  // Note that you need to call ChainBase.Unwrap() before calling this method if this ChainBase
   164  // was returned from a transaction, and the transaction was committed or rolled back.
   165  func (cb *ChainBase) Update() *ChainBaseUpdateOne {
   166  	return (&ChainBaseClient{config: cb.config}).UpdateOne(cb)
   167  }
   168  
   169  // Unwrap unwraps the ChainBase entity that was returned from a transaction after it was closed,
   170  // so that all future queries will be executed through the driver which created the transaction.
   171  func (cb *ChainBase) Unwrap() *ChainBase {
   172  	_tx, ok := cb.config.driver.(*txDriver)
   173  	if !ok {
   174  		panic("ent: ChainBase is not a transactional entity")
   175  	}
   176  	cb.config.driver = _tx.drv
   177  	return cb
   178  }
   179  
   180  // String implements the fmt.Stringer.
   181  func (cb *ChainBase) String() string {
   182  	var builder strings.Builder
   183  	builder.WriteString("ChainBase(")
   184  	builder.WriteString(fmt.Sprintf("id=%v, ", cb.ID))
   185  	builder.WriteString("created_at=")
   186  	builder.WriteString(fmt.Sprintf("%v", cb.CreatedAt))
   187  	builder.WriteString(", ")
   188  	builder.WriteString("updated_at=")
   189  	builder.WriteString(fmt.Sprintf("%v", cb.UpdatedAt))
   190  	builder.WriteString(", ")
   191  	builder.WriteString("deleted_at=")
   192  	builder.WriteString(fmt.Sprintf("%v", cb.DeletedAt))
   193  	builder.WriteString(", ")
   194  	builder.WriteString("ent_id=")
   195  	builder.WriteString(fmt.Sprintf("%v", cb.EntID))
   196  	builder.WriteString(", ")
   197  	builder.WriteString("name=")
   198  	builder.WriteString(cb.Name)
   199  	builder.WriteString(", ")
   200  	builder.WriteString("logo=")
   201  	builder.WriteString(cb.Logo)
   202  	builder.WriteString(", ")
   203  	builder.WriteString("native_unit=")
   204  	builder.WriteString(cb.NativeUnit)
   205  	builder.WriteString(", ")
   206  	builder.WriteString("atomic_unit=")
   207  	builder.WriteString(cb.AtomicUnit)
   208  	builder.WriteString(", ")
   209  	builder.WriteString("unit_exp=")
   210  	builder.WriteString(fmt.Sprintf("%v", cb.UnitExp))
   211  	builder.WriteString(", ")
   212  	builder.WriteString("env=")
   213  	builder.WriteString(cb.Env)
   214  	builder.WriteString(", ")
   215  	builder.WriteString("chain_id=")
   216  	builder.WriteString(cb.ChainID)
   217  	builder.WriteString(", ")
   218  	builder.WriteString("nickname=")
   219  	builder.WriteString(cb.Nickname)
   220  	builder.WriteString(", ")
   221  	builder.WriteString("gas_type=")
   222  	builder.WriteString(cb.GasType)
   223  	builder.WriteByte(')')
   224  	return builder.String()
   225  }
   226  
   227  // ChainBases is a parsable slice of ChainBase.
   228  type ChainBases []*ChainBase
   229  
   230  func (cb ChainBases) config(cfg config) {
   231  	for _i := range cb {
   232  		cb[_i].config = cfg
   233  	}
   234  }