// Code generated by ent, DO NOT EDIT. package ent import ( "fmt" "online-order/ent/product" "strings" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" ) // Product is the model entity for the Product schema. type Product struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` // Description holds the value of the "description" field. Description *string `json:"description,omitempty"` // Price holds the value of the "price" field. Price float64 `json:"price,omitempty"` // OriginalPrice holds the value of the "original_price" field. OriginalPrice float64 `json:"original_price,omitempty"` // Quantity holds the value of the "quantity" field. Quantity int `json:"quantity,omitempty"` // Status holds the value of the "status" field. Status bool `json:"status,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // UpdatedAt holds the value of the "updated_at" field. UpdatedAt time.Time `json:"updated_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the ProductQuery when eager-loading is set. Edges ProductEdges `json:"edges"` selectValues sql.SelectValues } // ProductEdges holds the relations/edges for other nodes in the graph. type ProductEdges struct { // ProductCategory holds the value of the productCategory edge. ProductCategory []*ProductCategory `json:"productCategory,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [1]bool } // ProductCategoryOrErr returns the ProductCategory value or an error if the edge // was not loaded in eager-loading. func (e ProductEdges) ProductCategoryOrErr() ([]*ProductCategory, error) { if e.loadedTypes[0] { return e.ProductCategory, nil } return nil, &NotLoadedError{edge: "productCategory"} } // scanValues returns the types for scanning values from sql.Rows. func (*Product) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case product.FieldStatus: values[i] = new(sql.NullBool) case product.FieldPrice, product.FieldOriginalPrice: values[i] = new(sql.NullFloat64) case product.FieldID, product.FieldQuantity: values[i] = new(sql.NullInt64) case product.FieldName, product.FieldDescription: values[i] = new(sql.NullString) case product.FieldCreatedAt, product.FieldUpdatedAt: values[i] = new(sql.NullTime) default: values[i] = new(sql.UnknownType) } } return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Product fields. func (pr *Product) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } for i := range columns { switch columns[i] { case product.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } pr.ID = int(value.Int64) case product.FieldName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field name", values[i]) } else if value.Valid { pr.Name = value.String } case product.FieldDescription: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field description", values[i]) } else if value.Valid { pr.Description = new(string) *pr.Description = value.String } case product.FieldPrice: if value, ok := values[i].(*sql.NullFloat64); !ok { return fmt.Errorf("unexpected type %T for field price", values[i]) } else if value.Valid { pr.Price = value.Float64 } case product.FieldOriginalPrice: if value, ok := values[i].(*sql.NullFloat64); !ok { return fmt.Errorf("unexpected type %T for field original_price", values[i]) } else if value.Valid { pr.OriginalPrice = value.Float64 } case product.FieldQuantity: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field quantity", values[i]) } else if value.Valid { pr.Quantity = int(value.Int64) } case product.FieldStatus: if value, ok := values[i].(*sql.NullBool); !ok { return fmt.Errorf("unexpected type %T for field status", values[i]) } else if value.Valid { pr.Status = value.Bool } case product.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { pr.CreatedAt = value.Time } case product.FieldUpdatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field updated_at", values[i]) } else if value.Valid { pr.UpdatedAt = value.Time } default: pr.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the Product. // This includes values selected through modifiers, order, etc. func (pr *Product) Value(name string) (ent.Value, error) { return pr.selectValues.Get(name) } // QueryProductCategory queries the "productCategory" edge of the Product entity. func (pr *Product) QueryProductCategory() *ProductCategoryQuery { return NewProductClient(pr.config).QueryProductCategory(pr) } // Update returns a builder for updating this Product. // Note that you need to call Product.Unwrap() before calling this method if this Product // was returned from a transaction, and the transaction was committed or rolled back. func (pr *Product) Update() *ProductUpdateOne { return NewProductClient(pr.config).UpdateOne(pr) } // Unwrap unwraps the Product entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (pr *Product) Unwrap() *Product { _tx, ok := pr.config.driver.(*txDriver) if !ok { panic("ent: Product is not a transactional entity") } pr.config.driver = _tx.drv return pr } // String implements the fmt.Stringer. func (pr *Product) String() string { var builder strings.Builder builder.WriteString("Product(") builder.WriteString(fmt.Sprintf("id=%v, ", pr.ID)) builder.WriteString("name=") builder.WriteString(pr.Name) builder.WriteString(", ") if v := pr.Description; v != nil { builder.WriteString("description=") builder.WriteString(*v) } builder.WriteString(", ") builder.WriteString("price=") builder.WriteString(fmt.Sprintf("%v", pr.Price)) builder.WriteString(", ") builder.WriteString("original_price=") builder.WriteString(fmt.Sprintf("%v", pr.OriginalPrice)) builder.WriteString(", ") builder.WriteString("quantity=") builder.WriteString(fmt.Sprintf("%v", pr.Quantity)) builder.WriteString(", ") builder.WriteString("status=") builder.WriteString(fmt.Sprintf("%v", pr.Status)) builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(pr.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("updated_at=") builder.WriteString(pr.UpdatedAt.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() } // Products is a parsable slice of Product. type Products []*Product