online-order/ent/business.go

326 lines
11 KiB
Go
Raw Permalink Normal View History

2023-10-27 09:51:58 +00:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"online-order/ent/business"
2023-10-28 23:12:07 +00:00
"online-order/ent/businesscategory"
"online-order/ent/user"
2023-10-27 09:51:58 +00:00
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Business is the model entity for the Business schema.
type Business 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"`
// Slug holds the value of the "slug" field.
Slug string `json:"slug,omitempty"`
// BotID holds the value of the "bot_id" field.
BotID *string `json:"bot_id,omitempty"`
// Description holds the value of the "description" field.
Description *string `json:"description,omitempty"`
// AboutUs holds the value of the "about_us" field.
AboutUs *string `json:"about_us,omitempty"`
2023-10-28 23:12:07 +00:00
// BusinessCategoryID holds the value of the "business_category_id" field.
BusinessCategoryID *int `json:"business_category_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 BusinessQuery when eager-loading is set.
Edges BusinessEdges `json:"edges"`
selectValues sql.SelectValues
}
// BusinessEdges holds the relations/edges for other nodes in the graph.
type BusinessEdges struct {
2023-10-28 23:12:07 +00:00
// BusinessCategories holds the value of the business_categories edge.
BusinessCategories *BusinessCategory `json:"business_categories,omitempty"`
// Users holds the value of the users edge.
Users *User `json:"users,omitempty"`
// Products holds the value of the products edge.
Products []*Product `json:"products,omitempty"`
// ProductCategories holds the value of the product_categories edge.
ProductCategories []*ProductCategory `json:"product_categories,omitempty"`
// Domains holds the value of the domains edge.
Domains []*Domain `json:"domains,omitempty"`
// BusinessConfigs holds the value of the business_configs edge.
BusinessConfigs []*BusinessConfig `json:"business_configs,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 [6]bool
2023-10-27 09:51:58 +00:00
}
2023-10-28 23:12:07 +00:00
// BusinessCategoriesOrErr returns the BusinessCategories value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e BusinessEdges) BusinessCategoriesOrErr() (*BusinessCategory, error) {
2023-10-27 09:51:58 +00:00
if e.loadedTypes[0] {
2023-10-28 23:12:07 +00:00
if e.BusinessCategories == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: businesscategory.Label}
}
return e.BusinessCategories, nil
}
return nil, &NotLoadedError{edge: "business_categories"}
}
// 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 BusinessEdges) UsersOrErr() (*User, error) {
if e.loadedTypes[1] {
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"}
}
// ProductsOrErr returns the Products value or an error if the edge
// was not loaded in eager-loading.
func (e BusinessEdges) ProductsOrErr() ([]*Product, error) {
if e.loadedTypes[2] {
return e.Products, nil
}
return nil, &NotLoadedError{edge: "products"}
}
// ProductCategoriesOrErr returns the ProductCategories value or an error if the edge
// was not loaded in eager-loading.
func (e BusinessEdges) ProductCategoriesOrErr() ([]*ProductCategory, error) {
if e.loadedTypes[3] {
return e.ProductCategories, nil
}
return nil, &NotLoadedError{edge: "product_categories"}
}
// DomainsOrErr returns the Domains value or an error if the edge
// was not loaded in eager-loading.
func (e BusinessEdges) DomainsOrErr() ([]*Domain, error) {
if e.loadedTypes[4] {
return e.Domains, nil
}
return nil, &NotLoadedError{edge: "domains"}
}
// BusinessConfigsOrErr returns the BusinessConfigs value or an error if the edge
// was not loaded in eager-loading.
func (e BusinessEdges) BusinessConfigsOrErr() ([]*BusinessConfig, error) {
if e.loadedTypes[5] {
return e.BusinessConfigs, nil
}
return nil, &NotLoadedError{edge: "business_configs"}
2023-10-27 09:51:58 +00:00
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Business) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
2023-10-28 23:12:07 +00:00
case business.FieldID, business.FieldBusinessCategoryID, business.FieldUserID:
2023-10-27 09:51:58 +00:00
values[i] = new(sql.NullInt64)
2023-10-28 23:12:07 +00:00
case business.FieldName, business.FieldSlug, business.FieldBotID, business.FieldDescription, business.FieldAboutUs:
2023-10-27 09:51:58 +00:00
values[i] = new(sql.NullString)
case business.FieldCreatedAt, business.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 Business fields.
func (b *Business) 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 business.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
b.ID = int(value.Int64)
case business.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
b.Name = value.String
}
case business.FieldSlug:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field slug", values[i])
} else if value.Valid {
b.Slug = value.String
}
case business.FieldBotID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field bot_id", values[i])
} else if value.Valid {
b.BotID = new(string)
*b.BotID = value.String
}
case business.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
b.Description = new(string)
*b.Description = value.String
}
case business.FieldAboutUs:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field about_us", values[i])
} else if value.Valid {
b.AboutUs = new(string)
*b.AboutUs = value.String
}
2023-10-28 23:12:07 +00:00
case business.FieldBusinessCategoryID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field business_category_id", values[i])
} else if value.Valid {
b.BusinessCategoryID = new(int)
*b.BusinessCategoryID = int(value.Int64)
}
case business.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 {
b.UserID = new(int)
*b.UserID = int(value.Int64)
}
2023-10-27 09:51:58 +00:00
case business.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 {
b.CreatedAt = value.Time
}
case business.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 {
b.UpdatedAt = value.Time
}
default:
b.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Business.
// This includes values selected through modifiers, order, etc.
func (b *Business) Value(name string) (ent.Value, error) {
return b.selectValues.Get(name)
}
2023-10-28 23:12:07 +00:00
// QueryBusinessCategories queries the "business_categories" edge of the Business entity.
func (b *Business) QueryBusinessCategories() *BusinessCategoryQuery {
return NewBusinessClient(b.config).QueryBusinessCategories(b)
}
// QueryUsers queries the "users" edge of the Business entity.
func (b *Business) QueryUsers() *UserQuery {
return NewBusinessClient(b.config).QueryUsers(b)
}
// QueryProducts queries the "products" edge of the Business entity.
func (b *Business) QueryProducts() *ProductQuery {
return NewBusinessClient(b.config).QueryProducts(b)
}
// QueryProductCategories queries the "product_categories" edge of the Business entity.
func (b *Business) QueryProductCategories() *ProductCategoryQuery {
return NewBusinessClient(b.config).QueryProductCategories(b)
}
// QueryDomains queries the "domains" edge of the Business entity.
func (b *Business) QueryDomains() *DomainQuery {
return NewBusinessClient(b.config).QueryDomains(b)
}
// QueryBusinessConfigs queries the "business_configs" edge of the Business entity.
func (b *Business) QueryBusinessConfigs() *BusinessConfigQuery {
return NewBusinessClient(b.config).QueryBusinessConfigs(b)
2023-10-27 09:51:58 +00:00
}
// Update returns a builder for updating this Business.
// Note that you need to call Business.Unwrap() before calling this method if this Business
// was returned from a transaction, and the transaction was committed or rolled back.
func (b *Business) Update() *BusinessUpdateOne {
return NewBusinessClient(b.config).UpdateOne(b)
}
// Unwrap unwraps the Business 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 (b *Business) Unwrap() *Business {
_tx, ok := b.config.driver.(*txDriver)
if !ok {
panic("ent: Business is not a transactional entity")
}
b.config.driver = _tx.drv
return b
}
// String implements the fmt.Stringer.
func (b *Business) String() string {
var builder strings.Builder
builder.WriteString("Business(")
builder.WriteString(fmt.Sprintf("id=%v, ", b.ID))
builder.WriteString("name=")
builder.WriteString(b.Name)
builder.WriteString(", ")
builder.WriteString("slug=")
builder.WriteString(b.Slug)
builder.WriteString(", ")
if v := b.BotID; v != nil {
builder.WriteString("bot_id=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := b.Description; v != nil {
builder.WriteString("description=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := b.AboutUs; v != nil {
builder.WriteString("about_us=")
builder.WriteString(*v)
}
builder.WriteString(", ")
2023-10-28 23:12:07 +00:00
if v := b.BusinessCategoryID; v != nil {
builder.WriteString("business_category_id=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
if v := b.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(b.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(b.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Businesses is a parsable slice of Business.
type Businesses []*Business