online-order/ent/product.go

320 lines
11 KiB
Go
Raw Normal View History

2023-10-27 09:51:58 +00:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
2023-10-28 23:12:07 +00:00
"online-order/ent/business"
2023-10-27 09:51:58 +00:00
"online-order/ent/product"
2023-10-28 23:12:07 +00:00
"online-order/ent/productcategory"
"online-order/ent/user"
2023-10-27 09:51:58 +00:00
"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"`
2023-10-28 23:12:07 +00:00
// Summary holds the value of the "summary" field.
Summary *string `json:"summary,omitempty"`
2023-10-27 09:51:58 +00:00
// 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"`
2023-10-28 23:12:07 +00:00
// 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"`
2023-10-27 09:51:58 +00:00
// 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 {
2023-10-28 23:12:07 +00:00
// 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"`
2023-10-27 09:51:58 +00:00
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
2023-10-28 23:12:07 +00:00
loadedTypes [3]bool
2023-10-27 09:51:58 +00:00
}
2023-10-28 23:12:07 +00:00
// 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) {
2023-10-27 09:51:58 +00:00
if e.loadedTypes[0] {
2023-10-28 23:12:07 +00:00
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
2023-10-27 09:51:58 +00:00
}
2023-10-28 23:12:07 +00:00
return nil, &NotLoadedError{edge: "users"}
2023-10-27 09:51:58 +00:00
}
// 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)
2023-10-28 23:12:07 +00:00
case product.FieldID, product.FieldQuantity, product.FieldProductCategoryID, product.FieldBusinessID, product.FieldUserID:
2023-10-27 09:51:58 +00:00
values[i] = new(sql.NullInt64)
2023-10-28 23:12:07 +00:00
case product.FieldName, product.FieldSummary, product.FieldDescription:
2023-10-27 09:51:58 +00:00
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
}
2023-10-28 23:12:07 +00:00
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
}
2023-10-27 09:51:58 +00:00
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
}
2023-10-28 23:12:07 +00:00
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)
}
2023-10-27 09:51:58 +00:00
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)
}
2023-10-28 23:12:07 +00:00
// 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)
2023-10-27 09:51:58 +00:00
}
// 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(", ")
2023-10-28 23:12:07 +00:00
if v := pr.Summary; v != nil {
builder.WriteString("summary=")
builder.WriteString(*v)
}
builder.WriteString(", ")
2023-10-27 09:51:58 +00:00
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(", ")
2023-10-28 23:12:07 +00:00
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(", ")
2023-10-27 09:51:58 +00:00
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