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

     1  // Code generated by ent, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"encoding/json"
     7  	"fmt"
     8  	"strings"
     9  
    10  	"entgo.io/ent/dialect/sql"
    11  	"github.com/NpoolPlatform/chain-middleware/pkg/db/ent/appcoin"
    12  	"github.com/google/uuid"
    13  	"github.com/shopspring/decimal"
    14  )
    15  
    16  // AppCoin is the model entity for the AppCoin schema.
    17  type AppCoin struct {
    18  	config `json:"-"`
    19  	// ID of the ent.
    20  	ID uint32 `json:"id,omitempty"`
    21  	// CreatedAt holds the value of the "created_at" field.
    22  	CreatedAt uint32 `json:"created_at,omitempty"`
    23  	// UpdatedAt holds the value of the "updated_at" field.
    24  	UpdatedAt uint32 `json:"updated_at,omitempty"`
    25  	// DeletedAt holds the value of the "deleted_at" field.
    26  	DeletedAt uint32 `json:"deleted_at,omitempty"`
    27  	// EntID holds the value of the "ent_id" field.
    28  	EntID uuid.UUID `json:"ent_id,omitempty"`
    29  	// AppID holds the value of the "app_id" field.
    30  	AppID uuid.UUID `json:"app_id,omitempty"`
    31  	// CoinTypeID holds the value of the "coin_type_id" field.
    32  	CoinTypeID uuid.UUID `json:"coin_type_id,omitempty"`
    33  	// Name holds the value of the "name" field.
    34  	Name string `json:"name,omitempty"`
    35  	// DisplayNames holds the value of the "display_names" field.
    36  	DisplayNames []string `json:"display_names,omitempty"`
    37  	// Logo holds the value of the "logo" field.
    38  	Logo string `json:"logo,omitempty"`
    39  	// ForPay holds the value of the "for_pay" field.
    40  	ForPay bool `json:"for_pay,omitempty"`
    41  	// WithdrawAutoReviewAmount holds the value of the "withdraw_auto_review_amount" field.
    42  	WithdrawAutoReviewAmount decimal.Decimal `json:"withdraw_auto_review_amount,omitempty"`
    43  	// ProductPage holds the value of the "product_page" field.
    44  	ProductPage string `json:"product_page,omitempty"`
    45  	// Disabled holds the value of the "disabled" field.
    46  	Disabled bool `json:"disabled,omitempty"`
    47  	// DailyRewardAmount holds the value of the "daily_reward_amount" field.
    48  	DailyRewardAmount decimal.Decimal `json:"daily_reward_amount,omitempty"`
    49  	// Display holds the value of the "display" field.
    50  	Display bool `json:"display,omitempty"`
    51  	// DisplayIndex holds the value of the "display_index" field.
    52  	DisplayIndex uint32 `json:"display_index,omitempty"`
    53  	// MaxAmountPerWithdraw holds the value of the "max_amount_per_withdraw" field.
    54  	MaxAmountPerWithdraw decimal.Decimal `json:"max_amount_per_withdraw,omitempty"`
    55  }
    56  
    57  // scanValues returns the types for scanning values from sql.Rows.
    58  func (*AppCoin) scanValues(columns []string) ([]interface{}, error) {
    59  	values := make([]interface{}, len(columns))
    60  	for i := range columns {
    61  		switch columns[i] {
    62  		case appcoin.FieldDisplayNames:
    63  			values[i] = new([]byte)
    64  		case appcoin.FieldWithdrawAutoReviewAmount, appcoin.FieldDailyRewardAmount, appcoin.FieldMaxAmountPerWithdraw:
    65  			values[i] = new(decimal.Decimal)
    66  		case appcoin.FieldForPay, appcoin.FieldDisabled, appcoin.FieldDisplay:
    67  			values[i] = new(sql.NullBool)
    68  		case appcoin.FieldID, appcoin.FieldCreatedAt, appcoin.FieldUpdatedAt, appcoin.FieldDeletedAt, appcoin.FieldDisplayIndex:
    69  			values[i] = new(sql.NullInt64)
    70  		case appcoin.FieldName, appcoin.FieldLogo, appcoin.FieldProductPage:
    71  			values[i] = new(sql.NullString)
    72  		case appcoin.FieldEntID, appcoin.FieldAppID, appcoin.FieldCoinTypeID:
    73  			values[i] = new(uuid.UUID)
    74  		default:
    75  			return nil, fmt.Errorf("unexpected column %q for type AppCoin", columns[i])
    76  		}
    77  	}
    78  	return values, nil
    79  }
    80  
    81  // assignValues assigns the values that were returned from sql.Rows (after scanning)
    82  // to the AppCoin fields.
    83  func (ac *AppCoin) assignValues(columns []string, values []interface{}) error {
    84  	if m, n := len(values), len(columns); m < n {
    85  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
    86  	}
    87  	for i := range columns {
    88  		switch columns[i] {
    89  		case appcoin.FieldID:
    90  			value, ok := values[i].(*sql.NullInt64)
    91  			if !ok {
    92  				return fmt.Errorf("unexpected type %T for field id", value)
    93  			}
    94  			ac.ID = uint32(value.Int64)
    95  		case appcoin.FieldCreatedAt:
    96  			if value, ok := values[i].(*sql.NullInt64); !ok {
    97  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
    98  			} else if value.Valid {
    99  				ac.CreatedAt = uint32(value.Int64)
   100  			}
   101  		case appcoin.FieldUpdatedAt:
   102  			if value, ok := values[i].(*sql.NullInt64); !ok {
   103  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
   104  			} else if value.Valid {
   105  				ac.UpdatedAt = uint32(value.Int64)
   106  			}
   107  		case appcoin.FieldDeletedAt:
   108  			if value, ok := values[i].(*sql.NullInt64); !ok {
   109  				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
   110  			} else if value.Valid {
   111  				ac.DeletedAt = uint32(value.Int64)
   112  			}
   113  		case appcoin.FieldEntID:
   114  			if value, ok := values[i].(*uuid.UUID); !ok {
   115  				return fmt.Errorf("unexpected type %T for field ent_id", values[i])
   116  			} else if value != nil {
   117  				ac.EntID = *value
   118  			}
   119  		case appcoin.FieldAppID:
   120  			if value, ok := values[i].(*uuid.UUID); !ok {
   121  				return fmt.Errorf("unexpected type %T for field app_id", values[i])
   122  			} else if value != nil {
   123  				ac.AppID = *value
   124  			}
   125  		case appcoin.FieldCoinTypeID:
   126  			if value, ok := values[i].(*uuid.UUID); !ok {
   127  				return fmt.Errorf("unexpected type %T for field coin_type_id", values[i])
   128  			} else if value != nil {
   129  				ac.CoinTypeID = *value
   130  			}
   131  		case appcoin.FieldName:
   132  			if value, ok := values[i].(*sql.NullString); !ok {
   133  				return fmt.Errorf("unexpected type %T for field name", values[i])
   134  			} else if value.Valid {
   135  				ac.Name = value.String
   136  			}
   137  		case appcoin.FieldDisplayNames:
   138  			if value, ok := values[i].(*[]byte); !ok {
   139  				return fmt.Errorf("unexpected type %T for field display_names", values[i])
   140  			} else if value != nil && len(*value) > 0 {
   141  				if err := json.Unmarshal(*value, &ac.DisplayNames); err != nil {
   142  					return fmt.Errorf("unmarshal field display_names: %w", err)
   143  				}
   144  			}
   145  		case appcoin.FieldLogo:
   146  			if value, ok := values[i].(*sql.NullString); !ok {
   147  				return fmt.Errorf("unexpected type %T for field logo", values[i])
   148  			} else if value.Valid {
   149  				ac.Logo = value.String
   150  			}
   151  		case appcoin.FieldForPay:
   152  			if value, ok := values[i].(*sql.NullBool); !ok {
   153  				return fmt.Errorf("unexpected type %T for field for_pay", values[i])
   154  			} else if value.Valid {
   155  				ac.ForPay = value.Bool
   156  			}
   157  		case appcoin.FieldWithdrawAutoReviewAmount:
   158  			if value, ok := values[i].(*decimal.Decimal); !ok {
   159  				return fmt.Errorf("unexpected type %T for field withdraw_auto_review_amount", values[i])
   160  			} else if value != nil {
   161  				ac.WithdrawAutoReviewAmount = *value
   162  			}
   163  		case appcoin.FieldProductPage:
   164  			if value, ok := values[i].(*sql.NullString); !ok {
   165  				return fmt.Errorf("unexpected type %T for field product_page", values[i])
   166  			} else if value.Valid {
   167  				ac.ProductPage = value.String
   168  			}
   169  		case appcoin.FieldDisabled:
   170  			if value, ok := values[i].(*sql.NullBool); !ok {
   171  				return fmt.Errorf("unexpected type %T for field disabled", values[i])
   172  			} else if value.Valid {
   173  				ac.Disabled = value.Bool
   174  			}
   175  		case appcoin.FieldDailyRewardAmount:
   176  			if value, ok := values[i].(*decimal.Decimal); !ok {
   177  				return fmt.Errorf("unexpected type %T for field daily_reward_amount", values[i])
   178  			} else if value != nil {
   179  				ac.DailyRewardAmount = *value
   180  			}
   181  		case appcoin.FieldDisplay:
   182  			if value, ok := values[i].(*sql.NullBool); !ok {
   183  				return fmt.Errorf("unexpected type %T for field display", values[i])
   184  			} else if value.Valid {
   185  				ac.Display = value.Bool
   186  			}
   187  		case appcoin.FieldDisplayIndex:
   188  			if value, ok := values[i].(*sql.NullInt64); !ok {
   189  				return fmt.Errorf("unexpected type %T for field display_index", values[i])
   190  			} else if value.Valid {
   191  				ac.DisplayIndex = uint32(value.Int64)
   192  			}
   193  		case appcoin.FieldMaxAmountPerWithdraw:
   194  			if value, ok := values[i].(*decimal.Decimal); !ok {
   195  				return fmt.Errorf("unexpected type %T for field max_amount_per_withdraw", values[i])
   196  			} else if value != nil {
   197  				ac.MaxAmountPerWithdraw = *value
   198  			}
   199  		}
   200  	}
   201  	return nil
   202  }
   203  
   204  // Update returns a builder for updating this AppCoin.
   205  // Note that you need to call AppCoin.Unwrap() before calling this method if this AppCoin
   206  // was returned from a transaction, and the transaction was committed or rolled back.
   207  func (ac *AppCoin) Update() *AppCoinUpdateOne {
   208  	return (&AppCoinClient{config: ac.config}).UpdateOne(ac)
   209  }
   210  
   211  // Unwrap unwraps the AppCoin entity that was returned from a transaction after it was closed,
   212  // so that all future queries will be executed through the driver which created the transaction.
   213  func (ac *AppCoin) Unwrap() *AppCoin {
   214  	_tx, ok := ac.config.driver.(*txDriver)
   215  	if !ok {
   216  		panic("ent: AppCoin is not a transactional entity")
   217  	}
   218  	ac.config.driver = _tx.drv
   219  	return ac
   220  }
   221  
   222  // String implements the fmt.Stringer.
   223  func (ac *AppCoin) String() string {
   224  	var builder strings.Builder
   225  	builder.WriteString("AppCoin(")
   226  	builder.WriteString(fmt.Sprintf("id=%v, ", ac.ID))
   227  	builder.WriteString("created_at=")
   228  	builder.WriteString(fmt.Sprintf("%v", ac.CreatedAt))
   229  	builder.WriteString(", ")
   230  	builder.WriteString("updated_at=")
   231  	builder.WriteString(fmt.Sprintf("%v", ac.UpdatedAt))
   232  	builder.WriteString(", ")
   233  	builder.WriteString("deleted_at=")
   234  	builder.WriteString(fmt.Sprintf("%v", ac.DeletedAt))
   235  	builder.WriteString(", ")
   236  	builder.WriteString("ent_id=")
   237  	builder.WriteString(fmt.Sprintf("%v", ac.EntID))
   238  	builder.WriteString(", ")
   239  	builder.WriteString("app_id=")
   240  	builder.WriteString(fmt.Sprintf("%v", ac.AppID))
   241  	builder.WriteString(", ")
   242  	builder.WriteString("coin_type_id=")
   243  	builder.WriteString(fmt.Sprintf("%v", ac.CoinTypeID))
   244  	builder.WriteString(", ")
   245  	builder.WriteString("name=")
   246  	builder.WriteString(ac.Name)
   247  	builder.WriteString(", ")
   248  	builder.WriteString("display_names=")
   249  	builder.WriteString(fmt.Sprintf("%v", ac.DisplayNames))
   250  	builder.WriteString(", ")
   251  	builder.WriteString("logo=")
   252  	builder.WriteString(ac.Logo)
   253  	builder.WriteString(", ")
   254  	builder.WriteString("for_pay=")
   255  	builder.WriteString(fmt.Sprintf("%v", ac.ForPay))
   256  	builder.WriteString(", ")
   257  	builder.WriteString("withdraw_auto_review_amount=")
   258  	builder.WriteString(fmt.Sprintf("%v", ac.WithdrawAutoReviewAmount))
   259  	builder.WriteString(", ")
   260  	builder.WriteString("product_page=")
   261  	builder.WriteString(ac.ProductPage)
   262  	builder.WriteString(", ")
   263  	builder.WriteString("disabled=")
   264  	builder.WriteString(fmt.Sprintf("%v", ac.Disabled))
   265  	builder.WriteString(", ")
   266  	builder.WriteString("daily_reward_amount=")
   267  	builder.WriteString(fmt.Sprintf("%v", ac.DailyRewardAmount))
   268  	builder.WriteString(", ")
   269  	builder.WriteString("display=")
   270  	builder.WriteString(fmt.Sprintf("%v", ac.Display))
   271  	builder.WriteString(", ")
   272  	builder.WriteString("display_index=")
   273  	builder.WriteString(fmt.Sprintf("%v", ac.DisplayIndex))
   274  	builder.WriteString(", ")
   275  	builder.WriteString("max_amount_per_withdraw=")
   276  	builder.WriteString(fmt.Sprintf("%v", ac.MaxAmountPerWithdraw))
   277  	builder.WriteByte(')')
   278  	return builder.String()
   279  }
   280  
   281  // AppCoins is a parsable slice of AppCoin.
   282  type AppCoins []*AppCoin
   283  
   284  func (ac AppCoins) config(cfg config) {
   285  	for _i := range ac {
   286  		ac[_i].config = cfg
   287  	}
   288  }