320 lines
11 KiB
Go
320 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"fmt"
|
|
"online-order/ent/business"
|
|
"online-order/ent/product"
|
|
"online-order/ent/productcategory"
|
|
"online-order/ent/user"
|
|
"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"`
|
|
// Summary holds the value of the "summary" field.
|
|
Summary *string `json:"summary,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"`
|
|
// ProductCategoryID holds the value of the "product_category_id" field.
|
|
ProductCategoryID *int `json:"product_category_id,omitempty"`
|
|
// BusinessID holds the value of the "business_id" field.
|
|
BusinessID *int `json:"business_id,omitempty"`
|
|
// UserID holds the value of the "user_id" field.
|
|
UserID *int `json:"user_id,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 {
|
|
// ProductCategories holds the value of the product_categories edge.
|
|
ProductCategories *ProductCategory `json:"product_categories,omitempty"`
|
|
// Businesses holds the value of the businesses edge.
|
|
Businesses *Business `json:"businesses,omitempty"`
|
|
// Users holds the value of the users edge.
|
|
Users *User `json:"users,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [3]bool
|
|
}
|
|
|
|
// ProductCategoriesOrErr returns the ProductCategories value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e ProductEdges) ProductCategoriesOrErr() (*ProductCategory, error) {
|
|
if e.loadedTypes[0] {
|
|
if e.ProductCategories == nil {
|
|
// Edge was loaded but was not found.
|
|
return nil, &NotFoundError{label: productcategory.Label}
|
|
}
|
|
return e.ProductCategories, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "product_categories"}
|
|
}
|
|
|
|
// BusinessesOrErr returns the Businesses value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e ProductEdges) BusinessesOrErr() (*Business, error) {
|
|
if e.loadedTypes[1] {
|
|
if e.Businesses == nil {
|
|
// Edge was loaded but was not found.
|
|
return nil, &NotFoundError{label: business.Label}
|
|
}
|
|
return e.Businesses, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "businesses"}
|
|
}
|
|
|
|
// UsersOrErr returns the Users value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e ProductEdges) UsersOrErr() (*User, error) {
|
|
if e.loadedTypes[2] {
|
|
if e.Users == nil {
|
|
// Edge was loaded but was not found.
|
|
return nil, &NotFoundError{label: user.Label}
|
|
}
|
|
return e.Users, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "users"}
|
|
}
|
|
|
|
// 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, product.FieldProductCategoryID, product.FieldBusinessID, product.FieldUserID:
|
|
values[i] = new(sql.NullInt64)
|
|
case product.FieldName, product.FieldSummary, 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.FieldSummary:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field summary", values[i])
|
|
} else if value.Valid {
|
|
pr.Summary = new(string)
|
|
*pr.Summary = 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.FieldProductCategoryID:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field product_category_id", values[i])
|
|
} else if value.Valid {
|
|
pr.ProductCategoryID = new(int)
|
|
*pr.ProductCategoryID = int(value.Int64)
|
|
}
|
|
case product.FieldBusinessID:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field business_id", values[i])
|
|
} else if value.Valid {
|
|
pr.BusinessID = new(int)
|
|
*pr.BusinessID = int(value.Int64)
|
|
}
|
|
case product.FieldUserID:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
|
} else if value.Valid {
|
|
pr.UserID = new(int)
|
|
*pr.UserID = int(value.Int64)
|
|
}
|
|
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)
|
|
}
|
|
|
|
// QueryProductCategories queries the "product_categories" edge of the Product entity.
|
|
func (pr *Product) QueryProductCategories() *ProductCategoryQuery {
|
|
return NewProductClient(pr.config).QueryProductCategories(pr)
|
|
}
|
|
|
|
// QueryBusinesses queries the "businesses" edge of the Product entity.
|
|
func (pr *Product) QueryBusinesses() *BusinessQuery {
|
|
return NewProductClient(pr.config).QueryBusinesses(pr)
|
|
}
|
|
|
|
// QueryUsers queries the "users" edge of the Product entity.
|
|
func (pr *Product) QueryUsers() *UserQuery {
|
|
return NewProductClient(pr.config).QueryUsers(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.Summary; v != nil {
|
|
builder.WriteString("summary=")
|
|
builder.WriteString(*v)
|
|
}
|
|
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(", ")
|
|
if v := pr.ProductCategoryID; v != nil {
|
|
builder.WriteString("product_category_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
}
|
|
builder.WriteString(", ")
|
|
if v := pr.BusinessID; v != nil {
|
|
builder.WriteString("business_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
}
|
|
builder.WriteString(", ")
|
|
if v := pr.UserID; v != nil {
|
|
builder.WriteString("user_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
}
|
|
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
|