telegram-commerce/ent/businesscategory.go
2023-10-26 01:24:32 +03:30

152 lines
5.1 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"tel-commerce/ent/businesscategory"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// BusinessCategory is the model entity for the BusinessCategory schema.
type BusinessCategory struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Slug holds the value of the "slug" field.
Slug string `json:"slug,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"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the BusinessCategoryQuery when eager-loading is set.
Edges BusinessCategoryEdges `json:"edges"`
selectValues sql.SelectValues
}
// BusinessCategoryEdges holds the relations/edges for other nodes in the graph.
type BusinessCategoryEdges struct {
// Businesses holds the value of the businesses edge.
Businesses []*Business `json:"businesses,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// BusinessesOrErr returns the Businesses value or an error if the edge
// was not loaded in eager-loading.
func (e BusinessCategoryEdges) BusinessesOrErr() ([]*Business, error) {
if e.loadedTypes[0] {
return e.Businesses, nil
}
return nil, &NotLoadedError{edge: "businesses"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*BusinessCategory) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case businesscategory.FieldID:
values[i] = new(sql.NullInt64)
case businesscategory.FieldSlug, businesscategory.FieldName, businesscategory.FieldDescription:
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the BusinessCategory fields.
func (bc *BusinessCategory) 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 businesscategory.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
bc.ID = int(value.Int64)
case businesscategory.FieldSlug:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field slug", values[i])
} else if value.Valid {
bc.Slug = value.String
}
case businesscategory.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
bc.Name = value.String
}
case businesscategory.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
bc.Description = value.String
}
default:
bc.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the BusinessCategory.
// This includes values selected through modifiers, order, etc.
func (bc *BusinessCategory) Value(name string) (ent.Value, error) {
return bc.selectValues.Get(name)
}
// QueryBusinesses queries the "businesses" edge of the BusinessCategory entity.
func (bc *BusinessCategory) QueryBusinesses() *BusinessQuery {
return NewBusinessCategoryClient(bc.config).QueryBusinesses(bc)
}
// Update returns a builder for updating this BusinessCategory.
// Note that you need to call BusinessCategory.Unwrap() before calling this method if this BusinessCategory
// was returned from a transaction, and the transaction was committed or rolled back.
func (bc *BusinessCategory) Update() *BusinessCategoryUpdateOne {
return NewBusinessCategoryClient(bc.config).UpdateOne(bc)
}
// Unwrap unwraps the BusinessCategory 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 (bc *BusinessCategory) Unwrap() *BusinessCategory {
_tx, ok := bc.config.driver.(*txDriver)
if !ok {
panic("ent: BusinessCategory is not a transactional entity")
}
bc.config.driver = _tx.drv
return bc
}
// String implements the fmt.Stringer.
func (bc *BusinessCategory) String() string {
var builder strings.Builder
builder.WriteString("BusinessCategory(")
builder.WriteString(fmt.Sprintf("id=%v, ", bc.ID))
builder.WriteString("slug=")
builder.WriteString(bc.Slug)
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(bc.Name)
builder.WriteString(", ")
builder.WriteString("description=")
builder.WriteString(bc.Description)
builder.WriteByte(')')
return builder.String()
}
// BusinessCategories is a parsable slice of BusinessCategory.
type BusinessCategories []*BusinessCategory