first commit
This commit is contained in:
commit
9e17dcc501
5
.env.example
Normal file
5
.env.example
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
DB_USERNAME=root
|
||||||
|
DB_PASSWORD=
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=tel_commerce
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/tel-commerce.iml" filepath="$PROJECT_DIR$/.idea/tel-commerce.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
9
.idea/tel-commerce.iml
Normal file
9
.idea/tel-commerce.iml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
12
app/Http/Controllers/Controller.go
Normal file
12
app/Http/Controllers/Controller.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package Controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"tel-commerce/ent"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Controller struct {
|
||||||
|
Ctx context.Context
|
||||||
|
Client *ent.Client
|
||||||
|
//DomainDetail *Service.baseDomain
|
||||||
|
}
|
18
app/Http/Controllers/Index.go
Normal file
18
app/Http/Controllers/Index.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package Controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
|
"tel-commerce/ent"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (Controller Controller) GetProducts() gin.HandlerFunc {
|
||||||
|
return func(ctx *gin.Context) {
|
||||||
|
if products, err := Controller.Client.Product.Query().Order(ent.Asc(product.FieldID)).All(Controller.Ctx); err != nil {
|
||||||
|
ctx.IndentedJSON(http.StatusInternalServerError, err.Error())
|
||||||
|
} else {
|
||||||
|
ctx.IndentedJSON(http.StatusOK, products)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
app/Http/Controllers/Show.go
Normal file
5
app/Http/Controllers/Show.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package Controllers
|
||||||
|
|
||||||
|
func ShowProduct() {
|
||||||
|
|
||||||
|
}
|
31
app/Middleware/setDomainDetail.go
Normal file
31
app/Middleware/setDomainDetail.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package Middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
|
"tel-commerce/ent"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DomainMiddleware(client *ent.Client) gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
// دریافت نام دامنه از درخواست
|
||||||
|
domainName := c.Query("domain")
|
||||||
|
if domainName == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "نام دامنه نا معتبر"})
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// دریافت اطلاعات دامنه از دیتابیس
|
||||||
|
domain, err := GetDomain(c, client, domainName)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "دامنه یافت نشد"})
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ذخیره id دامنه در متغیر سیاق Gin
|
||||||
|
c.Set("domain", domain)
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
37
config/database.go
Normal file
37
config/database.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type databaseConf struct {
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
Host string
|
||||||
|
Dbname string
|
||||||
|
Port string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loading env variables from ".env"
|
||||||
|
func init() {
|
||||||
|
godotenv.Load(".env")
|
||||||
|
}
|
||||||
|
|
||||||
|
// get loaded env variables and create a new databaseConf struct
|
||||||
|
func DatabaseConfig() *databaseConf {
|
||||||
|
username := os.Getenv("DB_USERNAME")
|
||||||
|
password := os.Getenv("DB_PASSWORD")
|
||||||
|
host := os.Getenv("DB_HOST")
|
||||||
|
port := os.Getenv("DB_PORT")
|
||||||
|
dbName := os.Getenv("DB_DATABASE")
|
||||||
|
|
||||||
|
return &databaseConf{
|
||||||
|
Username: username,
|
||||||
|
Password: password,
|
||||||
|
Host: host,
|
||||||
|
Port: port,
|
||||||
|
Dbname: dbName,
|
||||||
|
}
|
||||||
|
}
|
10
database/seeds/DatabaseSeeder.go
Normal file
10
database/seeds/DatabaseSeeder.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package seeds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"tel-commerce/ent"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RunDatabaseSeeder(client *ent.Client, ctx *context.Context) {
|
||||||
|
|
||||||
|
}
|
218
ent/business.go
Normal file
218
ent/business.go
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"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"`
|
||||||
|
// Company holds the value of the "company" field.
|
||||||
|
Company string `json:"company,omitempty"`
|
||||||
|
// AboutUs holds the value of the "about_us" field.
|
||||||
|
AboutUs *string `json:"about_us,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 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 {
|
||||||
|
// BusinessCategory holds the value of the businessCategory edge.
|
||||||
|
BusinessCategory []*BusinessCategory `json:"businessCategory,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessCategoryOrErr returns the BusinessCategory value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e BusinessEdges) BusinessCategoryOrErr() ([]*BusinessCategory, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
return e.BusinessCategory, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "businessCategory"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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] {
|
||||||
|
case business.FieldID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case business.FieldName, business.FieldSlug, business.FieldBotID, business.FieldDescription, business.FieldCompany, business.FieldAboutUs:
|
||||||
|
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.FieldCompany:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field company", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
b.Company = 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
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryBusinessCategory queries the "businessCategory" edge of the Business entity.
|
||||||
|
func (b *Business) QueryBusinessCategory() *BusinessCategoryQuery {
|
||||||
|
return NewBusinessClient(b.config).QueryBusinessCategory(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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(", ")
|
||||||
|
builder.WriteString("company=")
|
||||||
|
builder.WriteString(b.Company)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := b.AboutUs; v != nil {
|
||||||
|
builder.WriteString("about_us=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
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
|
153
ent/business/business.go
Normal file
153
ent/business/business.go
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package business
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the business type in the database.
|
||||||
|
Label = "business"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
FieldName = "name"
|
||||||
|
// FieldSlug holds the string denoting the slug field in the database.
|
||||||
|
FieldSlug = "slug"
|
||||||
|
// FieldBotID holds the string denoting the bot_id field in the database.
|
||||||
|
FieldBotID = "bot_id"
|
||||||
|
// FieldDescription holds the string denoting the description field in the database.
|
||||||
|
FieldDescription = "description"
|
||||||
|
// FieldCompany holds the string denoting the company field in the database.
|
||||||
|
FieldCompany = "company"
|
||||||
|
// FieldAboutUs holds the string denoting the about_us field in the database.
|
||||||
|
FieldAboutUs = "about_us"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// EdgeBusinessCategory holds the string denoting the businesscategory edge name in mutations.
|
||||||
|
EdgeBusinessCategory = "businessCategory"
|
||||||
|
// Table holds the table name of the business in the database.
|
||||||
|
Table = "businesses"
|
||||||
|
// BusinessCategoryTable is the table that holds the businessCategory relation/edge. The primary key declared below.
|
||||||
|
BusinessCategoryTable = "business_category_businesses"
|
||||||
|
// BusinessCategoryInverseTable is the table name for the BusinessCategory entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "businesscategory" package.
|
||||||
|
BusinessCategoryInverseTable = "business_categories"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for business fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldName,
|
||||||
|
FieldSlug,
|
||||||
|
FieldBotID,
|
||||||
|
FieldDescription,
|
||||||
|
FieldCompany,
|
||||||
|
FieldAboutUs,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// BusinessCategoryPrimaryKey and BusinessCategoryColumn2 are the table columns denoting the
|
||||||
|
// primary key for the businessCategory relation (M2M).
|
||||||
|
BusinessCategoryPrimaryKey = []string{"business_category_id", "business_id"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultName holds the default value on creation for the "name" field.
|
||||||
|
DefaultName string
|
||||||
|
// DefaultCompany holds the default value on creation for the "company" field.
|
||||||
|
DefaultCompany string
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the Business queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByName orders the results by the name field.
|
||||||
|
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// BySlug orders the results by the slug field.
|
||||||
|
func BySlug(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldSlug, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBotID orders the results by the bot_id field.
|
||||||
|
func ByBotID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldBotID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDescription orders the results by the description field.
|
||||||
|
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCompany orders the results by the company field.
|
||||||
|
func ByCompany(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCompany, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByAboutUs orders the results by the about_us field.
|
||||||
|
func ByAboutUs(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldAboutUs, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBusinessCategoryCount orders the results by businessCategory count.
|
||||||
|
func ByBusinessCategoryCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newBusinessCategoryStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBusinessCategory orders the results by businessCategory terms.
|
||||||
|
func ByBusinessCategory(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newBusinessCategoryStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newBusinessCategoryStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(BusinessCategoryInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, BusinessCategoryTable, BusinessCategoryPrimaryKey...),
|
||||||
|
)
|
||||||
|
}
|
624
ent/business/where.go
Normal file
624
ent/business/where.go
Normal file
@ -0,0 +1,624 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package business
|
||||||
|
|
||||||
|
import (
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||||
|
func Name(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slug applies equality check predicate on the "slug" field. It's identical to SlugEQ.
|
||||||
|
func Slug(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotID applies equality check predicate on the "bot_id" field. It's identical to BotIDEQ.
|
||||||
|
func BotID(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||||
|
func Description(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Company applies equality check predicate on the "company" field. It's identical to CompanyEQ.
|
||||||
|
func Company(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUs applies equality check predicate on the "about_us" field. It's identical to AboutUsEQ.
|
||||||
|
func AboutUs(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEQ applies the EQ predicate on the "name" field.
|
||||||
|
func NameEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||||
|
func NameNEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameIn applies the In predicate on the "name" field.
|
||||||
|
func NameIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||||
|
func NameNotIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGT applies the GT predicate on the "name" field.
|
||||||
|
func NameGT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGTE applies the GTE predicate on the "name" field.
|
||||||
|
func NameGTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLT applies the LT predicate on the "name" field.
|
||||||
|
func NameLT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLTE applies the LTE predicate on the "name" field.
|
||||||
|
func NameLTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContains applies the Contains predicate on the "name" field.
|
||||||
|
func NameContains(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContains(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||||
|
func NameHasPrefix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasPrefix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||||
|
func NameHasSuffix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasSuffix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||||
|
func NameEqualFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEqualFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||||
|
func NameContainsFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContainsFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugEQ applies the EQ predicate on the "slug" field.
|
||||||
|
func SlugEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugNEQ applies the NEQ predicate on the "slug" field.
|
||||||
|
func SlugNEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugIn applies the In predicate on the "slug" field.
|
||||||
|
func SlugIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldSlug, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugNotIn applies the NotIn predicate on the "slug" field.
|
||||||
|
func SlugNotIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldSlug, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugGT applies the GT predicate on the "slug" field.
|
||||||
|
func SlugGT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugGTE applies the GTE predicate on the "slug" field.
|
||||||
|
func SlugGTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugLT applies the LT predicate on the "slug" field.
|
||||||
|
func SlugLT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugLTE applies the LTE predicate on the "slug" field.
|
||||||
|
func SlugLTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugContains applies the Contains predicate on the "slug" field.
|
||||||
|
func SlugContains(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContains(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugHasPrefix applies the HasPrefix predicate on the "slug" field.
|
||||||
|
func SlugHasPrefix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasPrefix(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugHasSuffix applies the HasSuffix predicate on the "slug" field.
|
||||||
|
func SlugHasSuffix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasSuffix(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugEqualFold applies the EqualFold predicate on the "slug" field.
|
||||||
|
func SlugEqualFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEqualFold(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugContainsFold applies the ContainsFold predicate on the "slug" field.
|
||||||
|
func SlugContainsFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContainsFold(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDEQ applies the EQ predicate on the "bot_id" field.
|
||||||
|
func BotIDEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDNEQ applies the NEQ predicate on the "bot_id" field.
|
||||||
|
func BotIDNEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDIn applies the In predicate on the "bot_id" field.
|
||||||
|
func BotIDIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldBotID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDNotIn applies the NotIn predicate on the "bot_id" field.
|
||||||
|
func BotIDNotIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldBotID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDGT applies the GT predicate on the "bot_id" field.
|
||||||
|
func BotIDGT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDGTE applies the GTE predicate on the "bot_id" field.
|
||||||
|
func BotIDGTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDLT applies the LT predicate on the "bot_id" field.
|
||||||
|
func BotIDLT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDLTE applies the LTE predicate on the "bot_id" field.
|
||||||
|
func BotIDLTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDContains applies the Contains predicate on the "bot_id" field.
|
||||||
|
func BotIDContains(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContains(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDHasPrefix applies the HasPrefix predicate on the "bot_id" field.
|
||||||
|
func BotIDHasPrefix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasPrefix(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDHasSuffix applies the HasSuffix predicate on the "bot_id" field.
|
||||||
|
func BotIDHasSuffix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasSuffix(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDEqualFold applies the EqualFold predicate on the "bot_id" field.
|
||||||
|
func BotIDEqualFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEqualFold(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BotIDContainsFold applies the ContainsFold predicate on the "bot_id" field.
|
||||||
|
func BotIDContainsFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContainsFold(FieldBotID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||||
|
func DescriptionEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||||
|
func DescriptionNEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIn applies the In predicate on the "description" field.
|
||||||
|
func DescriptionIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||||
|
func DescriptionNotIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGT applies the GT predicate on the "description" field.
|
||||||
|
func DescriptionGT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||||
|
func DescriptionGTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLT applies the LT predicate on the "description" field.
|
||||||
|
func DescriptionLT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||||
|
func DescriptionLTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||||
|
func DescriptionContains(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContains(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||||
|
func DescriptionHasPrefix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasPrefix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||||
|
func DescriptionHasSuffix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasSuffix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||||
|
func DescriptionIsNil() predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIsNull(FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||||
|
func DescriptionNotNil() predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotNull(FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||||
|
func DescriptionEqualFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEqualFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||||
|
func DescriptionContainsFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContainsFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyEQ applies the EQ predicate on the "company" field.
|
||||||
|
func CompanyEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyNEQ applies the NEQ predicate on the "company" field.
|
||||||
|
func CompanyNEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyIn applies the In predicate on the "company" field.
|
||||||
|
func CompanyIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldCompany, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyNotIn applies the NotIn predicate on the "company" field.
|
||||||
|
func CompanyNotIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldCompany, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyGT applies the GT predicate on the "company" field.
|
||||||
|
func CompanyGT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyGTE applies the GTE predicate on the "company" field.
|
||||||
|
func CompanyGTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyLT applies the LT predicate on the "company" field.
|
||||||
|
func CompanyLT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyLTE applies the LTE predicate on the "company" field.
|
||||||
|
func CompanyLTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyContains applies the Contains predicate on the "company" field.
|
||||||
|
func CompanyContains(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContains(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyHasPrefix applies the HasPrefix predicate on the "company" field.
|
||||||
|
func CompanyHasPrefix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasPrefix(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyHasSuffix applies the HasSuffix predicate on the "company" field.
|
||||||
|
func CompanyHasSuffix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasSuffix(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyEqualFold applies the EqualFold predicate on the "company" field.
|
||||||
|
func CompanyEqualFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEqualFold(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompanyContainsFold applies the ContainsFold predicate on the "company" field.
|
||||||
|
func CompanyContainsFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContainsFold(FieldCompany, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsEQ applies the EQ predicate on the "about_us" field.
|
||||||
|
func AboutUsEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsNEQ applies the NEQ predicate on the "about_us" field.
|
||||||
|
func AboutUsNEQ(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsIn applies the In predicate on the "about_us" field.
|
||||||
|
func AboutUsIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldAboutUs, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsNotIn applies the NotIn predicate on the "about_us" field.
|
||||||
|
func AboutUsNotIn(vs ...string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldAboutUs, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsGT applies the GT predicate on the "about_us" field.
|
||||||
|
func AboutUsGT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsGTE applies the GTE predicate on the "about_us" field.
|
||||||
|
func AboutUsGTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsLT applies the LT predicate on the "about_us" field.
|
||||||
|
func AboutUsLT(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsLTE applies the LTE predicate on the "about_us" field.
|
||||||
|
func AboutUsLTE(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsContains applies the Contains predicate on the "about_us" field.
|
||||||
|
func AboutUsContains(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContains(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsHasPrefix applies the HasPrefix predicate on the "about_us" field.
|
||||||
|
func AboutUsHasPrefix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasPrefix(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsHasSuffix applies the HasSuffix predicate on the "about_us" field.
|
||||||
|
func AboutUsHasSuffix(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldHasSuffix(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsIsNil applies the IsNil predicate on the "about_us" field.
|
||||||
|
func AboutUsIsNil() predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIsNull(FieldAboutUs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsNotNil applies the NotNil predicate on the "about_us" field.
|
||||||
|
func AboutUsNotNil() predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotNull(FieldAboutUs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsEqualFold applies the EqualFold predicate on the "about_us" field.
|
||||||
|
func AboutUsEqualFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEqualFold(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AboutUsContainsFold applies the ContainsFold predicate on the "about_us" field.
|
||||||
|
func AboutUsContainsFold(v string) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldContainsFold(FieldAboutUs, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.Business {
|
||||||
|
return predicate.Business(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasBusinessCategory applies the HasEdge predicate on the "businessCategory" edge.
|
||||||
|
func HasBusinessCategory() predicate.Business {
|
||||||
|
return predicate.Business(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, BusinessCategoryTable, BusinessCategoryPrimaryKey...),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasBusinessCategoryWith applies the HasEdge predicate on the "businessCategory" edge with a given conditions (other predicates).
|
||||||
|
func HasBusinessCategoryWith(preds ...predicate.BusinessCategory) predicate.Business {
|
||||||
|
return predicate.Business(func(s *sql.Selector) {
|
||||||
|
step := newBusinessCategoryStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.Business) predicate.Business {
|
||||||
|
return predicate.Business(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.Business) predicate.Business {
|
||||||
|
return predicate.Business(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.Business) predicate.Business {
|
||||||
|
return predicate.Business(sql.NotPredicates(p))
|
||||||
|
}
|
371
ent/business_create.go
Normal file
371
ent/business_create.go
Normal file
@ -0,0 +1,371 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessCreate is the builder for creating a Business entity.
|
||||||
|
type BusinessCreate struct {
|
||||||
|
config
|
||||||
|
mutation *BusinessMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (bc *BusinessCreate) SetName(s string) *BusinessCreate {
|
||||||
|
bc.mutation.SetName(s)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (bc *BusinessCreate) SetNillableName(s *string) *BusinessCreate {
|
||||||
|
if s != nil {
|
||||||
|
bc.SetName(*s)
|
||||||
|
}
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (bc *BusinessCreate) SetSlug(s string) *BusinessCreate {
|
||||||
|
bc.mutation.SetSlug(s)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBotID sets the "bot_id" field.
|
||||||
|
func (bc *BusinessCreate) SetBotID(s string) *BusinessCreate {
|
||||||
|
bc.mutation.SetBotID(s)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (bc *BusinessCreate) SetDescription(s string) *BusinessCreate {
|
||||||
|
bc.mutation.SetDescription(s)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (bc *BusinessCreate) SetNillableDescription(s *string) *BusinessCreate {
|
||||||
|
if s != nil {
|
||||||
|
bc.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCompany sets the "company" field.
|
||||||
|
func (bc *BusinessCreate) SetCompany(s string) *BusinessCreate {
|
||||||
|
bc.mutation.SetCompany(s)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCompany sets the "company" field if the given value is not nil.
|
||||||
|
func (bc *BusinessCreate) SetNillableCompany(s *string) *BusinessCreate {
|
||||||
|
if s != nil {
|
||||||
|
bc.SetCompany(*s)
|
||||||
|
}
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAboutUs sets the "about_us" field.
|
||||||
|
func (bc *BusinessCreate) SetAboutUs(s string) *BusinessCreate {
|
||||||
|
bc.mutation.SetAboutUs(s)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAboutUs sets the "about_us" field if the given value is not nil.
|
||||||
|
func (bc *BusinessCreate) SetNillableAboutUs(s *string) *BusinessCreate {
|
||||||
|
if s != nil {
|
||||||
|
bc.SetAboutUs(*s)
|
||||||
|
}
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (bc *BusinessCreate) SetCreatedAt(t time.Time) *BusinessCreate {
|
||||||
|
bc.mutation.SetCreatedAt(t)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (bc *BusinessCreate) SetNillableCreatedAt(t *time.Time) *BusinessCreate {
|
||||||
|
if t != nil {
|
||||||
|
bc.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (bc *BusinessCreate) SetUpdatedAt(t time.Time) *BusinessCreate {
|
||||||
|
bc.mutation.SetUpdatedAt(t)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (bc *BusinessCreate) SetNillableUpdatedAt(t *time.Time) *BusinessCreate {
|
||||||
|
if t != nil {
|
||||||
|
bc.SetUpdatedAt(*t)
|
||||||
|
}
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessCategoryIDs adds the "businessCategory" edge to the BusinessCategory entity by IDs.
|
||||||
|
func (bc *BusinessCreate) AddBusinessCategoryIDs(ids ...int) *BusinessCreate {
|
||||||
|
bc.mutation.AddBusinessCategoryIDs(ids...)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessCategory adds the "businessCategory" edges to the BusinessCategory entity.
|
||||||
|
func (bc *BusinessCreate) AddBusinessCategory(b ...*BusinessCategory) *BusinessCreate {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return bc.AddBusinessCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the BusinessMutation object of the builder.
|
||||||
|
func (bc *BusinessCreate) Mutation() *BusinessMutation {
|
||||||
|
return bc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Business in the database.
|
||||||
|
func (bc *BusinessCreate) Save(ctx context.Context) (*Business, error) {
|
||||||
|
bc.defaults()
|
||||||
|
return withHooks(ctx, bc.sqlSave, bc.mutation, bc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (bc *BusinessCreate) SaveX(ctx context.Context) *Business {
|
||||||
|
v, err := bc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (bc *BusinessCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := bc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bc *BusinessCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := bc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (bc *BusinessCreate) defaults() {
|
||||||
|
if _, ok := bc.mutation.Name(); !ok {
|
||||||
|
v := business.DefaultName
|
||||||
|
bc.mutation.SetName(v)
|
||||||
|
}
|
||||||
|
if _, ok := bc.mutation.Company(); !ok {
|
||||||
|
v := business.DefaultCompany
|
||||||
|
bc.mutation.SetCompany(v)
|
||||||
|
}
|
||||||
|
if _, ok := bc.mutation.CreatedAt(); !ok {
|
||||||
|
v := business.DefaultCreatedAt()
|
||||||
|
bc.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := bc.mutation.UpdatedAt(); !ok {
|
||||||
|
v := business.DefaultUpdatedAt()
|
||||||
|
bc.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (bc *BusinessCreate) check() error {
|
||||||
|
if _, ok := bc.mutation.Name(); !ok {
|
||||||
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Business.name"`)}
|
||||||
|
}
|
||||||
|
if _, ok := bc.mutation.Slug(); !ok {
|
||||||
|
return &ValidationError{Name: "slug", err: errors.New(`ent: missing required field "Business.slug"`)}
|
||||||
|
}
|
||||||
|
if _, ok := bc.mutation.BotID(); !ok {
|
||||||
|
return &ValidationError{Name: "bot_id", err: errors.New(`ent: missing required field "Business.bot_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := bc.mutation.Company(); !ok {
|
||||||
|
return &ValidationError{Name: "company", err: errors.New(`ent: missing required field "Business.company"`)}
|
||||||
|
}
|
||||||
|
if _, ok := bc.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Business.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := bc.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Business.updated_at"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc *BusinessCreate) sqlSave(ctx context.Context) (*Business, error) {
|
||||||
|
if err := bc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := bc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, bc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int(id)
|
||||||
|
bc.mutation.id = &_node.ID
|
||||||
|
bc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc *BusinessCreate) createSpec() (*Business, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Business{config: bc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(business.Table, sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt))
|
||||||
|
)
|
||||||
|
if value, ok := bc.mutation.Name(); ok {
|
||||||
|
_spec.SetField(business.FieldName, field.TypeString, value)
|
||||||
|
_node.Name = value
|
||||||
|
}
|
||||||
|
if value, ok := bc.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(business.FieldSlug, field.TypeString, value)
|
||||||
|
_node.Slug = value
|
||||||
|
}
|
||||||
|
if value, ok := bc.mutation.BotID(); ok {
|
||||||
|
_spec.SetField(business.FieldBotID, field.TypeString, value)
|
||||||
|
_node.BotID = &value
|
||||||
|
}
|
||||||
|
if value, ok := bc.mutation.Description(); ok {
|
||||||
|
_spec.SetField(business.FieldDescription, field.TypeString, value)
|
||||||
|
_node.Description = &value
|
||||||
|
}
|
||||||
|
if value, ok := bc.mutation.Company(); ok {
|
||||||
|
_spec.SetField(business.FieldCompany, field.TypeString, value)
|
||||||
|
_node.Company = value
|
||||||
|
}
|
||||||
|
if value, ok := bc.mutation.AboutUs(); ok {
|
||||||
|
_spec.SetField(business.FieldAboutUs, field.TypeString, value)
|
||||||
|
_node.AboutUs = &value
|
||||||
|
}
|
||||||
|
if value, ok := bc.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(business.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := bc.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(business.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if nodes := bc.mutation.BusinessCategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: business.BusinessCategoryTable,
|
||||||
|
Columns: business.BusinessCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessCreateBulk is the builder for creating many Business entities in bulk.
|
||||||
|
type BusinessCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*BusinessCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Business entities in the database.
|
||||||
|
func (bcb *BusinessCreateBulk) Save(ctx context.Context) ([]*Business, error) {
|
||||||
|
if bcb.err != nil {
|
||||||
|
return nil, bcb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(bcb.builders))
|
||||||
|
nodes := make([]*Business, len(bcb.builders))
|
||||||
|
mutators := make([]Mutator, len(bcb.builders))
|
||||||
|
for i := range bcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := bcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*BusinessMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, bcb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, bcb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, bcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (bcb *BusinessCreateBulk) SaveX(ctx context.Context) []*Business {
|
||||||
|
v, err := bcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (bcb *BusinessCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := bcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bcb *BusinessCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := bcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
88
ent/business_delete.go
Normal file
88
ent/business_delete.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessDelete is the builder for deleting a Business entity.
|
||||||
|
type BusinessDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *BusinessMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the BusinessDelete builder.
|
||||||
|
func (bd *BusinessDelete) Where(ps ...predicate.Business) *BusinessDelete {
|
||||||
|
bd.mutation.Where(ps...)
|
||||||
|
return bd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (bd *BusinessDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, bd.sqlExec, bd.mutation, bd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bd *BusinessDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := bd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bd *BusinessDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(business.Table, sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt))
|
||||||
|
if ps := bd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, bd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
bd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessDeleteOne is the builder for deleting a single Business entity.
|
||||||
|
type BusinessDeleteOne struct {
|
||||||
|
bd *BusinessDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the BusinessDelete builder.
|
||||||
|
func (bdo *BusinessDeleteOne) Where(ps ...predicate.Business) *BusinessDeleteOne {
|
||||||
|
bdo.bd.mutation.Where(ps...)
|
||||||
|
return bdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (bdo *BusinessDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := bdo.bd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{business.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bdo *BusinessDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := bdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
636
ent/business_query.go
Normal file
636
ent/business_query.go
Normal file
@ -0,0 +1,636 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessQuery is the builder for querying Business entities.
|
||||||
|
type BusinessQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []business.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.Business
|
||||||
|
withBusinessCategory *BusinessCategoryQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the BusinessQuery builder.
|
||||||
|
func (bq *BusinessQuery) Where(ps ...predicate.Business) *BusinessQuery {
|
||||||
|
bq.predicates = append(bq.predicates, ps...)
|
||||||
|
return bq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (bq *BusinessQuery) Limit(limit int) *BusinessQuery {
|
||||||
|
bq.ctx.Limit = &limit
|
||||||
|
return bq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (bq *BusinessQuery) Offset(offset int) *BusinessQuery {
|
||||||
|
bq.ctx.Offset = &offset
|
||||||
|
return bq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (bq *BusinessQuery) Unique(unique bool) *BusinessQuery {
|
||||||
|
bq.ctx.Unique = &unique
|
||||||
|
return bq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (bq *BusinessQuery) Order(o ...business.OrderOption) *BusinessQuery {
|
||||||
|
bq.order = append(bq.order, o...)
|
||||||
|
return bq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryBusinessCategory chains the current query on the "businessCategory" edge.
|
||||||
|
func (bq *BusinessQuery) QueryBusinessCategory() *BusinessCategoryQuery {
|
||||||
|
query := (&BusinessCategoryClient{config: bq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := bq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := bq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(business.Table, business.FieldID, selector),
|
||||||
|
sqlgraph.To(businesscategory.Table, businesscategory.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, business.BusinessCategoryTable, business.BusinessCategoryPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(bq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Business entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Business was found.
|
||||||
|
func (bq *BusinessQuery) First(ctx context.Context) (*Business, error) {
|
||||||
|
nodes, err := bq.Limit(1).All(setContextOp(ctx, bq.ctx, "First"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{business.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (bq *BusinessQuery) FirstX(ctx context.Context) *Business {
|
||||||
|
node, err := bq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Business ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Business ID was found.
|
||||||
|
func (bq *BusinessQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = bq.Limit(1).IDs(setContextOp(ctx, bq.ctx, "FirstID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{business.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (bq *BusinessQuery) FirstIDX(ctx context.Context) int {
|
||||||
|
id, err := bq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Business entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Business entity is found.
|
||||||
|
// Returns a *NotFoundError when no Business entities are found.
|
||||||
|
func (bq *BusinessQuery) Only(ctx context.Context) (*Business, error) {
|
||||||
|
nodes, err := bq.Limit(2).All(setContextOp(ctx, bq.ctx, "Only"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{business.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{business.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (bq *BusinessQuery) OnlyX(ctx context.Context) *Business {
|
||||||
|
node, err := bq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Business ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Business ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (bq *BusinessQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = bq.Limit(2).IDs(setContextOp(ctx, bq.ctx, "OnlyID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{business.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{business.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (bq *BusinessQuery) OnlyIDX(ctx context.Context) int {
|
||||||
|
id, err := bq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of Businesses.
|
||||||
|
func (bq *BusinessQuery) All(ctx context.Context) ([]*Business, error) {
|
||||||
|
ctx = setContextOp(ctx, bq.ctx, "All")
|
||||||
|
if err := bq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*Business, *BusinessQuery]()
|
||||||
|
return withInterceptors[[]*Business](ctx, bq, qr, bq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (bq *BusinessQuery) AllX(ctx context.Context) []*Business {
|
||||||
|
nodes, err := bq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Business IDs.
|
||||||
|
func (bq *BusinessQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||||
|
if bq.ctx.Unique == nil && bq.path != nil {
|
||||||
|
bq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, bq.ctx, "IDs")
|
||||||
|
if err = bq.Select(business.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (bq *BusinessQuery) IDsX(ctx context.Context) []int {
|
||||||
|
ids, err := bq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (bq *BusinessQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, bq.ctx, "Count")
|
||||||
|
if err := bq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, bq, querierCount[*BusinessQuery](), bq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (bq *BusinessQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := bq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (bq *BusinessQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, bq.ctx, "Exist")
|
||||||
|
switch _, err := bq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (bq *BusinessQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := bq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the BusinessQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (bq *BusinessQuery) Clone() *BusinessQuery {
|
||||||
|
if bq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &BusinessQuery{
|
||||||
|
config: bq.config,
|
||||||
|
ctx: bq.ctx.Clone(),
|
||||||
|
order: append([]business.OrderOption{}, bq.order...),
|
||||||
|
inters: append([]Interceptor{}, bq.inters...),
|
||||||
|
predicates: append([]predicate.Business{}, bq.predicates...),
|
||||||
|
withBusinessCategory: bq.withBusinessCategory.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: bq.sql.Clone(),
|
||||||
|
path: bq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithBusinessCategory tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "businessCategory" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (bq *BusinessQuery) WithBusinessCategory(opts ...func(*BusinessCategoryQuery)) *BusinessQuery {
|
||||||
|
query := (&BusinessCategoryClient{config: bq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
bq.withBusinessCategory = query
|
||||||
|
return bq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Name string `json:"name,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Business.Query().
|
||||||
|
// GroupBy(business.FieldName).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (bq *BusinessQuery) GroupBy(field string, fields ...string) *BusinessGroupBy {
|
||||||
|
bq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &BusinessGroupBy{build: bq}
|
||||||
|
grbuild.flds = &bq.ctx.Fields
|
||||||
|
grbuild.label = business.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Name string `json:"name,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Business.Query().
|
||||||
|
// Select(business.FieldName).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (bq *BusinessQuery) Select(fields ...string) *BusinessSelect {
|
||||||
|
bq.ctx.Fields = append(bq.ctx.Fields, fields...)
|
||||||
|
sbuild := &BusinessSelect{BusinessQuery: bq}
|
||||||
|
sbuild.label = business.Label
|
||||||
|
sbuild.flds, sbuild.scan = &bq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a BusinessSelect configured with the given aggregations.
|
||||||
|
func (bq *BusinessQuery) Aggregate(fns ...AggregateFunc) *BusinessSelect {
|
||||||
|
return bq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bq *BusinessQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range bq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, bq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range bq.ctx.Fields {
|
||||||
|
if !business.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if bq.path != nil {
|
||||||
|
prev, err := bq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
bq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bq *BusinessQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Business, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Business{}
|
||||||
|
_spec = bq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
bq.withBusinessCategory != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*Business).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &Business{config: bq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, bq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := bq.withBusinessCategory; query != nil {
|
||||||
|
if err := bq.loadBusinessCategory(ctx, query, nodes,
|
||||||
|
func(n *Business) { n.Edges.BusinessCategory = []*BusinessCategory{} },
|
||||||
|
func(n *Business, e *BusinessCategory) { n.Edges.BusinessCategory = append(n.Edges.BusinessCategory, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bq *BusinessQuery) loadBusinessCategory(ctx context.Context, query *BusinessCategoryQuery, nodes []*Business, init func(*Business), assign func(*Business, *BusinessCategory)) error {
|
||||||
|
edgeIDs := make([]driver.Value, len(nodes))
|
||||||
|
byID := make(map[int]*Business)
|
||||||
|
nids := make(map[int]map[*Business]struct{})
|
||||||
|
for i, node := range nodes {
|
||||||
|
edgeIDs[i] = node.ID
|
||||||
|
byID[node.ID] = node
|
||||||
|
if init != nil {
|
||||||
|
init(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.Where(func(s *sql.Selector) {
|
||||||
|
joinT := sql.Table(business.BusinessCategoryTable)
|
||||||
|
s.Join(joinT).On(s.C(businesscategory.FieldID), joinT.C(business.BusinessCategoryPrimaryKey[0]))
|
||||||
|
s.Where(sql.InValues(joinT.C(business.BusinessCategoryPrimaryKey[1]), edgeIDs...))
|
||||||
|
columns := s.SelectedColumns()
|
||||||
|
s.Select(joinT.C(business.BusinessCategoryPrimaryKey[1]))
|
||||||
|
s.AppendSelect(columns...)
|
||||||
|
s.SetDistinct(false)
|
||||||
|
})
|
||||||
|
if err := query.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||||
|
assign := spec.Assign
|
||||||
|
values := spec.ScanValues
|
||||||
|
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
values, err := values(columns[1:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||||
|
}
|
||||||
|
spec.Assign = func(columns []string, values []any) error {
|
||||||
|
outValue := int(values[0].(*sql.NullInt64).Int64)
|
||||||
|
inValue := int(values[1].(*sql.NullInt64).Int64)
|
||||||
|
if nids[inValue] == nil {
|
||||||
|
nids[inValue] = map[*Business]struct{}{byID[outValue]: {}}
|
||||||
|
return assign(columns[1:], values[1:])
|
||||||
|
}
|
||||||
|
nids[inValue][byID[outValue]] = struct{}{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
neighbors, err := withInterceptors[[]*BusinessCategory](ctx, query, qr, query.inters)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected "businessCategory" node returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for kn := range nodes {
|
||||||
|
assign(kn, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bq *BusinessQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := bq.querySpec()
|
||||||
|
_spec.Node.Columns = bq.ctx.Fields
|
||||||
|
if len(bq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = bq.ctx.Unique != nil && *bq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, bq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bq *BusinessQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(business.Table, business.Columns, sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt))
|
||||||
|
_spec.From = bq.sql
|
||||||
|
if unique := bq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if bq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := bq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, business.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != business.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := bq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := bq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := bq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := bq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bq *BusinessQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(bq.driver.Dialect())
|
||||||
|
t1 := builder.Table(business.Table)
|
||||||
|
columns := bq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = business.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if bq.sql != nil {
|
||||||
|
selector = bq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if bq.ctx.Unique != nil && *bq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range bq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range bq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := bq.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := bq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessGroupBy is the group-by builder for Business entities.
|
||||||
|
type BusinessGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *BusinessQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (bgb *BusinessGroupBy) Aggregate(fns ...AggregateFunc) *BusinessGroupBy {
|
||||||
|
bgb.fns = append(bgb.fns, fns...)
|
||||||
|
return bgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (bgb *BusinessGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, bgb.build.ctx, "GroupBy")
|
||||||
|
if err := bgb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*BusinessQuery, *BusinessGroupBy](ctx, bgb.build, bgb, bgb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bgb *BusinessGroupBy) sqlScan(ctx context.Context, root *BusinessQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(bgb.fns))
|
||||||
|
for _, fn := range bgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*bgb.flds)+len(bgb.fns))
|
||||||
|
for _, f := range *bgb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*bgb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := bgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessSelect is the builder for selecting fields of Business entities.
|
||||||
|
type BusinessSelect struct {
|
||||||
|
*BusinessQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (bs *BusinessSelect) Aggregate(fns ...AggregateFunc) *BusinessSelect {
|
||||||
|
bs.fns = append(bs.fns, fns...)
|
||||||
|
return bs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (bs *BusinessSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, bs.ctx, "Select")
|
||||||
|
if err := bs.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*BusinessQuery, *BusinessSelect](ctx, bs.BusinessQuery, bs, bs.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bs *BusinessSelect) sqlScan(ctx context.Context, root *BusinessQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(bs.fns))
|
||||||
|
for _, fn := range bs.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*bs.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := bs.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
617
ent/business_update.go
Normal file
617
ent/business_update.go
Normal file
@ -0,0 +1,617 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessUpdate is the builder for updating Business entities.
|
||||||
|
type BusinessUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *BusinessMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the BusinessUpdate builder.
|
||||||
|
func (bu *BusinessUpdate) Where(ps ...predicate.Business) *BusinessUpdate {
|
||||||
|
bu.mutation.Where(ps...)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (bu *BusinessUpdate) SetName(s string) *BusinessUpdate {
|
||||||
|
bu.mutation.SetName(s)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (bu *BusinessUpdate) SetNillableName(s *string) *BusinessUpdate {
|
||||||
|
if s != nil {
|
||||||
|
bu.SetName(*s)
|
||||||
|
}
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (bu *BusinessUpdate) SetSlug(s string) *BusinessUpdate {
|
||||||
|
bu.mutation.SetSlug(s)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBotID sets the "bot_id" field.
|
||||||
|
func (bu *BusinessUpdate) SetBotID(s string) *BusinessUpdate {
|
||||||
|
bu.mutation.SetBotID(s)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (bu *BusinessUpdate) SetDescription(s string) *BusinessUpdate {
|
||||||
|
bu.mutation.SetDescription(s)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (bu *BusinessUpdate) SetNillableDescription(s *string) *BusinessUpdate {
|
||||||
|
if s != nil {
|
||||||
|
bu.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (bu *BusinessUpdate) ClearDescription() *BusinessUpdate {
|
||||||
|
bu.mutation.ClearDescription()
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCompany sets the "company" field.
|
||||||
|
func (bu *BusinessUpdate) SetCompany(s string) *BusinessUpdate {
|
||||||
|
bu.mutation.SetCompany(s)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCompany sets the "company" field if the given value is not nil.
|
||||||
|
func (bu *BusinessUpdate) SetNillableCompany(s *string) *BusinessUpdate {
|
||||||
|
if s != nil {
|
||||||
|
bu.SetCompany(*s)
|
||||||
|
}
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAboutUs sets the "about_us" field.
|
||||||
|
func (bu *BusinessUpdate) SetAboutUs(s string) *BusinessUpdate {
|
||||||
|
bu.mutation.SetAboutUs(s)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAboutUs sets the "about_us" field if the given value is not nil.
|
||||||
|
func (bu *BusinessUpdate) SetNillableAboutUs(s *string) *BusinessUpdate {
|
||||||
|
if s != nil {
|
||||||
|
bu.SetAboutUs(*s)
|
||||||
|
}
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAboutUs clears the value of the "about_us" field.
|
||||||
|
func (bu *BusinessUpdate) ClearAboutUs() *BusinessUpdate {
|
||||||
|
bu.mutation.ClearAboutUs()
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (bu *BusinessUpdate) SetCreatedAt(t time.Time) *BusinessUpdate {
|
||||||
|
bu.mutation.SetCreatedAt(t)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (bu *BusinessUpdate) SetNillableCreatedAt(t *time.Time) *BusinessUpdate {
|
||||||
|
if t != nil {
|
||||||
|
bu.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (bu *BusinessUpdate) SetUpdatedAt(t time.Time) *BusinessUpdate {
|
||||||
|
bu.mutation.SetUpdatedAt(t)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessCategoryIDs adds the "businessCategory" edge to the BusinessCategory entity by IDs.
|
||||||
|
func (bu *BusinessUpdate) AddBusinessCategoryIDs(ids ...int) *BusinessUpdate {
|
||||||
|
bu.mutation.AddBusinessCategoryIDs(ids...)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessCategory adds the "businessCategory" edges to the BusinessCategory entity.
|
||||||
|
func (bu *BusinessUpdate) AddBusinessCategory(b ...*BusinessCategory) *BusinessUpdate {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return bu.AddBusinessCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the BusinessMutation object of the builder.
|
||||||
|
func (bu *BusinessUpdate) Mutation() *BusinessMutation {
|
||||||
|
return bu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearBusinessCategory clears all "businessCategory" edges to the BusinessCategory entity.
|
||||||
|
func (bu *BusinessUpdate) ClearBusinessCategory() *BusinessUpdate {
|
||||||
|
bu.mutation.ClearBusinessCategory()
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveBusinessCategoryIDs removes the "businessCategory" edge to BusinessCategory entities by IDs.
|
||||||
|
func (bu *BusinessUpdate) RemoveBusinessCategoryIDs(ids ...int) *BusinessUpdate {
|
||||||
|
bu.mutation.RemoveBusinessCategoryIDs(ids...)
|
||||||
|
return bu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveBusinessCategory removes "businessCategory" edges to BusinessCategory entities.
|
||||||
|
func (bu *BusinessUpdate) RemoveBusinessCategory(b ...*BusinessCategory) *BusinessUpdate {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return bu.RemoveBusinessCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (bu *BusinessUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
bu.defaults()
|
||||||
|
return withHooks(ctx, bu.sqlSave, bu.mutation, bu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (bu *BusinessUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := bu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (bu *BusinessUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := bu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bu *BusinessUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := bu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (bu *BusinessUpdate) defaults() {
|
||||||
|
if _, ok := bu.mutation.UpdatedAt(); !ok {
|
||||||
|
v := business.UpdateDefaultUpdatedAt()
|
||||||
|
bu.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bu *BusinessUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(business.Table, business.Columns, sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt))
|
||||||
|
if ps := bu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := bu.mutation.Name(); ok {
|
||||||
|
_spec.SetField(business.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := bu.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(business.FieldSlug, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := bu.mutation.BotID(); ok {
|
||||||
|
_spec.SetField(business.FieldBotID, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := bu.mutation.Description(); ok {
|
||||||
|
_spec.SetField(business.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if bu.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(business.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := bu.mutation.Company(); ok {
|
||||||
|
_spec.SetField(business.FieldCompany, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := bu.mutation.AboutUs(); ok {
|
||||||
|
_spec.SetField(business.FieldAboutUs, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if bu.mutation.AboutUsCleared() {
|
||||||
|
_spec.ClearField(business.FieldAboutUs, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := bu.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(business.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := bu.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(business.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if bu.mutation.BusinessCategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: business.BusinessCategoryTable,
|
||||||
|
Columns: business.BusinessCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := bu.mutation.RemovedBusinessCategoryIDs(); len(nodes) > 0 && !bu.mutation.BusinessCategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: business.BusinessCategoryTable,
|
||||||
|
Columns: business.BusinessCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := bu.mutation.BusinessCategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: business.BusinessCategoryTable,
|
||||||
|
Columns: business.BusinessCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, bu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{business.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
bu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessUpdateOne is the builder for updating a single Business entity.
|
||||||
|
type BusinessUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *BusinessMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (buo *BusinessUpdateOne) SetName(s string) *BusinessUpdateOne {
|
||||||
|
buo.mutation.SetName(s)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (buo *BusinessUpdateOne) SetNillableName(s *string) *BusinessUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
buo.SetName(*s)
|
||||||
|
}
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (buo *BusinessUpdateOne) SetSlug(s string) *BusinessUpdateOne {
|
||||||
|
buo.mutation.SetSlug(s)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBotID sets the "bot_id" field.
|
||||||
|
func (buo *BusinessUpdateOne) SetBotID(s string) *BusinessUpdateOne {
|
||||||
|
buo.mutation.SetBotID(s)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (buo *BusinessUpdateOne) SetDescription(s string) *BusinessUpdateOne {
|
||||||
|
buo.mutation.SetDescription(s)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (buo *BusinessUpdateOne) SetNillableDescription(s *string) *BusinessUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
buo.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (buo *BusinessUpdateOne) ClearDescription() *BusinessUpdateOne {
|
||||||
|
buo.mutation.ClearDescription()
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCompany sets the "company" field.
|
||||||
|
func (buo *BusinessUpdateOne) SetCompany(s string) *BusinessUpdateOne {
|
||||||
|
buo.mutation.SetCompany(s)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCompany sets the "company" field if the given value is not nil.
|
||||||
|
func (buo *BusinessUpdateOne) SetNillableCompany(s *string) *BusinessUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
buo.SetCompany(*s)
|
||||||
|
}
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAboutUs sets the "about_us" field.
|
||||||
|
func (buo *BusinessUpdateOne) SetAboutUs(s string) *BusinessUpdateOne {
|
||||||
|
buo.mutation.SetAboutUs(s)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAboutUs sets the "about_us" field if the given value is not nil.
|
||||||
|
func (buo *BusinessUpdateOne) SetNillableAboutUs(s *string) *BusinessUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
buo.SetAboutUs(*s)
|
||||||
|
}
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAboutUs clears the value of the "about_us" field.
|
||||||
|
func (buo *BusinessUpdateOne) ClearAboutUs() *BusinessUpdateOne {
|
||||||
|
buo.mutation.ClearAboutUs()
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (buo *BusinessUpdateOne) SetCreatedAt(t time.Time) *BusinessUpdateOne {
|
||||||
|
buo.mutation.SetCreatedAt(t)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (buo *BusinessUpdateOne) SetNillableCreatedAt(t *time.Time) *BusinessUpdateOne {
|
||||||
|
if t != nil {
|
||||||
|
buo.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (buo *BusinessUpdateOne) SetUpdatedAt(t time.Time) *BusinessUpdateOne {
|
||||||
|
buo.mutation.SetUpdatedAt(t)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessCategoryIDs adds the "businessCategory" edge to the BusinessCategory entity by IDs.
|
||||||
|
func (buo *BusinessUpdateOne) AddBusinessCategoryIDs(ids ...int) *BusinessUpdateOne {
|
||||||
|
buo.mutation.AddBusinessCategoryIDs(ids...)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessCategory adds the "businessCategory" edges to the BusinessCategory entity.
|
||||||
|
func (buo *BusinessUpdateOne) AddBusinessCategory(b ...*BusinessCategory) *BusinessUpdateOne {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return buo.AddBusinessCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the BusinessMutation object of the builder.
|
||||||
|
func (buo *BusinessUpdateOne) Mutation() *BusinessMutation {
|
||||||
|
return buo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearBusinessCategory clears all "businessCategory" edges to the BusinessCategory entity.
|
||||||
|
func (buo *BusinessUpdateOne) ClearBusinessCategory() *BusinessUpdateOne {
|
||||||
|
buo.mutation.ClearBusinessCategory()
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveBusinessCategoryIDs removes the "businessCategory" edge to BusinessCategory entities by IDs.
|
||||||
|
func (buo *BusinessUpdateOne) RemoveBusinessCategoryIDs(ids ...int) *BusinessUpdateOne {
|
||||||
|
buo.mutation.RemoveBusinessCategoryIDs(ids...)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveBusinessCategory removes "businessCategory" edges to BusinessCategory entities.
|
||||||
|
func (buo *BusinessUpdateOne) RemoveBusinessCategory(b ...*BusinessCategory) *BusinessUpdateOne {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return buo.RemoveBusinessCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the BusinessUpdate builder.
|
||||||
|
func (buo *BusinessUpdateOne) Where(ps ...predicate.Business) *BusinessUpdateOne {
|
||||||
|
buo.mutation.Where(ps...)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (buo *BusinessUpdateOne) Select(field string, fields ...string) *BusinessUpdateOne {
|
||||||
|
buo.fields = append([]string{field}, fields...)
|
||||||
|
return buo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Business entity.
|
||||||
|
func (buo *BusinessUpdateOne) Save(ctx context.Context) (*Business, error) {
|
||||||
|
buo.defaults()
|
||||||
|
return withHooks(ctx, buo.sqlSave, buo.mutation, buo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (buo *BusinessUpdateOne) SaveX(ctx context.Context) *Business {
|
||||||
|
node, err := buo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (buo *BusinessUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := buo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (buo *BusinessUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := buo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (buo *BusinessUpdateOne) defaults() {
|
||||||
|
if _, ok := buo.mutation.UpdatedAt(); !ok {
|
||||||
|
v := business.UpdateDefaultUpdatedAt()
|
||||||
|
buo.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (buo *BusinessUpdateOne) sqlSave(ctx context.Context) (_node *Business, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(business.Table, business.Columns, sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt))
|
||||||
|
id, ok := buo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Business.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := buo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, business.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !business.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != business.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := buo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := buo.mutation.Name(); ok {
|
||||||
|
_spec.SetField(business.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := buo.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(business.FieldSlug, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := buo.mutation.BotID(); ok {
|
||||||
|
_spec.SetField(business.FieldBotID, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := buo.mutation.Description(); ok {
|
||||||
|
_spec.SetField(business.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if buo.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(business.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := buo.mutation.Company(); ok {
|
||||||
|
_spec.SetField(business.FieldCompany, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := buo.mutation.AboutUs(); ok {
|
||||||
|
_spec.SetField(business.FieldAboutUs, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if buo.mutation.AboutUsCleared() {
|
||||||
|
_spec.ClearField(business.FieldAboutUs, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := buo.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(business.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := buo.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(business.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if buo.mutation.BusinessCategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: business.BusinessCategoryTable,
|
||||||
|
Columns: business.BusinessCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := buo.mutation.RemovedBusinessCategoryIDs(); len(nodes) > 0 && !buo.mutation.BusinessCategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: business.BusinessCategoryTable,
|
||||||
|
Columns: business.BusinessCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := buo.mutation.BusinessCategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: business.BusinessCategoryTable,
|
||||||
|
Columns: business.BusinessCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Business{config: buo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, buo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{business.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
buo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
151
ent/businesscategory.go
Normal file
151
ent/businesscategory.go
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
// 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
|
105
ent/businesscategory/businesscategory.go
Normal file
105
ent/businesscategory/businesscategory.go
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package businesscategory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the businesscategory type in the database.
|
||||||
|
Label = "business_category"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldSlug holds the string denoting the slug field in the database.
|
||||||
|
FieldSlug = "slug"
|
||||||
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
FieldName = "name"
|
||||||
|
// FieldDescription holds the string denoting the description field in the database.
|
||||||
|
FieldDescription = "description"
|
||||||
|
// EdgeBusinesses holds the string denoting the businesses edge name in mutations.
|
||||||
|
EdgeBusinesses = "businesses"
|
||||||
|
// Table holds the table name of the businesscategory in the database.
|
||||||
|
Table = "business_categories"
|
||||||
|
// BusinessesTable is the table that holds the businesses relation/edge. The primary key declared below.
|
||||||
|
BusinessesTable = "business_category_businesses"
|
||||||
|
// BusinessesInverseTable is the table name for the Business entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "business" package.
|
||||||
|
BusinessesInverseTable = "businesses"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for businesscategory fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldSlug,
|
||||||
|
FieldName,
|
||||||
|
FieldDescription,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// BusinessesPrimaryKey and BusinessesColumn2 are the table columns denoting the
|
||||||
|
// primary key for the businesses relation (M2M).
|
||||||
|
BusinessesPrimaryKey = []string{"business_category_id", "business_id"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultName holds the default value on creation for the "name" field.
|
||||||
|
DefaultName string
|
||||||
|
// DefaultDescription holds the default value on creation for the "description" field.
|
||||||
|
DefaultDescription string
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the BusinessCategory queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// BySlug orders the results by the slug field.
|
||||||
|
func BySlug(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldSlug, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByName orders the results by the name field.
|
||||||
|
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDescription orders the results by the description field.
|
||||||
|
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBusinessesCount orders the results by businesses count.
|
||||||
|
func ByBusinessesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newBusinessesStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBusinesses orders the results by businesses terms.
|
||||||
|
func ByBusinesses(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newBusinessesStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newBusinessesStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(BusinessesInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, BusinessesTable, BusinessesPrimaryKey...),
|
||||||
|
)
|
||||||
|
}
|
303
ent/businesscategory/where.go
Normal file
303
ent/businesscategory/where.go
Normal file
@ -0,0 +1,303 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package businesscategory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slug applies equality check predicate on the "slug" field. It's identical to SlugEQ.
|
||||||
|
func Slug(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||||
|
func Name(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||||
|
func Description(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugEQ applies the EQ predicate on the "slug" field.
|
||||||
|
func SlugEQ(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugNEQ applies the NEQ predicate on the "slug" field.
|
||||||
|
func SlugNEQ(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldNEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugIn applies the In predicate on the "slug" field.
|
||||||
|
func SlugIn(vs ...string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldIn(FieldSlug, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugNotIn applies the NotIn predicate on the "slug" field.
|
||||||
|
func SlugNotIn(vs ...string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldNotIn(FieldSlug, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugGT applies the GT predicate on the "slug" field.
|
||||||
|
func SlugGT(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldGT(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugGTE applies the GTE predicate on the "slug" field.
|
||||||
|
func SlugGTE(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldGTE(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugLT applies the LT predicate on the "slug" field.
|
||||||
|
func SlugLT(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldLT(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugLTE applies the LTE predicate on the "slug" field.
|
||||||
|
func SlugLTE(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldLTE(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugContains applies the Contains predicate on the "slug" field.
|
||||||
|
func SlugContains(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldContains(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugHasPrefix applies the HasPrefix predicate on the "slug" field.
|
||||||
|
func SlugHasPrefix(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldHasPrefix(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugHasSuffix applies the HasSuffix predicate on the "slug" field.
|
||||||
|
func SlugHasSuffix(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldHasSuffix(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugEqualFold applies the EqualFold predicate on the "slug" field.
|
||||||
|
func SlugEqualFold(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEqualFold(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugContainsFold applies the ContainsFold predicate on the "slug" field.
|
||||||
|
func SlugContainsFold(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldContainsFold(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEQ applies the EQ predicate on the "name" field.
|
||||||
|
func NameEQ(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||||
|
func NameNEQ(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldNEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameIn applies the In predicate on the "name" field.
|
||||||
|
func NameIn(vs ...string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||||
|
func NameNotIn(vs ...string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldNotIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGT applies the GT predicate on the "name" field.
|
||||||
|
func NameGT(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldGT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGTE applies the GTE predicate on the "name" field.
|
||||||
|
func NameGTE(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldGTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLT applies the LT predicate on the "name" field.
|
||||||
|
func NameLT(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldLT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLTE applies the LTE predicate on the "name" field.
|
||||||
|
func NameLTE(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldLTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContains applies the Contains predicate on the "name" field.
|
||||||
|
func NameContains(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldContains(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||||
|
func NameHasPrefix(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldHasPrefix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||||
|
func NameHasSuffix(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldHasSuffix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||||
|
func NameEqualFold(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEqualFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||||
|
func NameContainsFold(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldContainsFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||||
|
func DescriptionEQ(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||||
|
func DescriptionNEQ(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldNEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIn applies the In predicate on the "description" field.
|
||||||
|
func DescriptionIn(vs ...string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||||
|
func DescriptionNotIn(vs ...string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldNotIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGT applies the GT predicate on the "description" field.
|
||||||
|
func DescriptionGT(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldGT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||||
|
func DescriptionGTE(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldGTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLT applies the LT predicate on the "description" field.
|
||||||
|
func DescriptionLT(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldLT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||||
|
func DescriptionLTE(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldLTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||||
|
func DescriptionContains(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldContains(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||||
|
func DescriptionHasPrefix(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldHasPrefix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||||
|
func DescriptionHasSuffix(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldHasSuffix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||||
|
func DescriptionEqualFold(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldEqualFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||||
|
func DescriptionContainsFold(v string) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.FieldContainsFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasBusinesses applies the HasEdge predicate on the "businesses" edge.
|
||||||
|
func HasBusinesses() predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, BusinessesTable, BusinessesPrimaryKey...),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasBusinessesWith applies the HasEdge predicate on the "businesses" edge with a given conditions (other predicates).
|
||||||
|
func HasBusinessesWith(preds ...predicate.Business) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(func(s *sql.Selector) {
|
||||||
|
step := newBusinessesStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.BusinessCategory) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.BusinessCategory) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.BusinessCategory) predicate.BusinessCategory {
|
||||||
|
return predicate.BusinessCategory(sql.NotPredicates(p))
|
||||||
|
}
|
271
ent/businesscategory_create.go
Normal file
271
ent/businesscategory_create.go
Normal file
@ -0,0 +1,271 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessCategoryCreate is the builder for creating a BusinessCategory entity.
|
||||||
|
type BusinessCategoryCreate struct {
|
||||||
|
config
|
||||||
|
mutation *BusinessCategoryMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (bcc *BusinessCategoryCreate) SetSlug(s string) *BusinessCategoryCreate {
|
||||||
|
bcc.mutation.SetSlug(s)
|
||||||
|
return bcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (bcc *BusinessCategoryCreate) SetName(s string) *BusinessCategoryCreate {
|
||||||
|
bcc.mutation.SetName(s)
|
||||||
|
return bcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (bcc *BusinessCategoryCreate) SetNillableName(s *string) *BusinessCategoryCreate {
|
||||||
|
if s != nil {
|
||||||
|
bcc.SetName(*s)
|
||||||
|
}
|
||||||
|
return bcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (bcc *BusinessCategoryCreate) SetDescription(s string) *BusinessCategoryCreate {
|
||||||
|
bcc.mutation.SetDescription(s)
|
||||||
|
return bcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (bcc *BusinessCategoryCreate) SetNillableDescription(s *string) *BusinessCategoryCreate {
|
||||||
|
if s != nil {
|
||||||
|
bcc.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return bcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessIDs adds the "businesses" edge to the Business entity by IDs.
|
||||||
|
func (bcc *BusinessCategoryCreate) AddBusinessIDs(ids ...int) *BusinessCategoryCreate {
|
||||||
|
bcc.mutation.AddBusinessIDs(ids...)
|
||||||
|
return bcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinesses adds the "businesses" edges to the Business entity.
|
||||||
|
func (bcc *BusinessCategoryCreate) AddBusinesses(b ...*Business) *BusinessCategoryCreate {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return bcc.AddBusinessIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the BusinessCategoryMutation object of the builder.
|
||||||
|
func (bcc *BusinessCategoryCreate) Mutation() *BusinessCategoryMutation {
|
||||||
|
return bcc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the BusinessCategory in the database.
|
||||||
|
func (bcc *BusinessCategoryCreate) Save(ctx context.Context) (*BusinessCategory, error) {
|
||||||
|
bcc.defaults()
|
||||||
|
return withHooks(ctx, bcc.sqlSave, bcc.mutation, bcc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (bcc *BusinessCategoryCreate) SaveX(ctx context.Context) *BusinessCategory {
|
||||||
|
v, err := bcc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (bcc *BusinessCategoryCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := bcc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bcc *BusinessCategoryCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := bcc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (bcc *BusinessCategoryCreate) defaults() {
|
||||||
|
if _, ok := bcc.mutation.Name(); !ok {
|
||||||
|
v := businesscategory.DefaultName
|
||||||
|
bcc.mutation.SetName(v)
|
||||||
|
}
|
||||||
|
if _, ok := bcc.mutation.Description(); !ok {
|
||||||
|
v := businesscategory.DefaultDescription
|
||||||
|
bcc.mutation.SetDescription(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (bcc *BusinessCategoryCreate) check() error {
|
||||||
|
if _, ok := bcc.mutation.Slug(); !ok {
|
||||||
|
return &ValidationError{Name: "slug", err: errors.New(`ent: missing required field "BusinessCategory.slug"`)}
|
||||||
|
}
|
||||||
|
if _, ok := bcc.mutation.Name(); !ok {
|
||||||
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "BusinessCategory.name"`)}
|
||||||
|
}
|
||||||
|
if _, ok := bcc.mutation.Description(); !ok {
|
||||||
|
return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "BusinessCategory.description"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcc *BusinessCategoryCreate) sqlSave(ctx context.Context) (*BusinessCategory, error) {
|
||||||
|
if err := bcc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := bcc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, bcc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int(id)
|
||||||
|
bcc.mutation.id = &_node.ID
|
||||||
|
bcc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcc *BusinessCategoryCreate) createSpec() (*BusinessCategory, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &BusinessCategory{config: bcc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(businesscategory.Table, sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt))
|
||||||
|
)
|
||||||
|
if value, ok := bcc.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldSlug, field.TypeString, value)
|
||||||
|
_node.Slug = value
|
||||||
|
}
|
||||||
|
if value, ok := bcc.mutation.Name(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldName, field.TypeString, value)
|
||||||
|
_node.Name = value
|
||||||
|
}
|
||||||
|
if value, ok := bcc.mutation.Description(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldDescription, field.TypeString, value)
|
||||||
|
_node.Description = value
|
||||||
|
}
|
||||||
|
if nodes := bcc.mutation.BusinessesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: businesscategory.BusinessesTable,
|
||||||
|
Columns: businesscategory.BusinessesPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessCategoryCreateBulk is the builder for creating many BusinessCategory entities in bulk.
|
||||||
|
type BusinessCategoryCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*BusinessCategoryCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the BusinessCategory entities in the database.
|
||||||
|
func (bccb *BusinessCategoryCreateBulk) Save(ctx context.Context) ([]*BusinessCategory, error) {
|
||||||
|
if bccb.err != nil {
|
||||||
|
return nil, bccb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(bccb.builders))
|
||||||
|
nodes := make([]*BusinessCategory, len(bccb.builders))
|
||||||
|
mutators := make([]Mutator, len(bccb.builders))
|
||||||
|
for i := range bccb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := bccb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*BusinessCategoryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, bccb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, bccb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, bccb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (bccb *BusinessCategoryCreateBulk) SaveX(ctx context.Context) []*BusinessCategory {
|
||||||
|
v, err := bccb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (bccb *BusinessCategoryCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := bccb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bccb *BusinessCategoryCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := bccb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
88
ent/businesscategory_delete.go
Normal file
88
ent/businesscategory_delete.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessCategoryDelete is the builder for deleting a BusinessCategory entity.
|
||||||
|
type BusinessCategoryDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *BusinessCategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the BusinessCategoryDelete builder.
|
||||||
|
func (bcd *BusinessCategoryDelete) Where(ps ...predicate.BusinessCategory) *BusinessCategoryDelete {
|
||||||
|
bcd.mutation.Where(ps...)
|
||||||
|
return bcd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (bcd *BusinessCategoryDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, bcd.sqlExec, bcd.mutation, bcd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bcd *BusinessCategoryDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := bcd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcd *BusinessCategoryDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(businesscategory.Table, sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt))
|
||||||
|
if ps := bcd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, bcd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
bcd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessCategoryDeleteOne is the builder for deleting a single BusinessCategory entity.
|
||||||
|
type BusinessCategoryDeleteOne struct {
|
||||||
|
bcd *BusinessCategoryDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the BusinessCategoryDelete builder.
|
||||||
|
func (bcdo *BusinessCategoryDeleteOne) Where(ps ...predicate.BusinessCategory) *BusinessCategoryDeleteOne {
|
||||||
|
bcdo.bcd.mutation.Where(ps...)
|
||||||
|
return bcdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (bcdo *BusinessCategoryDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := bcdo.bcd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{businesscategory.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bcdo *BusinessCategoryDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := bcdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
636
ent/businesscategory_query.go
Normal file
636
ent/businesscategory_query.go
Normal file
@ -0,0 +1,636 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessCategoryQuery is the builder for querying BusinessCategory entities.
|
||||||
|
type BusinessCategoryQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []businesscategory.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.BusinessCategory
|
||||||
|
withBusinesses *BusinessQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the BusinessCategoryQuery builder.
|
||||||
|
func (bcq *BusinessCategoryQuery) Where(ps ...predicate.BusinessCategory) *BusinessCategoryQuery {
|
||||||
|
bcq.predicates = append(bcq.predicates, ps...)
|
||||||
|
return bcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (bcq *BusinessCategoryQuery) Limit(limit int) *BusinessCategoryQuery {
|
||||||
|
bcq.ctx.Limit = &limit
|
||||||
|
return bcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (bcq *BusinessCategoryQuery) Offset(offset int) *BusinessCategoryQuery {
|
||||||
|
bcq.ctx.Offset = &offset
|
||||||
|
return bcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (bcq *BusinessCategoryQuery) Unique(unique bool) *BusinessCategoryQuery {
|
||||||
|
bcq.ctx.Unique = &unique
|
||||||
|
return bcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (bcq *BusinessCategoryQuery) Order(o ...businesscategory.OrderOption) *BusinessCategoryQuery {
|
||||||
|
bcq.order = append(bcq.order, o...)
|
||||||
|
return bcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryBusinesses chains the current query on the "businesses" edge.
|
||||||
|
func (bcq *BusinessCategoryQuery) QueryBusinesses() *BusinessQuery {
|
||||||
|
query := (&BusinessClient{config: bcq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := bcq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := bcq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(businesscategory.Table, businesscategory.FieldID, selector),
|
||||||
|
sqlgraph.To(business.Table, business.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, businesscategory.BusinessesTable, businesscategory.BusinessesPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(bcq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first BusinessCategory entity from the query.
|
||||||
|
// Returns a *NotFoundError when no BusinessCategory was found.
|
||||||
|
func (bcq *BusinessCategoryQuery) First(ctx context.Context) (*BusinessCategory, error) {
|
||||||
|
nodes, err := bcq.Limit(1).All(setContextOp(ctx, bcq.ctx, "First"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{businesscategory.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (bcq *BusinessCategoryQuery) FirstX(ctx context.Context) *BusinessCategory {
|
||||||
|
node, err := bcq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first BusinessCategory ID from the query.
|
||||||
|
// Returns a *NotFoundError when no BusinessCategory ID was found.
|
||||||
|
func (bcq *BusinessCategoryQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = bcq.Limit(1).IDs(setContextOp(ctx, bcq.ctx, "FirstID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{businesscategory.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (bcq *BusinessCategoryQuery) FirstIDX(ctx context.Context) int {
|
||||||
|
id, err := bcq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single BusinessCategory entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one BusinessCategory entity is found.
|
||||||
|
// Returns a *NotFoundError when no BusinessCategory entities are found.
|
||||||
|
func (bcq *BusinessCategoryQuery) Only(ctx context.Context) (*BusinessCategory, error) {
|
||||||
|
nodes, err := bcq.Limit(2).All(setContextOp(ctx, bcq.ctx, "Only"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{businesscategory.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{businesscategory.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (bcq *BusinessCategoryQuery) OnlyX(ctx context.Context) *BusinessCategory {
|
||||||
|
node, err := bcq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only BusinessCategory ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one BusinessCategory ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (bcq *BusinessCategoryQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = bcq.Limit(2).IDs(setContextOp(ctx, bcq.ctx, "OnlyID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{businesscategory.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{businesscategory.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (bcq *BusinessCategoryQuery) OnlyIDX(ctx context.Context) int {
|
||||||
|
id, err := bcq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of BusinessCategories.
|
||||||
|
func (bcq *BusinessCategoryQuery) All(ctx context.Context) ([]*BusinessCategory, error) {
|
||||||
|
ctx = setContextOp(ctx, bcq.ctx, "All")
|
||||||
|
if err := bcq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*BusinessCategory, *BusinessCategoryQuery]()
|
||||||
|
return withInterceptors[[]*BusinessCategory](ctx, bcq, qr, bcq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (bcq *BusinessCategoryQuery) AllX(ctx context.Context) []*BusinessCategory {
|
||||||
|
nodes, err := bcq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of BusinessCategory IDs.
|
||||||
|
func (bcq *BusinessCategoryQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||||
|
if bcq.ctx.Unique == nil && bcq.path != nil {
|
||||||
|
bcq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, bcq.ctx, "IDs")
|
||||||
|
if err = bcq.Select(businesscategory.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (bcq *BusinessCategoryQuery) IDsX(ctx context.Context) []int {
|
||||||
|
ids, err := bcq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (bcq *BusinessCategoryQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, bcq.ctx, "Count")
|
||||||
|
if err := bcq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, bcq, querierCount[*BusinessCategoryQuery](), bcq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (bcq *BusinessCategoryQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := bcq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (bcq *BusinessCategoryQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, bcq.ctx, "Exist")
|
||||||
|
switch _, err := bcq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (bcq *BusinessCategoryQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := bcq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the BusinessCategoryQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (bcq *BusinessCategoryQuery) Clone() *BusinessCategoryQuery {
|
||||||
|
if bcq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &BusinessCategoryQuery{
|
||||||
|
config: bcq.config,
|
||||||
|
ctx: bcq.ctx.Clone(),
|
||||||
|
order: append([]businesscategory.OrderOption{}, bcq.order...),
|
||||||
|
inters: append([]Interceptor{}, bcq.inters...),
|
||||||
|
predicates: append([]predicate.BusinessCategory{}, bcq.predicates...),
|
||||||
|
withBusinesses: bcq.withBusinesses.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: bcq.sql.Clone(),
|
||||||
|
path: bcq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithBusinesses tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "businesses" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (bcq *BusinessCategoryQuery) WithBusinesses(opts ...func(*BusinessQuery)) *BusinessCategoryQuery {
|
||||||
|
query := (&BusinessClient{config: bcq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
bcq.withBusinesses = query
|
||||||
|
return bcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Slug string `json:"slug,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.BusinessCategory.Query().
|
||||||
|
// GroupBy(businesscategory.FieldSlug).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (bcq *BusinessCategoryQuery) GroupBy(field string, fields ...string) *BusinessCategoryGroupBy {
|
||||||
|
bcq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &BusinessCategoryGroupBy{build: bcq}
|
||||||
|
grbuild.flds = &bcq.ctx.Fields
|
||||||
|
grbuild.label = businesscategory.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Slug string `json:"slug,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.BusinessCategory.Query().
|
||||||
|
// Select(businesscategory.FieldSlug).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (bcq *BusinessCategoryQuery) Select(fields ...string) *BusinessCategorySelect {
|
||||||
|
bcq.ctx.Fields = append(bcq.ctx.Fields, fields...)
|
||||||
|
sbuild := &BusinessCategorySelect{BusinessCategoryQuery: bcq}
|
||||||
|
sbuild.label = businesscategory.Label
|
||||||
|
sbuild.flds, sbuild.scan = &bcq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a BusinessCategorySelect configured with the given aggregations.
|
||||||
|
func (bcq *BusinessCategoryQuery) Aggregate(fns ...AggregateFunc) *BusinessCategorySelect {
|
||||||
|
return bcq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcq *BusinessCategoryQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range bcq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, bcq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range bcq.ctx.Fields {
|
||||||
|
if !businesscategory.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if bcq.path != nil {
|
||||||
|
prev, err := bcq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
bcq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcq *BusinessCategoryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*BusinessCategory, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*BusinessCategory{}
|
||||||
|
_spec = bcq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
bcq.withBusinesses != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*BusinessCategory).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &BusinessCategory{config: bcq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, bcq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := bcq.withBusinesses; query != nil {
|
||||||
|
if err := bcq.loadBusinesses(ctx, query, nodes,
|
||||||
|
func(n *BusinessCategory) { n.Edges.Businesses = []*Business{} },
|
||||||
|
func(n *BusinessCategory, e *Business) { n.Edges.Businesses = append(n.Edges.Businesses, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcq *BusinessCategoryQuery) loadBusinesses(ctx context.Context, query *BusinessQuery, nodes []*BusinessCategory, init func(*BusinessCategory), assign func(*BusinessCategory, *Business)) error {
|
||||||
|
edgeIDs := make([]driver.Value, len(nodes))
|
||||||
|
byID := make(map[int]*BusinessCategory)
|
||||||
|
nids := make(map[int]map[*BusinessCategory]struct{})
|
||||||
|
for i, node := range nodes {
|
||||||
|
edgeIDs[i] = node.ID
|
||||||
|
byID[node.ID] = node
|
||||||
|
if init != nil {
|
||||||
|
init(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.Where(func(s *sql.Selector) {
|
||||||
|
joinT := sql.Table(businesscategory.BusinessesTable)
|
||||||
|
s.Join(joinT).On(s.C(business.FieldID), joinT.C(businesscategory.BusinessesPrimaryKey[1]))
|
||||||
|
s.Where(sql.InValues(joinT.C(businesscategory.BusinessesPrimaryKey[0]), edgeIDs...))
|
||||||
|
columns := s.SelectedColumns()
|
||||||
|
s.Select(joinT.C(businesscategory.BusinessesPrimaryKey[0]))
|
||||||
|
s.AppendSelect(columns...)
|
||||||
|
s.SetDistinct(false)
|
||||||
|
})
|
||||||
|
if err := query.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||||
|
assign := spec.Assign
|
||||||
|
values := spec.ScanValues
|
||||||
|
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
values, err := values(columns[1:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||||
|
}
|
||||||
|
spec.Assign = func(columns []string, values []any) error {
|
||||||
|
outValue := int(values[0].(*sql.NullInt64).Int64)
|
||||||
|
inValue := int(values[1].(*sql.NullInt64).Int64)
|
||||||
|
if nids[inValue] == nil {
|
||||||
|
nids[inValue] = map[*BusinessCategory]struct{}{byID[outValue]: {}}
|
||||||
|
return assign(columns[1:], values[1:])
|
||||||
|
}
|
||||||
|
nids[inValue][byID[outValue]] = struct{}{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
neighbors, err := withInterceptors[[]*Business](ctx, query, qr, query.inters)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected "businesses" node returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for kn := range nodes {
|
||||||
|
assign(kn, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcq *BusinessCategoryQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := bcq.querySpec()
|
||||||
|
_spec.Node.Columns = bcq.ctx.Fields
|
||||||
|
if len(bcq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = bcq.ctx.Unique != nil && *bcq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, bcq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcq *BusinessCategoryQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(businesscategory.Table, businesscategory.Columns, sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt))
|
||||||
|
_spec.From = bcq.sql
|
||||||
|
if unique := bcq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if bcq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := bcq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, businesscategory.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != businesscategory.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := bcq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := bcq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := bcq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := bcq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcq *BusinessCategoryQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(bcq.driver.Dialect())
|
||||||
|
t1 := builder.Table(businesscategory.Table)
|
||||||
|
columns := bcq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = businesscategory.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if bcq.sql != nil {
|
||||||
|
selector = bcq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if bcq.ctx.Unique != nil && *bcq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range bcq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range bcq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := bcq.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := bcq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessCategoryGroupBy is the group-by builder for BusinessCategory entities.
|
||||||
|
type BusinessCategoryGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *BusinessCategoryQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (bcgb *BusinessCategoryGroupBy) Aggregate(fns ...AggregateFunc) *BusinessCategoryGroupBy {
|
||||||
|
bcgb.fns = append(bcgb.fns, fns...)
|
||||||
|
return bcgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (bcgb *BusinessCategoryGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, bcgb.build.ctx, "GroupBy")
|
||||||
|
if err := bcgb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*BusinessCategoryQuery, *BusinessCategoryGroupBy](ctx, bcgb.build, bcgb, bcgb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcgb *BusinessCategoryGroupBy) sqlScan(ctx context.Context, root *BusinessCategoryQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(bcgb.fns))
|
||||||
|
for _, fn := range bcgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*bcgb.flds)+len(bcgb.fns))
|
||||||
|
for _, f := range *bcgb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*bcgb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := bcgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessCategorySelect is the builder for selecting fields of BusinessCategory entities.
|
||||||
|
type BusinessCategorySelect struct {
|
||||||
|
*BusinessCategoryQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (bcs *BusinessCategorySelect) Aggregate(fns ...AggregateFunc) *BusinessCategorySelect {
|
||||||
|
bcs.fns = append(bcs.fns, fns...)
|
||||||
|
return bcs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (bcs *BusinessCategorySelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, bcs.ctx, "Select")
|
||||||
|
if err := bcs.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*BusinessCategoryQuery, *BusinessCategorySelect](ctx, bcs.BusinessCategoryQuery, bcs, bcs.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcs *BusinessCategorySelect) sqlScan(ctx context.Context, root *BusinessCategoryQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(bcs.fns))
|
||||||
|
for _, fn := range bcs.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*bcs.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := bcs.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
424
ent/businesscategory_update.go
Normal file
424
ent/businesscategory_update.go
Normal file
@ -0,0 +1,424 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessCategoryUpdate is the builder for updating BusinessCategory entities.
|
||||||
|
type BusinessCategoryUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *BusinessCategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the BusinessCategoryUpdate builder.
|
||||||
|
func (bcu *BusinessCategoryUpdate) Where(ps ...predicate.BusinessCategory) *BusinessCategoryUpdate {
|
||||||
|
bcu.mutation.Where(ps...)
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (bcu *BusinessCategoryUpdate) SetSlug(s string) *BusinessCategoryUpdate {
|
||||||
|
bcu.mutation.SetSlug(s)
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (bcu *BusinessCategoryUpdate) SetName(s string) *BusinessCategoryUpdate {
|
||||||
|
bcu.mutation.SetName(s)
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (bcu *BusinessCategoryUpdate) SetNillableName(s *string) *BusinessCategoryUpdate {
|
||||||
|
if s != nil {
|
||||||
|
bcu.SetName(*s)
|
||||||
|
}
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (bcu *BusinessCategoryUpdate) SetDescription(s string) *BusinessCategoryUpdate {
|
||||||
|
bcu.mutation.SetDescription(s)
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (bcu *BusinessCategoryUpdate) SetNillableDescription(s *string) *BusinessCategoryUpdate {
|
||||||
|
if s != nil {
|
||||||
|
bcu.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessIDs adds the "businesses" edge to the Business entity by IDs.
|
||||||
|
func (bcu *BusinessCategoryUpdate) AddBusinessIDs(ids ...int) *BusinessCategoryUpdate {
|
||||||
|
bcu.mutation.AddBusinessIDs(ids...)
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinesses adds the "businesses" edges to the Business entity.
|
||||||
|
func (bcu *BusinessCategoryUpdate) AddBusinesses(b ...*Business) *BusinessCategoryUpdate {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return bcu.AddBusinessIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the BusinessCategoryMutation object of the builder.
|
||||||
|
func (bcu *BusinessCategoryUpdate) Mutation() *BusinessCategoryMutation {
|
||||||
|
return bcu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearBusinesses clears all "businesses" edges to the Business entity.
|
||||||
|
func (bcu *BusinessCategoryUpdate) ClearBusinesses() *BusinessCategoryUpdate {
|
||||||
|
bcu.mutation.ClearBusinesses()
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveBusinessIDs removes the "businesses" edge to Business entities by IDs.
|
||||||
|
func (bcu *BusinessCategoryUpdate) RemoveBusinessIDs(ids ...int) *BusinessCategoryUpdate {
|
||||||
|
bcu.mutation.RemoveBusinessIDs(ids...)
|
||||||
|
return bcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveBusinesses removes "businesses" edges to Business entities.
|
||||||
|
func (bcu *BusinessCategoryUpdate) RemoveBusinesses(b ...*Business) *BusinessCategoryUpdate {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return bcu.RemoveBusinessIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (bcu *BusinessCategoryUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, bcu.sqlSave, bcu.mutation, bcu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (bcu *BusinessCategoryUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := bcu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (bcu *BusinessCategoryUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := bcu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bcu *BusinessCategoryUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := bcu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcu *BusinessCategoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(businesscategory.Table, businesscategory.Columns, sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt))
|
||||||
|
if ps := bcu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := bcu.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldSlug, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := bcu.mutation.Name(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := bcu.mutation.Description(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if bcu.mutation.BusinessesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: businesscategory.BusinessesTable,
|
||||||
|
Columns: businesscategory.BusinessesPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := bcu.mutation.RemovedBusinessesIDs(); len(nodes) > 0 && !bcu.mutation.BusinessesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: businesscategory.BusinessesTable,
|
||||||
|
Columns: businesscategory.BusinessesPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := bcu.mutation.BusinessesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: businesscategory.BusinessesTable,
|
||||||
|
Columns: businesscategory.BusinessesPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, bcu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{businesscategory.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
bcu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessCategoryUpdateOne is the builder for updating a single BusinessCategory entity.
|
||||||
|
type BusinessCategoryUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *BusinessCategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) SetSlug(s string) *BusinessCategoryUpdateOne {
|
||||||
|
bcuo.mutation.SetSlug(s)
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) SetName(s string) *BusinessCategoryUpdateOne {
|
||||||
|
bcuo.mutation.SetName(s)
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) SetNillableName(s *string) *BusinessCategoryUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
bcuo.SetName(*s)
|
||||||
|
}
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) SetDescription(s string) *BusinessCategoryUpdateOne {
|
||||||
|
bcuo.mutation.SetDescription(s)
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) SetNillableDescription(s *string) *BusinessCategoryUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
bcuo.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinessIDs adds the "businesses" edge to the Business entity by IDs.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) AddBusinessIDs(ids ...int) *BusinessCategoryUpdateOne {
|
||||||
|
bcuo.mutation.AddBusinessIDs(ids...)
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBusinesses adds the "businesses" edges to the Business entity.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) AddBusinesses(b ...*Business) *BusinessCategoryUpdateOne {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return bcuo.AddBusinessIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the BusinessCategoryMutation object of the builder.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) Mutation() *BusinessCategoryMutation {
|
||||||
|
return bcuo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearBusinesses clears all "businesses" edges to the Business entity.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) ClearBusinesses() *BusinessCategoryUpdateOne {
|
||||||
|
bcuo.mutation.ClearBusinesses()
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveBusinessIDs removes the "businesses" edge to Business entities by IDs.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) RemoveBusinessIDs(ids ...int) *BusinessCategoryUpdateOne {
|
||||||
|
bcuo.mutation.RemoveBusinessIDs(ids...)
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveBusinesses removes "businesses" edges to Business entities.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) RemoveBusinesses(b ...*Business) *BusinessCategoryUpdateOne {
|
||||||
|
ids := make([]int, len(b))
|
||||||
|
for i := range b {
|
||||||
|
ids[i] = b[i].ID
|
||||||
|
}
|
||||||
|
return bcuo.RemoveBusinessIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the BusinessCategoryUpdate builder.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) Where(ps ...predicate.BusinessCategory) *BusinessCategoryUpdateOne {
|
||||||
|
bcuo.mutation.Where(ps...)
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) Select(field string, fields ...string) *BusinessCategoryUpdateOne {
|
||||||
|
bcuo.fields = append([]string{field}, fields...)
|
||||||
|
return bcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated BusinessCategory entity.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) Save(ctx context.Context) (*BusinessCategory, error) {
|
||||||
|
return withHooks(ctx, bcuo.sqlSave, bcuo.mutation, bcuo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) SaveX(ctx context.Context) *BusinessCategory {
|
||||||
|
node, err := bcuo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := bcuo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := bcuo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcuo *BusinessCategoryUpdateOne) sqlSave(ctx context.Context) (_node *BusinessCategory, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(businesscategory.Table, businesscategory.Columns, sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt))
|
||||||
|
id, ok := bcuo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BusinessCategory.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := bcuo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, businesscategory.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !businesscategory.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != businesscategory.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := bcuo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := bcuo.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldSlug, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := bcuo.mutation.Name(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := bcuo.mutation.Description(); ok {
|
||||||
|
_spec.SetField(businesscategory.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if bcuo.mutation.BusinessesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: businesscategory.BusinessesTable,
|
||||||
|
Columns: businesscategory.BusinessesPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := bcuo.mutation.RemovedBusinessesIDs(); len(nodes) > 0 && !bcuo.mutation.BusinessesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: businesscategory.BusinessesTable,
|
||||||
|
Columns: businesscategory.BusinessesPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := bcuo.mutation.BusinessesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: businesscategory.BusinessesTable,
|
||||||
|
Columns: businesscategory.BusinessesPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &BusinessCategory{config: bcuo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, bcuo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{businesscategory.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
bcuo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
830
ent/client.go
Normal file
830
ent/client.go
Normal file
@ -0,0 +1,830 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"tel-commerce/ent/migrate"
|
||||||
|
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client is the client that holds all ent builders.
|
||||||
|
type Client struct {
|
||||||
|
config
|
||||||
|
// Schema is the client for creating, migrating and dropping schema.
|
||||||
|
Schema *migrate.Schema
|
||||||
|
// Business is the client for interacting with the Business builders.
|
||||||
|
Business *BusinessClient
|
||||||
|
// BusinessCategory is the client for interacting with the BusinessCategory builders.
|
||||||
|
BusinessCategory *BusinessCategoryClient
|
||||||
|
// Product is the client for interacting with the Product builders.
|
||||||
|
Product *ProductClient
|
||||||
|
// ProductCategory is the client for interacting with the ProductCategory builders.
|
||||||
|
ProductCategory *ProductCategoryClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new client configured with the given options.
|
||||||
|
func NewClient(opts ...Option) *Client {
|
||||||
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||||
|
cfg.options(opts...)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) init() {
|
||||||
|
c.Schema = migrate.NewSchema(c.driver)
|
||||||
|
c.Business = NewBusinessClient(c.config)
|
||||||
|
c.BusinessCategory = NewBusinessCategoryClient(c.config)
|
||||||
|
c.Product = NewProductClient(c.config)
|
||||||
|
c.ProductCategory = NewProductCategoryClient(c.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// config is the configuration for the client and its builder.
|
||||||
|
config struct {
|
||||||
|
// driver used for executing database requests.
|
||||||
|
driver dialect.Driver
|
||||||
|
// debug enable a debug logging.
|
||||||
|
debug bool
|
||||||
|
// log used for logging on debug mode.
|
||||||
|
log func(...any)
|
||||||
|
// hooks to execute on mutations.
|
||||||
|
hooks *hooks
|
||||||
|
// interceptors to execute on queries.
|
||||||
|
inters *inters
|
||||||
|
}
|
||||||
|
// Option function to configure the client.
|
||||||
|
Option func(*config)
|
||||||
|
)
|
||||||
|
|
||||||
|
// options applies the options on the config object.
|
||||||
|
func (c *config) options(opts ...Option) {
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
if c.debug {
|
||||||
|
c.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug enables debug logging on the ent.Driver.
|
||||||
|
func Debug() Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.debug = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log sets the logging function for debug mode.
|
||||||
|
func Log(fn func(...any)) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.log = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Driver configures the client driver.
|
||||||
|
func Driver(driver dialect.Driver) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.driver = driver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open opens a database/sql.DB specified by the driver name and
|
||||||
|
// the data source name, and returns a new client attached to it.
|
||||||
|
// Optional parameters can be added for configuring the client.
|
||||||
|
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||||
|
switch driverName {
|
||||||
|
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||||
|
drv, err := sql.Open(driverName, dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewClient(append(options, Driver(drv))...), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||||
|
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
|
||||||
|
|
||||||
|
// Tx returns a new transactional client. The provided context
|
||||||
|
// is used until the transaction is committed or rolled back.
|
||||||
|
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, ErrTxStarted
|
||||||
|
}
|
||||||
|
tx, err := newTx(ctx, c.driver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = tx
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Business: NewBusinessClient(cfg),
|
||||||
|
BusinessCategory: NewBusinessCategoryClient(cfg),
|
||||||
|
Product: NewProductClient(cfg),
|
||||||
|
ProductCategory: NewProductCategoryClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeginTx returns a transactional client with specified options.
|
||||||
|
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, errors.New("ent: cannot start a transaction within a transaction")
|
||||||
|
}
|
||||||
|
tx, err := c.driver.(interface {
|
||||||
|
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
|
||||||
|
}).BeginTx(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Business: NewBusinessClient(cfg),
|
||||||
|
BusinessCategory: NewBusinessCategoryClient(cfg),
|
||||||
|
Product: NewProductClient(cfg),
|
||||||
|
ProductCategory: NewProductCategoryClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||||
|
//
|
||||||
|
// client.Debug().
|
||||||
|
// Business.
|
||||||
|
// Query().
|
||||||
|
// Count(ctx)
|
||||||
|
func (c *Client) Debug() *Client {
|
||||||
|
if c.debug {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the database connection and prevents new queries from starting.
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
return c.driver.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds the mutation hooks to all the entity clients.
|
||||||
|
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||||
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
|
c.Business.Use(hooks...)
|
||||||
|
c.BusinessCategory.Use(hooks...)
|
||||||
|
c.Product.Use(hooks...)
|
||||||
|
c.ProductCategory.Use(hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds the query interceptors to all the entity clients.
|
||||||
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||||
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.Business.Intercept(interceptors...)
|
||||||
|
c.BusinessCategory.Intercept(interceptors...)
|
||||||
|
c.Product.Intercept(interceptors...)
|
||||||
|
c.ProductCategory.Intercept(interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate implements the ent.Mutator interface.
|
||||||
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *BusinessMutation:
|
||||||
|
return c.Business.mutate(ctx, m)
|
||||||
|
case *BusinessCategoryMutation:
|
||||||
|
return c.BusinessCategory.mutate(ctx, m)
|
||||||
|
case *ProductMutation:
|
||||||
|
return c.Product.mutate(ctx, m)
|
||||||
|
case *ProductCategoryMutation:
|
||||||
|
return c.ProductCategory.mutate(ctx, m)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessClient is a client for the Business schema.
|
||||||
|
type BusinessClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBusinessClient returns a client for the Business from the given config.
|
||||||
|
func NewBusinessClient(c config) *BusinessClient {
|
||||||
|
return &BusinessClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `business.Hooks(f(g(h())))`.
|
||||||
|
func (c *BusinessClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Business = append(c.hooks.Business, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `business.Intercept(f(g(h())))`.
|
||||||
|
func (c *BusinessClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.Business = append(c.inters.Business, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a Business entity.
|
||||||
|
func (c *BusinessClient) Create() *BusinessCreate {
|
||||||
|
mutation := newBusinessMutation(c.config, OpCreate)
|
||||||
|
return &BusinessCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Business entities.
|
||||||
|
func (c *BusinessClient) CreateBulk(builders ...*BusinessCreate) *BusinessCreateBulk {
|
||||||
|
return &BusinessCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *BusinessClient) MapCreateBulk(slice any, setFunc func(*BusinessCreate, int)) *BusinessCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &BusinessCreateBulk{err: fmt.Errorf("calling to BusinessClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*BusinessCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &BusinessCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Business.
|
||||||
|
func (c *BusinessClient) Update() *BusinessUpdate {
|
||||||
|
mutation := newBusinessMutation(c.config, OpUpdate)
|
||||||
|
return &BusinessUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *BusinessClient) UpdateOne(b *Business) *BusinessUpdateOne {
|
||||||
|
mutation := newBusinessMutation(c.config, OpUpdateOne, withBusiness(b))
|
||||||
|
return &BusinessUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *BusinessClient) UpdateOneID(id int) *BusinessUpdateOne {
|
||||||
|
mutation := newBusinessMutation(c.config, OpUpdateOne, withBusinessID(id))
|
||||||
|
return &BusinessUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Business.
|
||||||
|
func (c *BusinessClient) Delete() *BusinessDelete {
|
||||||
|
mutation := newBusinessMutation(c.config, OpDelete)
|
||||||
|
return &BusinessDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *BusinessClient) DeleteOne(b *Business) *BusinessDeleteOne {
|
||||||
|
return c.DeleteOneID(b.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *BusinessClient) DeleteOneID(id int) *BusinessDeleteOne {
|
||||||
|
builder := c.Delete().Where(business.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &BusinessDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Business.
|
||||||
|
func (c *BusinessClient) Query() *BusinessQuery {
|
||||||
|
return &BusinessQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeBusiness},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Business entity by its id.
|
||||||
|
func (c *BusinessClient) Get(ctx context.Context, id int) (*Business, error) {
|
||||||
|
return c.Query().Where(business.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *BusinessClient) GetX(ctx context.Context, id int) *Business {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryBusinessCategory queries the businessCategory edge of a Business.
|
||||||
|
func (c *BusinessClient) QueryBusinessCategory(b *Business) *BusinessCategoryQuery {
|
||||||
|
query := (&BusinessCategoryClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := b.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(business.Table, business.FieldID, id),
|
||||||
|
sqlgraph.To(businesscategory.Table, businesscategory.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, business.BusinessCategoryTable, business.BusinessCategoryPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(b.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *BusinessClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Business
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *BusinessClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.Business
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BusinessClient) mutate(ctx context.Context, m *BusinessMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&BusinessCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&BusinessUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&BusinessUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&BusinessDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown Business mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BusinessCategoryClient is a client for the BusinessCategory schema.
|
||||||
|
type BusinessCategoryClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBusinessCategoryClient returns a client for the BusinessCategory from the given config.
|
||||||
|
func NewBusinessCategoryClient(c config) *BusinessCategoryClient {
|
||||||
|
return &BusinessCategoryClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `businesscategory.Hooks(f(g(h())))`.
|
||||||
|
func (c *BusinessCategoryClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.BusinessCategory = append(c.hooks.BusinessCategory, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `businesscategory.Intercept(f(g(h())))`.
|
||||||
|
func (c *BusinessCategoryClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.BusinessCategory = append(c.inters.BusinessCategory, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a BusinessCategory entity.
|
||||||
|
func (c *BusinessCategoryClient) Create() *BusinessCategoryCreate {
|
||||||
|
mutation := newBusinessCategoryMutation(c.config, OpCreate)
|
||||||
|
return &BusinessCategoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of BusinessCategory entities.
|
||||||
|
func (c *BusinessCategoryClient) CreateBulk(builders ...*BusinessCategoryCreate) *BusinessCategoryCreateBulk {
|
||||||
|
return &BusinessCategoryCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *BusinessCategoryClient) MapCreateBulk(slice any, setFunc func(*BusinessCategoryCreate, int)) *BusinessCategoryCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &BusinessCategoryCreateBulk{err: fmt.Errorf("calling to BusinessCategoryClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*BusinessCategoryCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &BusinessCategoryCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for BusinessCategory.
|
||||||
|
func (c *BusinessCategoryClient) Update() *BusinessCategoryUpdate {
|
||||||
|
mutation := newBusinessCategoryMutation(c.config, OpUpdate)
|
||||||
|
return &BusinessCategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *BusinessCategoryClient) UpdateOne(bc *BusinessCategory) *BusinessCategoryUpdateOne {
|
||||||
|
mutation := newBusinessCategoryMutation(c.config, OpUpdateOne, withBusinessCategory(bc))
|
||||||
|
return &BusinessCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *BusinessCategoryClient) UpdateOneID(id int) *BusinessCategoryUpdateOne {
|
||||||
|
mutation := newBusinessCategoryMutation(c.config, OpUpdateOne, withBusinessCategoryID(id))
|
||||||
|
return &BusinessCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for BusinessCategory.
|
||||||
|
func (c *BusinessCategoryClient) Delete() *BusinessCategoryDelete {
|
||||||
|
mutation := newBusinessCategoryMutation(c.config, OpDelete)
|
||||||
|
return &BusinessCategoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *BusinessCategoryClient) DeleteOne(bc *BusinessCategory) *BusinessCategoryDeleteOne {
|
||||||
|
return c.DeleteOneID(bc.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *BusinessCategoryClient) DeleteOneID(id int) *BusinessCategoryDeleteOne {
|
||||||
|
builder := c.Delete().Where(businesscategory.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &BusinessCategoryDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for BusinessCategory.
|
||||||
|
func (c *BusinessCategoryClient) Query() *BusinessCategoryQuery {
|
||||||
|
return &BusinessCategoryQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeBusinessCategory},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a BusinessCategory entity by its id.
|
||||||
|
func (c *BusinessCategoryClient) Get(ctx context.Context, id int) (*BusinessCategory, error) {
|
||||||
|
return c.Query().Where(businesscategory.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *BusinessCategoryClient) GetX(ctx context.Context, id int) *BusinessCategory {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryBusinesses queries the businesses edge of a BusinessCategory.
|
||||||
|
func (c *BusinessCategoryClient) QueryBusinesses(bc *BusinessCategory) *BusinessQuery {
|
||||||
|
query := (&BusinessClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := bc.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(businesscategory.Table, businesscategory.FieldID, id),
|
||||||
|
sqlgraph.To(business.Table, business.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, businesscategory.BusinessesTable, businesscategory.BusinessesPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(bc.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *BusinessCategoryClient) Hooks() []Hook {
|
||||||
|
return c.hooks.BusinessCategory
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *BusinessCategoryClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.BusinessCategory
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BusinessCategoryClient) mutate(ctx context.Context, m *BusinessCategoryMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&BusinessCategoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&BusinessCategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&BusinessCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&BusinessCategoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown BusinessCategory mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductClient is a client for the Product schema.
|
||||||
|
type ProductClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProductClient returns a client for the Product from the given config.
|
||||||
|
func NewProductClient(c config) *ProductClient {
|
||||||
|
return &ProductClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `product.Hooks(f(g(h())))`.
|
||||||
|
func (c *ProductClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Product = append(c.hooks.Product, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `product.Intercept(f(g(h())))`.
|
||||||
|
func (c *ProductClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.Product = append(c.inters.Product, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a Product entity.
|
||||||
|
func (c *ProductClient) Create() *ProductCreate {
|
||||||
|
mutation := newProductMutation(c.config, OpCreate)
|
||||||
|
return &ProductCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Product entities.
|
||||||
|
func (c *ProductClient) CreateBulk(builders ...*ProductCreate) *ProductCreateBulk {
|
||||||
|
return &ProductCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *ProductClient) MapCreateBulk(slice any, setFunc func(*ProductCreate, int)) *ProductCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &ProductCreateBulk{err: fmt.Errorf("calling to ProductClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*ProductCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &ProductCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Product.
|
||||||
|
func (c *ProductClient) Update() *ProductUpdate {
|
||||||
|
mutation := newProductMutation(c.config, OpUpdate)
|
||||||
|
return &ProductUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *ProductClient) UpdateOne(pr *Product) *ProductUpdateOne {
|
||||||
|
mutation := newProductMutation(c.config, OpUpdateOne, withProduct(pr))
|
||||||
|
return &ProductUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *ProductClient) UpdateOneID(id int) *ProductUpdateOne {
|
||||||
|
mutation := newProductMutation(c.config, OpUpdateOne, withProductID(id))
|
||||||
|
return &ProductUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Product.
|
||||||
|
func (c *ProductClient) Delete() *ProductDelete {
|
||||||
|
mutation := newProductMutation(c.config, OpDelete)
|
||||||
|
return &ProductDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *ProductClient) DeleteOne(pr *Product) *ProductDeleteOne {
|
||||||
|
return c.DeleteOneID(pr.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *ProductClient) DeleteOneID(id int) *ProductDeleteOne {
|
||||||
|
builder := c.Delete().Where(product.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &ProductDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Product.
|
||||||
|
func (c *ProductClient) Query() *ProductQuery {
|
||||||
|
return &ProductQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeProduct},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Product entity by its id.
|
||||||
|
func (c *ProductClient) Get(ctx context.Context, id int) (*Product, error) {
|
||||||
|
return c.Query().Where(product.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *ProductClient) GetX(ctx context.Context, id int) *Product {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryProductCategory queries the productCategory edge of a Product.
|
||||||
|
func (c *ProductClient) QueryProductCategory(pr *Product) *ProductCategoryQuery {
|
||||||
|
query := (&ProductCategoryClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := pr.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(product.Table, product.FieldID, id),
|
||||||
|
sqlgraph.To(productcategory.Table, productcategory.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, product.ProductCategoryTable, product.ProductCategoryPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(pr.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *ProductClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Product
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *ProductClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.Product
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ProductClient) mutate(ctx context.Context, m *ProductMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&ProductCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&ProductUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&ProductUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&ProductDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown Product mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategoryClient is a client for the ProductCategory schema.
|
||||||
|
type ProductCategoryClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProductCategoryClient returns a client for the ProductCategory from the given config.
|
||||||
|
func NewProductCategoryClient(c config) *ProductCategoryClient {
|
||||||
|
return &ProductCategoryClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `productcategory.Hooks(f(g(h())))`.
|
||||||
|
func (c *ProductCategoryClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.ProductCategory = append(c.hooks.ProductCategory, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `productcategory.Intercept(f(g(h())))`.
|
||||||
|
func (c *ProductCategoryClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.ProductCategory = append(c.inters.ProductCategory, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a ProductCategory entity.
|
||||||
|
func (c *ProductCategoryClient) Create() *ProductCategoryCreate {
|
||||||
|
mutation := newProductCategoryMutation(c.config, OpCreate)
|
||||||
|
return &ProductCategoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of ProductCategory entities.
|
||||||
|
func (c *ProductCategoryClient) CreateBulk(builders ...*ProductCategoryCreate) *ProductCategoryCreateBulk {
|
||||||
|
return &ProductCategoryCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *ProductCategoryClient) MapCreateBulk(slice any, setFunc func(*ProductCategoryCreate, int)) *ProductCategoryCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &ProductCategoryCreateBulk{err: fmt.Errorf("calling to ProductCategoryClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*ProductCategoryCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &ProductCategoryCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for ProductCategory.
|
||||||
|
func (c *ProductCategoryClient) Update() *ProductCategoryUpdate {
|
||||||
|
mutation := newProductCategoryMutation(c.config, OpUpdate)
|
||||||
|
return &ProductCategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *ProductCategoryClient) UpdateOne(pc *ProductCategory) *ProductCategoryUpdateOne {
|
||||||
|
mutation := newProductCategoryMutation(c.config, OpUpdateOne, withProductCategory(pc))
|
||||||
|
return &ProductCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *ProductCategoryClient) UpdateOneID(id int) *ProductCategoryUpdateOne {
|
||||||
|
mutation := newProductCategoryMutation(c.config, OpUpdateOne, withProductCategoryID(id))
|
||||||
|
return &ProductCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for ProductCategory.
|
||||||
|
func (c *ProductCategoryClient) Delete() *ProductCategoryDelete {
|
||||||
|
mutation := newProductCategoryMutation(c.config, OpDelete)
|
||||||
|
return &ProductCategoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *ProductCategoryClient) DeleteOne(pc *ProductCategory) *ProductCategoryDeleteOne {
|
||||||
|
return c.DeleteOneID(pc.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *ProductCategoryClient) DeleteOneID(id int) *ProductCategoryDeleteOne {
|
||||||
|
builder := c.Delete().Where(productcategory.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &ProductCategoryDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for ProductCategory.
|
||||||
|
func (c *ProductCategoryClient) Query() *ProductCategoryQuery {
|
||||||
|
return &ProductCategoryQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeProductCategory},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a ProductCategory entity by its id.
|
||||||
|
func (c *ProductCategoryClient) Get(ctx context.Context, id int) (*ProductCategory, error) {
|
||||||
|
return c.Query().Where(productcategory.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *ProductCategoryClient) GetX(ctx context.Context, id int) *ProductCategory {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryProducts queries the products edge of a ProductCategory.
|
||||||
|
func (c *ProductCategoryClient) QueryProducts(pc *ProductCategory) *ProductQuery {
|
||||||
|
query := (&ProductClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := pc.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(productcategory.Table, productcategory.FieldID, id),
|
||||||
|
sqlgraph.To(product.Table, product.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, productcategory.ProductsTable, productcategory.ProductsPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(pc.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *ProductCategoryClient) Hooks() []Hook {
|
||||||
|
return c.hooks.ProductCategory
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *ProductCategoryClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.ProductCategory
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ProductCategoryClient) mutate(ctx context.Context, m *ProductCategoryMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&ProductCategoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&ProductCategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&ProductCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&ProductCategoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown ProductCategory mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hooks and interceptors per client, for fast access.
|
||||||
|
type (
|
||||||
|
hooks struct {
|
||||||
|
Business, BusinessCategory, Product, ProductCategory []ent.Hook
|
||||||
|
}
|
||||||
|
inters struct {
|
||||||
|
Business, BusinessCategory, Product, ProductCategory []ent.Interceptor
|
||||||
|
}
|
||||||
|
)
|
614
ent/ent.go
Normal file
614
ent/ent.go
Normal file
@ -0,0 +1,614 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"sync"
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ent aliases to avoid import conflicts in user's code.
|
||||||
|
type (
|
||||||
|
Op = ent.Op
|
||||||
|
Hook = ent.Hook
|
||||||
|
Value = ent.Value
|
||||||
|
Query = ent.Query
|
||||||
|
QueryContext = ent.QueryContext
|
||||||
|
Querier = ent.Querier
|
||||||
|
QuerierFunc = ent.QuerierFunc
|
||||||
|
Interceptor = ent.Interceptor
|
||||||
|
InterceptFunc = ent.InterceptFunc
|
||||||
|
Traverser = ent.Traverser
|
||||||
|
TraverseFunc = ent.TraverseFunc
|
||||||
|
Policy = ent.Policy
|
||||||
|
Mutator = ent.Mutator
|
||||||
|
Mutation = ent.Mutation
|
||||||
|
MutateFunc = ent.MutateFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
type clientCtxKey struct{}
|
||||||
|
|
||||||
|
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||||
|
func FromContext(ctx context.Context) *Client {
|
||||||
|
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext returns a new context with the given Client attached.
|
||||||
|
func NewContext(parent context.Context, c *Client) context.Context {
|
||||||
|
return context.WithValue(parent, clientCtxKey{}, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
type txCtxKey struct{}
|
||||||
|
|
||||||
|
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||||
|
func TxFromContext(ctx context.Context) *Tx {
|
||||||
|
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTxContext returns a new context with the given Tx attached.
|
||||||
|
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||||
|
return context.WithValue(parent, txCtxKey{}, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderFunc applies an ordering on the sql selector.
|
||||||
|
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||||
|
type OrderFunc func(*sql.Selector)
|
||||||
|
|
||||||
|
var (
|
||||||
|
initCheck sync.Once
|
||||||
|
columnCheck sql.ColumnCheck
|
||||||
|
)
|
||||||
|
|
||||||
|
// columnChecker checks if the column exists in the given table.
|
||||||
|
func checkColumn(table, column string) error {
|
||||||
|
initCheck.Do(func() {
|
||||||
|
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||||
|
business.Table: business.ValidColumn,
|
||||||
|
businesscategory.Table: businesscategory.ValidColumn,
|
||||||
|
product.Table: product.ValidColumn,
|
||||||
|
productcategory.Table: productcategory.ValidColumn,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return columnCheck(table, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asc applies the given fields in ASC order.
|
||||||
|
func Asc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Asc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desc applies the given fields in DESC order.
|
||||||
|
func Desc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Desc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||||
|
type AggregateFunc func(*sql.Selector) string
|
||||||
|
|
||||||
|
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||||
|
//
|
||||||
|
// GroupBy(field1, field2).
|
||||||
|
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.As(fn(s), end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count applies the "count" aggregation function on each group.
|
||||||
|
func Count() AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.Count("*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max applies the "max" aggregation function on the given field of each group.
|
||||||
|
func Max(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Max(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||||
|
func Mean(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Avg(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Min applies the "min" aggregation function on the given field of each group.
|
||||||
|
func Min(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Min(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||||
|
func Sum(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Sum(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidationError returns when validating a field or edge fails.
|
||||||
|
type ValidationError struct {
|
||||||
|
Name string // Field or edge name.
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *ValidationError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ValidationError) Unwrap() error {
|
||||||
|
return e.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||||
|
func IsValidationError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ValidationError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||||
|
type NotFoundError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotFoundError) Error() string {
|
||||||
|
return "ent: " + e.label + " not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||||
|
func IsNotFound(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotFoundError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaskNotFound masks not found error.
|
||||||
|
func MaskNotFound(err error) error {
|
||||||
|
if IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||||
|
type NotSingularError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotSingularError) Error() string {
|
||||||
|
return "ent: " + e.label + " not singular"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||||
|
func IsNotSingular(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotSingularError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||||
|
type NotLoadedError struct {
|
||||||
|
edge string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotLoadedError) Error() string {
|
||||||
|
return "ent: " + e.edge + " edge was not loaded"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||||
|
func IsNotLoaded(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotLoadedError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConstraintError returns when trying to create/update one or more entities and
|
||||||
|
// one or more of their constraints failed. For example, violation of edge or
|
||||||
|
// field uniqueness.
|
||||||
|
type ConstraintError struct {
|
||||||
|
msg string
|
||||||
|
wrap error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ConstraintError) Error() string {
|
||||||
|
return "ent: constraint failed: " + e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ConstraintError) Unwrap() error {
|
||||||
|
return e.wrap
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||||
|
func IsConstraintError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ConstraintError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// selector embedded by the different Select/GroupBy builders.
|
||||||
|
type selector struct {
|
||||||
|
label string
|
||||||
|
flds *[]string
|
||||||
|
fns []AggregateFunc
|
||||||
|
scan func(context.Context, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||||
|
if err := s.scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (s *selector) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := s.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = s.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (s *selector) StringX(ctx context.Context) string {
|
||||||
|
v, err := s.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (s *selector) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := s.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = s.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (s *selector) IntX(ctx context.Context) int {
|
||||||
|
v, err := s.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := s.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = s.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := s.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := s.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = s.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := s.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// withHooks invokes the builder operation with the given hooks, if any.
|
||||||
|
func withHooks[V Value, M any, PM interface {
|
||||||
|
*M
|
||||||
|
Mutation
|
||||||
|
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||||
|
if len(hooks) == 0 {
|
||||||
|
return exec(ctx)
|
||||||
|
}
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutationT, ok := any(m).(PM)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
// Set the mutation to the builder.
|
||||||
|
*mutation = *mutationT
|
||||||
|
return exec(ctx)
|
||||||
|
})
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
if hooks[i] == nil {
|
||||||
|
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = hooks[i](mut)
|
||||||
|
}
|
||||||
|
v, err := mut.Mutate(ctx, mutation)
|
||||||
|
if err != nil {
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
nv, ok := v.(V)
|
||||||
|
if !ok {
|
||||||
|
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||||
|
}
|
||||||
|
return nv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||||
|
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||||
|
if ent.QueryFromContext(ctx) == nil {
|
||||||
|
qc.Op = op
|
||||||
|
ctx = ent.NewQueryContext(ctx, qc)
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierAll[V Value, Q interface {
|
||||||
|
sqlAll(context.Context, ...queryHook) (V, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlAll(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierCount[Q interface {
|
||||||
|
sqlCount(context.Context) (int, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlCount(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
rv, err := qr.Query(ctx, q)
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
vt, ok := rv.(V)
|
||||||
|
if !ok {
|
||||||
|
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||||
|
}
|
||||||
|
return vt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||||
|
sqlScan(context.Context, Q1, any) error
|
||||||
|
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||||
|
rv := reflect.ValueOf(v)
|
||||||
|
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q1)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||||
|
return rv.Elem().Interface(), nil
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
})
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
vv, err := qr.Query(ctx, rootQuery)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch rv2 := reflect.ValueOf(vv); {
|
||||||
|
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||||
|
case rv.Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2.Elem())
|
||||||
|
case rv.Elem().Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// queryHook describes an internal hook for the different sqlAll methods.
|
||||||
|
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
84
ent/enttest/enttest.go
Normal file
84
ent/enttest/enttest.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package enttest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"tel-commerce/ent"
|
||||||
|
// required by schema hooks.
|
||||||
|
_ "tel-commerce/ent/runtime"
|
||||||
|
|
||||||
|
"tel-commerce/ent/migrate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TestingT is the interface that is shared between
|
||||||
|
// testing.T and testing.B and used by enttest.
|
||||||
|
TestingT interface {
|
||||||
|
FailNow()
|
||||||
|
Error(...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option configures client creation.
|
||||||
|
Option func(*options)
|
||||||
|
|
||||||
|
options struct {
|
||||||
|
opts []ent.Option
|
||||||
|
migrateOpts []schema.MigrateOption
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithOptions forwards options to client creation.
|
||||||
|
func WithOptions(opts ...ent.Option) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.opts = append(o.opts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMigrateOptions forwards options to auto migration.
|
||||||
|
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOptions(opts []Option) *options {
|
||||||
|
o := &options{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(o)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open calls ent.Open and auto-run migration.
|
||||||
|
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c, err := ent.Open(driverName, dataSourceName, o.opts...)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient calls ent.NewClient and auto-run migration.
|
||||||
|
func NewClient(t TestingT, opts ...Option) *ent.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c := ent.NewClient(o.opts...)
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
func migrateSchema(t TestingT, c *ent.Client, o *options) {
|
||||||
|
tables, err := schema.CopyTables(migrate.Tables)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
3
ent/generate.go
Normal file
3
ent/generate.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package ent
|
||||||
|
|
||||||
|
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema
|
234
ent/hook/hook.go
Normal file
234
ent/hook/hook.go
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package hook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The BusinessFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Business mutator.
|
||||||
|
type BusinessFunc func(context.Context, *ent.BusinessMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f BusinessFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.BusinessMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.BusinessMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The BusinessCategoryFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as BusinessCategory mutator.
|
||||||
|
type BusinessCategoryFunc func(context.Context, *ent.BusinessCategoryMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f BusinessCategoryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.BusinessCategoryMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.BusinessCategoryMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ProductFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Product mutator.
|
||||||
|
type ProductFunc func(context.Context, *ent.ProductMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f ProductFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.ProductMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ProductMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ProductCategoryFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as ProductCategory mutator.
|
||||||
|
type ProductCategoryFunc func(context.Context, *ent.ProductCategoryMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f ProductCategoryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.ProductCategoryMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ProductCategoryMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Condition is a hook condition function.
|
||||||
|
type Condition func(context.Context, ent.Mutation) bool
|
||||||
|
|
||||||
|
// And groups conditions with the AND operator.
|
||||||
|
func And(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
if !first(ctx, m) || !second(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if !cond(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups conditions with the OR operator.
|
||||||
|
func Or(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
if first(ctx, m) || second(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not negates a given condition.
|
||||||
|
func Not(cond Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
return !cond(ctx, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasOp is a condition testing mutation operation.
|
||||||
|
func HasOp(op ent.Op) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
return m.Op().Is(op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||||
|
func HasAddedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||||
|
func HasClearedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasFields is a condition validating `.Field` on fields.
|
||||||
|
func HasFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If executes the given hook under condition.
|
||||||
|
//
|
||||||
|
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||||
|
func If(hk ent.Hook, cond Condition) ent.Hook {
|
||||||
|
return func(next ent.Mutator) ent.Mutator {
|
||||||
|
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return hk(next).Mutate(ctx, m)
|
||||||
|
}
|
||||||
|
return next.Mutate(ctx, m)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On executes the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.On(Log, ent.Delete|ent.Create)
|
||||||
|
func On(hk ent.Hook, op ent.Op) ent.Hook {
|
||||||
|
return If(hk, HasOp(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unless skips the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||||
|
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||||
|
return If(hk, Not(HasOp(op)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedError is a hook returning a fixed error.
|
||||||
|
func FixedError(err error) ent.Hook {
|
||||||
|
return func(ent.Mutator) ent.Mutator {
|
||||||
|
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject returns a hook that rejects all operations that match op.
|
||||||
|
//
|
||||||
|
// func (T) Hooks() []ent.Hook {
|
||||||
|
// return []ent.Hook{
|
||||||
|
// Reject(ent.Delete|ent.Update),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
func Reject(op ent.Op) ent.Hook {
|
||||||
|
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||||
|
return On(hk, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chain acts as a list of hooks and is effectively immutable.
|
||||||
|
// Once created, it will always hold the same set of hooks in the same order.
|
||||||
|
type Chain struct {
|
||||||
|
hooks []ent.Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewChain creates a new chain of hooks.
|
||||||
|
func NewChain(hooks ...ent.Hook) Chain {
|
||||||
|
return Chain{append([]ent.Hook(nil), hooks...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook chains the list of hooks and returns the final hook.
|
||||||
|
func (c Chain) Hook() ent.Hook {
|
||||||
|
return func(mutator ent.Mutator) ent.Mutator {
|
||||||
|
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||||
|
mutator = c.hooks[i](mutator)
|
||||||
|
}
|
||||||
|
return mutator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append extends a chain, adding the specified hook
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Append(hooks ...ent.Hook) Chain {
|
||||||
|
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
|
||||||
|
newHooks = append(newHooks, c.hooks...)
|
||||||
|
newHooks = append(newHooks, hooks...)
|
||||||
|
return Chain{newHooks}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend extends a chain, adding the specified chain
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Extend(chain Chain) Chain {
|
||||||
|
return c.Append(chain.hooks...)
|
||||||
|
}
|
64
ent/migrate/migrate.go
Normal file
64
ent/migrate/migrate.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||||
|
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||||
|
// for the ids of each entity (table).
|
||||||
|
// Note that this option cannot be applied on tables that already exist.
|
||||||
|
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||||
|
// WithDropColumn sets the drop column option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old columns
|
||||||
|
// that were used for both fields and edges. This defaults to false.
|
||||||
|
WithDropColumn = schema.WithDropColumn
|
||||||
|
// WithDropIndex sets the drop index option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old indexes
|
||||||
|
// that were defined in the schema. This defaults to false.
|
||||||
|
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||||
|
// and therefore, it's recommended to enable this option to get more
|
||||||
|
// flexibility in the schema changes.
|
||||||
|
WithDropIndex = schema.WithDropIndex
|
||||||
|
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||||
|
WithForeignKeys = schema.WithForeignKeys
|
||||||
|
)
|
||||||
|
|
||||||
|
// Schema is the API for creating, migrating and dropping a schema.
|
||||||
|
type Schema struct {
|
||||||
|
drv dialect.Driver
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSchema creates a new schema client.
|
||||||
|
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||||
|
|
||||||
|
// Create creates all schema resources.
|
||||||
|
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, s, Tables, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates all table resources using the given schema driver.
|
||||||
|
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||||
|
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ent/migrate: %w", err)
|
||||||
|
}
|
||||||
|
return migrate.Create(ctx, tables...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||||
|
//
|
||||||
|
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||||
|
}
|
142
ent/migrate/schema.go
Normal file
142
ent/migrate/schema.go
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// BusinessesColumns holds the columns for the "businesses" table.
|
||||||
|
BusinessesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
|
{Name: "name", Type: field.TypeString, Default: "unknown"},
|
||||||
|
{Name: "slug", Type: field.TypeString, Unique: true},
|
||||||
|
{Name: "bot_id", Type: field.TypeString, Unique: true},
|
||||||
|
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "company", Type: field.TypeString, Default: "main"},
|
||||||
|
{Name: "about_us", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
}
|
||||||
|
// BusinessesTable holds the schema information for the "businesses" table.
|
||||||
|
BusinessesTable = &schema.Table{
|
||||||
|
Name: "businesses",
|
||||||
|
Columns: BusinessesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{BusinessesColumns[0]},
|
||||||
|
}
|
||||||
|
// BusinessCategoriesColumns holds the columns for the "business_categories" table.
|
||||||
|
BusinessCategoriesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
|
{Name: "slug", Type: field.TypeString, Unique: true},
|
||||||
|
{Name: "name", Type: field.TypeString, Default: "unknown"},
|
||||||
|
{Name: "description", Type: field.TypeString, Default: "unknown"},
|
||||||
|
}
|
||||||
|
// BusinessCategoriesTable holds the schema information for the "business_categories" table.
|
||||||
|
BusinessCategoriesTable = &schema.Table{
|
||||||
|
Name: "business_categories",
|
||||||
|
Columns: BusinessCategoriesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{BusinessCategoriesColumns[0]},
|
||||||
|
}
|
||||||
|
// ProductsColumns holds the columns for the "products" table.
|
||||||
|
ProductsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
|
{Name: "name", Type: field.TypeString, Default: "unknown"},
|
||||||
|
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "price", Type: field.TypeFloat64, Default: 0},
|
||||||
|
{Name: "original_price", Type: field.TypeFloat64, Default: 0},
|
||||||
|
{Name: "quantity", Type: field.TypeInt, Default: 0},
|
||||||
|
{Name: "status", Type: field.TypeBool, Default: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
}
|
||||||
|
// ProductsTable holds the schema information for the "products" table.
|
||||||
|
ProductsTable = &schema.Table{
|
||||||
|
Name: "products",
|
||||||
|
Columns: ProductsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{ProductsColumns[0]},
|
||||||
|
}
|
||||||
|
// ProductCategoriesColumns holds the columns for the "product_categories" table.
|
||||||
|
ProductCategoriesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
|
{Name: "name", Type: field.TypeString, Default: "unknown"},
|
||||||
|
{Name: "slug", Type: field.TypeString, Unique: true},
|
||||||
|
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "status", Type: field.TypeBool, Default: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
}
|
||||||
|
// ProductCategoriesTable holds the schema information for the "product_categories" table.
|
||||||
|
ProductCategoriesTable = &schema.Table{
|
||||||
|
Name: "product_categories",
|
||||||
|
Columns: ProductCategoriesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{ProductCategoriesColumns[0]},
|
||||||
|
}
|
||||||
|
// BusinessCategoryBusinessesColumns holds the columns for the "business_category_businesses" table.
|
||||||
|
BusinessCategoryBusinessesColumns = []*schema.Column{
|
||||||
|
{Name: "business_category_id", Type: field.TypeInt},
|
||||||
|
{Name: "business_id", Type: field.TypeInt},
|
||||||
|
}
|
||||||
|
// BusinessCategoryBusinessesTable holds the schema information for the "business_category_businesses" table.
|
||||||
|
BusinessCategoryBusinessesTable = &schema.Table{
|
||||||
|
Name: "business_category_businesses",
|
||||||
|
Columns: BusinessCategoryBusinessesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{BusinessCategoryBusinessesColumns[0], BusinessCategoryBusinessesColumns[1]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "business_category_businesses_business_category_id",
|
||||||
|
Columns: []*schema.Column{BusinessCategoryBusinessesColumns[0]},
|
||||||
|
RefColumns: []*schema.Column{BusinessCategoriesColumns[0]},
|
||||||
|
OnDelete: schema.Cascade,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Symbol: "business_category_businesses_business_id",
|
||||||
|
Columns: []*schema.Column{BusinessCategoryBusinessesColumns[1]},
|
||||||
|
RefColumns: []*schema.Column{BusinessesColumns[0]},
|
||||||
|
OnDelete: schema.Cascade,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// ProductCategoryProductsColumns holds the columns for the "product_category_products" table.
|
||||||
|
ProductCategoryProductsColumns = []*schema.Column{
|
||||||
|
{Name: "product_category_id", Type: field.TypeInt},
|
||||||
|
{Name: "product_id", Type: field.TypeInt},
|
||||||
|
}
|
||||||
|
// ProductCategoryProductsTable holds the schema information for the "product_category_products" table.
|
||||||
|
ProductCategoryProductsTable = &schema.Table{
|
||||||
|
Name: "product_category_products",
|
||||||
|
Columns: ProductCategoryProductsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{ProductCategoryProductsColumns[0], ProductCategoryProductsColumns[1]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "product_category_products_product_category_id",
|
||||||
|
Columns: []*schema.Column{ProductCategoryProductsColumns[0]},
|
||||||
|
RefColumns: []*schema.Column{ProductCategoriesColumns[0]},
|
||||||
|
OnDelete: schema.Cascade,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Symbol: "product_category_products_product_id",
|
||||||
|
Columns: []*schema.Column{ProductCategoryProductsColumns[1]},
|
||||||
|
RefColumns: []*schema.Column{ProductsColumns[0]},
|
||||||
|
OnDelete: schema.Cascade,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// Tables holds all the tables in the schema.
|
||||||
|
Tables = []*schema.Table{
|
||||||
|
BusinessesTable,
|
||||||
|
BusinessCategoriesTable,
|
||||||
|
ProductsTable,
|
||||||
|
ProductCategoriesTable,
|
||||||
|
BusinessCategoryBusinessesTable,
|
||||||
|
ProductCategoryProductsTable,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
BusinessCategoryBusinessesTable.ForeignKeys[0].RefTable = BusinessCategoriesTable
|
||||||
|
BusinessCategoryBusinessesTable.ForeignKeys[1].RefTable = BusinessesTable
|
||||||
|
ProductCategoryProductsTable.ForeignKeys[0].RefTable = ProductCategoriesTable
|
||||||
|
ProductCategoryProductsTable.ForeignKeys[1].RefTable = ProductsTable
|
||||||
|
}
|
3031
ent/mutation.go
Normal file
3031
ent/mutation.go
Normal file
File diff suppressed because it is too large
Load Diff
19
ent/predicate/predicate.go
Normal file
19
ent/predicate/predicate.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package predicate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Business is the predicate function for business builders.
|
||||||
|
type Business func(*sql.Selector)
|
||||||
|
|
||||||
|
// BusinessCategory is the predicate function for businesscategory builders.
|
||||||
|
type BusinessCategory func(*sql.Selector)
|
||||||
|
|
||||||
|
// Product is the predicate function for product builders.
|
||||||
|
type Product func(*sql.Selector)
|
||||||
|
|
||||||
|
// ProductCategory is the predicate function for productcategory builders.
|
||||||
|
type ProductCategory func(*sql.Selector)
|
216
ent/product.go
Normal file
216
ent/product.go
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"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
|
165
ent/product/product.go
Normal file
165
ent/product/product.go
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package product
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the product type in the database.
|
||||||
|
Label = "product"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
FieldName = "name"
|
||||||
|
// FieldDescription holds the string denoting the description field in the database.
|
||||||
|
FieldDescription = "description"
|
||||||
|
// FieldPrice holds the string denoting the price field in the database.
|
||||||
|
FieldPrice = "price"
|
||||||
|
// FieldOriginalPrice holds the string denoting the original_price field in the database.
|
||||||
|
FieldOriginalPrice = "original_price"
|
||||||
|
// FieldQuantity holds the string denoting the quantity field in the database.
|
||||||
|
FieldQuantity = "quantity"
|
||||||
|
// FieldStatus holds the string denoting the status field in the database.
|
||||||
|
FieldStatus = "status"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// EdgeProductCategory holds the string denoting the productcategory edge name in mutations.
|
||||||
|
EdgeProductCategory = "productCategory"
|
||||||
|
// Table holds the table name of the product in the database.
|
||||||
|
Table = "products"
|
||||||
|
// ProductCategoryTable is the table that holds the productCategory relation/edge. The primary key declared below.
|
||||||
|
ProductCategoryTable = "product_category_products"
|
||||||
|
// ProductCategoryInverseTable is the table name for the ProductCategory entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "productcategory" package.
|
||||||
|
ProductCategoryInverseTable = "product_categories"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for product fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldName,
|
||||||
|
FieldDescription,
|
||||||
|
FieldPrice,
|
||||||
|
FieldOriginalPrice,
|
||||||
|
FieldQuantity,
|
||||||
|
FieldStatus,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ProductCategoryPrimaryKey and ProductCategoryColumn2 are the table columns denoting the
|
||||||
|
// primary key for the productCategory relation (M2M).
|
||||||
|
ProductCategoryPrimaryKey = []string{"product_category_id", "product_id"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultName holds the default value on creation for the "name" field.
|
||||||
|
DefaultName string
|
||||||
|
// DefaultPrice holds the default value on creation for the "price" field.
|
||||||
|
DefaultPrice float64
|
||||||
|
// PriceValidator is a validator for the "price" field. It is called by the builders before save.
|
||||||
|
PriceValidator func(float64) error
|
||||||
|
// DefaultOriginalPrice holds the default value on creation for the "original_price" field.
|
||||||
|
DefaultOriginalPrice float64
|
||||||
|
// OriginalPriceValidator is a validator for the "original_price" field. It is called by the builders before save.
|
||||||
|
OriginalPriceValidator func(float64) error
|
||||||
|
// DefaultQuantity holds the default value on creation for the "quantity" field.
|
||||||
|
DefaultQuantity int
|
||||||
|
// QuantityValidator is a validator for the "quantity" field. It is called by the builders before save.
|
||||||
|
QuantityValidator func(int) error
|
||||||
|
// DefaultStatus holds the default value on creation for the "status" field.
|
||||||
|
DefaultStatus bool
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the Product queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByName orders the results by the name field.
|
||||||
|
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDescription orders the results by the description field.
|
||||||
|
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPrice orders the results by the price field.
|
||||||
|
func ByPrice(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldPrice, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByOriginalPrice orders the results by the original_price field.
|
||||||
|
func ByOriginalPrice(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldOriginalPrice, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByQuantity orders the results by the quantity field.
|
||||||
|
func ByQuantity(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldQuantity, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByStatus orders the results by the status field.
|
||||||
|
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProductCategoryCount orders the results by productCategory count.
|
||||||
|
func ByProductCategoryCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newProductCategoryStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProductCategory orders the results by productCategory terms.
|
||||||
|
func ByProductCategory(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newProductCategoryStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newProductCategoryStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(ProductCategoryInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, ProductCategoryTable, ProductCategoryPrimaryKey...),
|
||||||
|
)
|
||||||
|
}
|
484
ent/product/where.go
Normal file
484
ent/product/where.go
Normal file
@ -0,0 +1,484 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package product
|
||||||
|
|
||||||
|
import (
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||||
|
func Name(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||||
|
func Description(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Price applies equality check predicate on the "price" field. It's identical to PriceEQ.
|
||||||
|
func Price(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPrice applies equality check predicate on the "original_price" field. It's identical to OriginalPriceEQ.
|
||||||
|
func OriginalPrice(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldOriginalPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quantity applies equality check predicate on the "quantity" field. It's identical to QuantityEQ.
|
||||||
|
func Quantity(v int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldQuantity, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
|
||||||
|
func Status(v bool) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEQ applies the EQ predicate on the "name" field.
|
||||||
|
func NameEQ(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||||
|
func NameNEQ(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameIn applies the In predicate on the "name" field.
|
||||||
|
func NameIn(vs ...string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||||
|
func NameNotIn(vs ...string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGT applies the GT predicate on the "name" field.
|
||||||
|
func NameGT(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGTE applies the GTE predicate on the "name" field.
|
||||||
|
func NameGTE(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLT applies the LT predicate on the "name" field.
|
||||||
|
func NameLT(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLTE applies the LTE predicate on the "name" field.
|
||||||
|
func NameLTE(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContains applies the Contains predicate on the "name" field.
|
||||||
|
func NameContains(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldContains(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||||
|
func NameHasPrefix(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldHasPrefix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||||
|
func NameHasSuffix(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldHasSuffix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||||
|
func NameEqualFold(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEqualFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||||
|
func NameContainsFold(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldContainsFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||||
|
func DescriptionEQ(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||||
|
func DescriptionNEQ(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIn applies the In predicate on the "description" field.
|
||||||
|
func DescriptionIn(vs ...string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||||
|
func DescriptionNotIn(vs ...string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGT applies the GT predicate on the "description" field.
|
||||||
|
func DescriptionGT(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||||
|
func DescriptionGTE(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLT applies the LT predicate on the "description" field.
|
||||||
|
func DescriptionLT(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||||
|
func DescriptionLTE(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||||
|
func DescriptionContains(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldContains(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||||
|
func DescriptionHasPrefix(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldHasPrefix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||||
|
func DescriptionHasSuffix(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldHasSuffix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||||
|
func DescriptionIsNil() predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIsNull(FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||||
|
func DescriptionNotNil() predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotNull(FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||||
|
func DescriptionEqualFold(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEqualFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||||
|
func DescriptionContainsFold(v string) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldContainsFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PriceEQ applies the EQ predicate on the "price" field.
|
||||||
|
func PriceEQ(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PriceNEQ applies the NEQ predicate on the "price" field.
|
||||||
|
func PriceNEQ(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PriceIn applies the In predicate on the "price" field.
|
||||||
|
func PriceIn(vs ...float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIn(FieldPrice, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PriceNotIn applies the NotIn predicate on the "price" field.
|
||||||
|
func PriceNotIn(vs ...float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotIn(FieldPrice, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PriceGT applies the GT predicate on the "price" field.
|
||||||
|
func PriceGT(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGT(FieldPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PriceGTE applies the GTE predicate on the "price" field.
|
||||||
|
func PriceGTE(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGTE(FieldPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PriceLT applies the LT predicate on the "price" field.
|
||||||
|
func PriceLT(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLT(FieldPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PriceLTE applies the LTE predicate on the "price" field.
|
||||||
|
func PriceLTE(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLTE(FieldPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPriceEQ applies the EQ predicate on the "original_price" field.
|
||||||
|
func OriginalPriceEQ(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldOriginalPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPriceNEQ applies the NEQ predicate on the "original_price" field.
|
||||||
|
func OriginalPriceNEQ(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldOriginalPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPriceIn applies the In predicate on the "original_price" field.
|
||||||
|
func OriginalPriceIn(vs ...float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIn(FieldOriginalPrice, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPriceNotIn applies the NotIn predicate on the "original_price" field.
|
||||||
|
func OriginalPriceNotIn(vs ...float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotIn(FieldOriginalPrice, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPriceGT applies the GT predicate on the "original_price" field.
|
||||||
|
func OriginalPriceGT(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGT(FieldOriginalPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPriceGTE applies the GTE predicate on the "original_price" field.
|
||||||
|
func OriginalPriceGTE(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGTE(FieldOriginalPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPriceLT applies the LT predicate on the "original_price" field.
|
||||||
|
func OriginalPriceLT(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLT(FieldOriginalPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// OriginalPriceLTE applies the LTE predicate on the "original_price" field.
|
||||||
|
func OriginalPriceLTE(v float64) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLTE(FieldOriginalPrice, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuantityEQ applies the EQ predicate on the "quantity" field.
|
||||||
|
func QuantityEQ(v int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldQuantity, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuantityNEQ applies the NEQ predicate on the "quantity" field.
|
||||||
|
func QuantityNEQ(v int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldQuantity, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuantityIn applies the In predicate on the "quantity" field.
|
||||||
|
func QuantityIn(vs ...int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIn(FieldQuantity, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuantityNotIn applies the NotIn predicate on the "quantity" field.
|
||||||
|
func QuantityNotIn(vs ...int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotIn(FieldQuantity, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuantityGT applies the GT predicate on the "quantity" field.
|
||||||
|
func QuantityGT(v int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGT(FieldQuantity, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuantityGTE applies the GTE predicate on the "quantity" field.
|
||||||
|
func QuantityGTE(v int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGTE(FieldQuantity, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuantityLT applies the LT predicate on the "quantity" field.
|
||||||
|
func QuantityLT(v int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLT(FieldQuantity, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuantityLTE applies the LTE predicate on the "quantity" field.
|
||||||
|
func QuantityLTE(v int) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLTE(FieldQuantity, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusEQ applies the EQ predicate on the "status" field.
|
||||||
|
func StatusEQ(v bool) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||||
|
func StatusNEQ(v bool) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.Product {
|
||||||
|
return predicate.Product(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasProductCategory applies the HasEdge predicate on the "productCategory" edge.
|
||||||
|
func HasProductCategory() predicate.Product {
|
||||||
|
return predicate.Product(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, ProductCategoryTable, ProductCategoryPrimaryKey...),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasProductCategoryWith applies the HasEdge predicate on the "productCategory" edge with a given conditions (other predicates).
|
||||||
|
func HasProductCategoryWith(preds ...predicate.ProductCategory) predicate.Product {
|
||||||
|
return predicate.Product(func(s *sql.Selector) {
|
||||||
|
step := newProductCategoryStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.Product) predicate.Product {
|
||||||
|
return predicate.Product(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.Product) predicate.Product {
|
||||||
|
return predicate.Product(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.Product) predicate.Product {
|
||||||
|
return predicate.Product(sql.NotPredicates(p))
|
||||||
|
}
|
417
ent/product_create.go
Normal file
417
ent/product_create.go
Normal file
@ -0,0 +1,417 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductCreate is the builder for creating a Product entity.
|
||||||
|
type ProductCreate struct {
|
||||||
|
config
|
||||||
|
mutation *ProductMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (pc *ProductCreate) SetName(s string) *ProductCreate {
|
||||||
|
pc.mutation.SetName(s)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (pc *ProductCreate) SetNillableName(s *string) *ProductCreate {
|
||||||
|
if s != nil {
|
||||||
|
pc.SetName(*s)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (pc *ProductCreate) SetDescription(s string) *ProductCreate {
|
||||||
|
pc.mutation.SetDescription(s)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (pc *ProductCreate) SetNillableDescription(s *string) *ProductCreate {
|
||||||
|
if s != nil {
|
||||||
|
pc.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPrice sets the "price" field.
|
||||||
|
func (pc *ProductCreate) SetPrice(f float64) *ProductCreate {
|
||||||
|
pc.mutation.SetPrice(f)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePrice sets the "price" field if the given value is not nil.
|
||||||
|
func (pc *ProductCreate) SetNillablePrice(f *float64) *ProductCreate {
|
||||||
|
if f != nil {
|
||||||
|
pc.SetPrice(*f)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOriginalPrice sets the "original_price" field.
|
||||||
|
func (pc *ProductCreate) SetOriginalPrice(f float64) *ProductCreate {
|
||||||
|
pc.mutation.SetOriginalPrice(f)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
|
||||||
|
func (pc *ProductCreate) SetNillableOriginalPrice(f *float64) *ProductCreate {
|
||||||
|
if f != nil {
|
||||||
|
pc.SetOriginalPrice(*f)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetQuantity sets the "quantity" field.
|
||||||
|
func (pc *ProductCreate) SetQuantity(i int) *ProductCreate {
|
||||||
|
pc.mutation.SetQuantity(i)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
|
||||||
|
func (pc *ProductCreate) SetNillableQuantity(i *int) *ProductCreate {
|
||||||
|
if i != nil {
|
||||||
|
pc.SetQuantity(*i)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (pc *ProductCreate) SetStatus(b bool) *ProductCreate {
|
||||||
|
pc.mutation.SetStatus(b)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (pc *ProductCreate) SetNillableStatus(b *bool) *ProductCreate {
|
||||||
|
if b != nil {
|
||||||
|
pc.SetStatus(*b)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (pc *ProductCreate) SetCreatedAt(t time.Time) *ProductCreate {
|
||||||
|
pc.mutation.SetCreatedAt(t)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (pc *ProductCreate) SetNillableCreatedAt(t *time.Time) *ProductCreate {
|
||||||
|
if t != nil {
|
||||||
|
pc.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pc *ProductCreate) SetUpdatedAt(t time.Time) *ProductCreate {
|
||||||
|
pc.mutation.SetUpdatedAt(t)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (pc *ProductCreate) SetNillableUpdatedAt(t *time.Time) *ProductCreate {
|
||||||
|
if t != nil {
|
||||||
|
pc.SetUpdatedAt(*t)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductCategoryIDs adds the "productCategory" edge to the ProductCategory entity by IDs.
|
||||||
|
func (pc *ProductCreate) AddProductCategoryIDs(ids ...int) *ProductCreate {
|
||||||
|
pc.mutation.AddProductCategoryIDs(ids...)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductCategory adds the "productCategory" edges to the ProductCategory entity.
|
||||||
|
func (pc *ProductCreate) AddProductCategory(p ...*ProductCategory) *ProductCreate {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pc.AddProductCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProductMutation object of the builder.
|
||||||
|
func (pc *ProductCreate) Mutation() *ProductMutation {
|
||||||
|
return pc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Product in the database.
|
||||||
|
func (pc *ProductCreate) Save(ctx context.Context) (*Product, error) {
|
||||||
|
pc.defaults()
|
||||||
|
return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (pc *ProductCreate) SaveX(ctx context.Context) *Product {
|
||||||
|
v, err := pc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pc *ProductCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := pc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pc *ProductCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := pc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pc *ProductCreate) defaults() {
|
||||||
|
if _, ok := pc.mutation.Name(); !ok {
|
||||||
|
v := product.DefaultName
|
||||||
|
pc.mutation.SetName(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Price(); !ok {
|
||||||
|
v := product.DefaultPrice
|
||||||
|
pc.mutation.SetPrice(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.OriginalPrice(); !ok {
|
||||||
|
v := product.DefaultOriginalPrice
|
||||||
|
pc.mutation.SetOriginalPrice(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Quantity(); !ok {
|
||||||
|
v := product.DefaultQuantity
|
||||||
|
pc.mutation.SetQuantity(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Status(); !ok {
|
||||||
|
v := product.DefaultStatus
|
||||||
|
pc.mutation.SetStatus(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.CreatedAt(); !ok {
|
||||||
|
v := product.DefaultCreatedAt
|
||||||
|
pc.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.UpdatedAt(); !ok {
|
||||||
|
v := product.DefaultUpdatedAt
|
||||||
|
pc.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (pc *ProductCreate) check() error {
|
||||||
|
if _, ok := pc.mutation.Name(); !ok {
|
||||||
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Product.name"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Price(); !ok {
|
||||||
|
return &ValidationError{Name: "price", err: errors.New(`ent: missing required field "Product.price"`)}
|
||||||
|
}
|
||||||
|
if v, ok := pc.mutation.Price(); ok {
|
||||||
|
if err := product.PriceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "price", err: fmt.Errorf(`ent: validator failed for field "Product.price": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.OriginalPrice(); !ok {
|
||||||
|
return &ValidationError{Name: "original_price", err: errors.New(`ent: missing required field "Product.original_price"`)}
|
||||||
|
}
|
||||||
|
if v, ok := pc.mutation.OriginalPrice(); ok {
|
||||||
|
if err := product.OriginalPriceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "original_price", err: fmt.Errorf(`ent: validator failed for field "Product.original_price": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Quantity(); !ok {
|
||||||
|
return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "Product.quantity"`)}
|
||||||
|
}
|
||||||
|
if v, ok := pc.mutation.Quantity(); ok {
|
||||||
|
if err := product.QuantityValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "quantity", err: fmt.Errorf(`ent: validator failed for field "Product.quantity": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Status(); !ok {
|
||||||
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Product.status"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Product.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Product.updated_at"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *ProductCreate) sqlSave(ctx context.Context) (*Product, error) {
|
||||||
|
if err := pc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := pc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, pc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int(id)
|
||||||
|
pc.mutation.id = &_node.ID
|
||||||
|
pc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *ProductCreate) createSpec() (*Product, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Product{config: pc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(product.Table, sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt))
|
||||||
|
)
|
||||||
|
if value, ok := pc.mutation.Name(); ok {
|
||||||
|
_spec.SetField(product.FieldName, field.TypeString, value)
|
||||||
|
_node.Name = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Description(); ok {
|
||||||
|
_spec.SetField(product.FieldDescription, field.TypeString, value)
|
||||||
|
_node.Description = &value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Price(); ok {
|
||||||
|
_spec.SetField(product.FieldPrice, field.TypeFloat64, value)
|
||||||
|
_node.Price = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.OriginalPrice(); ok {
|
||||||
|
_spec.SetField(product.FieldOriginalPrice, field.TypeFloat64, value)
|
||||||
|
_node.OriginalPrice = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Quantity(); ok {
|
||||||
|
_spec.SetField(product.FieldQuantity, field.TypeInt, value)
|
||||||
|
_node.Quantity = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Status(); ok {
|
||||||
|
_spec.SetField(product.FieldStatus, field.TypeBool, value)
|
||||||
|
_node.Status = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(product.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(product.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if nodes := pc.mutation.ProductCategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: product.ProductCategoryTable,
|
||||||
|
Columns: product.ProductCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCreateBulk is the builder for creating many Product entities in bulk.
|
||||||
|
type ProductCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*ProductCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Product entities in the database.
|
||||||
|
func (pcb *ProductCreateBulk) Save(ctx context.Context) ([]*Product, error) {
|
||||||
|
if pcb.err != nil {
|
||||||
|
return nil, pcb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(pcb.builders))
|
||||||
|
nodes := make([]*Product, len(pcb.builders))
|
||||||
|
mutators := make([]Mutator, len(pcb.builders))
|
||||||
|
for i := range pcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := pcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*ProductMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, pcb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, pcb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, pcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pcb *ProductCreateBulk) SaveX(ctx context.Context) []*Product {
|
||||||
|
v, err := pcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pcb *ProductCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := pcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pcb *ProductCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := pcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
88
ent/product_delete.go
Normal file
88
ent/product_delete.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductDelete is the builder for deleting a Product entity.
|
||||||
|
type ProductDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProductMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProductDelete builder.
|
||||||
|
func (pd *ProductDelete) Where(ps ...predicate.Product) *ProductDelete {
|
||||||
|
pd.mutation.Where(ps...)
|
||||||
|
return pd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (pd *ProductDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pd *ProductDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := pd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pd *ProductDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(product.Table, sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt))
|
||||||
|
if ps := pd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, pd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
pd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductDeleteOne is the builder for deleting a single Product entity.
|
||||||
|
type ProductDeleteOne struct {
|
||||||
|
pd *ProductDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProductDelete builder.
|
||||||
|
func (pdo *ProductDeleteOne) Where(ps ...predicate.Product) *ProductDeleteOne {
|
||||||
|
pdo.pd.mutation.Where(ps...)
|
||||||
|
return pdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (pdo *ProductDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := pdo.pd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{product.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pdo *ProductDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := pdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
636
ent/product_query.go
Normal file
636
ent/product_query.go
Normal file
@ -0,0 +1,636 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductQuery is the builder for querying Product entities.
|
||||||
|
type ProductQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []product.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.Product
|
||||||
|
withProductCategory *ProductCategoryQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the ProductQuery builder.
|
||||||
|
func (pq *ProductQuery) Where(ps ...predicate.Product) *ProductQuery {
|
||||||
|
pq.predicates = append(pq.predicates, ps...)
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (pq *ProductQuery) Limit(limit int) *ProductQuery {
|
||||||
|
pq.ctx.Limit = &limit
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (pq *ProductQuery) Offset(offset int) *ProductQuery {
|
||||||
|
pq.ctx.Offset = &offset
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (pq *ProductQuery) Unique(unique bool) *ProductQuery {
|
||||||
|
pq.ctx.Unique = &unique
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (pq *ProductQuery) Order(o ...product.OrderOption) *ProductQuery {
|
||||||
|
pq.order = append(pq.order, o...)
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryProductCategory chains the current query on the "productCategory" edge.
|
||||||
|
func (pq *ProductQuery) QueryProductCategory() *ProductCategoryQuery {
|
||||||
|
query := (&ProductCategoryClient{config: pq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := pq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(product.Table, product.FieldID, selector),
|
||||||
|
sqlgraph.To(productcategory.Table, productcategory.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, product.ProductCategoryTable, product.ProductCategoryPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Product entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Product was found.
|
||||||
|
func (pq *ProductQuery) First(ctx context.Context) (*Product, error) {
|
||||||
|
nodes, err := pq.Limit(1).All(setContextOp(ctx, pq.ctx, "First"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{product.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (pq *ProductQuery) FirstX(ctx context.Context) *Product {
|
||||||
|
node, err := pq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Product ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Product ID was found.
|
||||||
|
func (pq *ProductQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = pq.Limit(1).IDs(setContextOp(ctx, pq.ctx, "FirstID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{product.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (pq *ProductQuery) FirstIDX(ctx context.Context) int {
|
||||||
|
id, err := pq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Product entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Product entity is found.
|
||||||
|
// Returns a *NotFoundError when no Product entities are found.
|
||||||
|
func (pq *ProductQuery) Only(ctx context.Context) (*Product, error) {
|
||||||
|
nodes, err := pq.Limit(2).All(setContextOp(ctx, pq.ctx, "Only"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{product.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{product.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (pq *ProductQuery) OnlyX(ctx context.Context) *Product {
|
||||||
|
node, err := pq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Product ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Product ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (pq *ProductQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = pq.Limit(2).IDs(setContextOp(ctx, pq.ctx, "OnlyID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{product.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{product.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (pq *ProductQuery) OnlyIDX(ctx context.Context) int {
|
||||||
|
id, err := pq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of Products.
|
||||||
|
func (pq *ProductQuery) All(ctx context.Context) ([]*Product, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, "All")
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*Product, *ProductQuery]()
|
||||||
|
return withInterceptors[[]*Product](ctx, pq, qr, pq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (pq *ProductQuery) AllX(ctx context.Context) []*Product {
|
||||||
|
nodes, err := pq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Product IDs.
|
||||||
|
func (pq *ProductQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||||
|
if pq.ctx.Unique == nil && pq.path != nil {
|
||||||
|
pq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, "IDs")
|
||||||
|
if err = pq.Select(product.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (pq *ProductQuery) IDsX(ctx context.Context) []int {
|
||||||
|
ids, err := pq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (pq *ProductQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, "Count")
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, pq, querierCount[*ProductQuery](), pq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (pq *ProductQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := pq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (pq *ProductQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, "Exist")
|
||||||
|
switch _, err := pq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (pq *ProductQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := pq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the ProductQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (pq *ProductQuery) Clone() *ProductQuery {
|
||||||
|
if pq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &ProductQuery{
|
||||||
|
config: pq.config,
|
||||||
|
ctx: pq.ctx.Clone(),
|
||||||
|
order: append([]product.OrderOption{}, pq.order...),
|
||||||
|
inters: append([]Interceptor{}, pq.inters...),
|
||||||
|
predicates: append([]predicate.Product{}, pq.predicates...),
|
||||||
|
withProductCategory: pq.withProductCategory.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: pq.sql.Clone(),
|
||||||
|
path: pq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithProductCategory tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "productCategory" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (pq *ProductQuery) WithProductCategory(opts ...func(*ProductCategoryQuery)) *ProductQuery {
|
||||||
|
query := (&ProductCategoryClient{config: pq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
pq.withProductCategory = query
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Name string `json:"name,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Product.Query().
|
||||||
|
// GroupBy(product.FieldName).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (pq *ProductQuery) GroupBy(field string, fields ...string) *ProductGroupBy {
|
||||||
|
pq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &ProductGroupBy{build: pq}
|
||||||
|
grbuild.flds = &pq.ctx.Fields
|
||||||
|
grbuild.label = product.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Name string `json:"name,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Product.Query().
|
||||||
|
// Select(product.FieldName).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (pq *ProductQuery) Select(fields ...string) *ProductSelect {
|
||||||
|
pq.ctx.Fields = append(pq.ctx.Fields, fields...)
|
||||||
|
sbuild := &ProductSelect{ProductQuery: pq}
|
||||||
|
sbuild.label = product.Label
|
||||||
|
sbuild.flds, sbuild.scan = &pq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a ProductSelect configured with the given aggregations.
|
||||||
|
func (pq *ProductQuery) Aggregate(fns ...AggregateFunc) *ProductSelect {
|
||||||
|
return pq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProductQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range pq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, pq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range pq.ctx.Fields {
|
||||||
|
if !product.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pq.path != nil {
|
||||||
|
prev, err := pq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProductQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Product, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Product{}
|
||||||
|
_spec = pq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
pq.withProductCategory != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*Product).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &Product{config: pq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, pq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := pq.withProductCategory; query != nil {
|
||||||
|
if err := pq.loadProductCategory(ctx, query, nodes,
|
||||||
|
func(n *Product) { n.Edges.ProductCategory = []*ProductCategory{} },
|
||||||
|
func(n *Product, e *ProductCategory) { n.Edges.ProductCategory = append(n.Edges.ProductCategory, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProductQuery) loadProductCategory(ctx context.Context, query *ProductCategoryQuery, nodes []*Product, init func(*Product), assign func(*Product, *ProductCategory)) error {
|
||||||
|
edgeIDs := make([]driver.Value, len(nodes))
|
||||||
|
byID := make(map[int]*Product)
|
||||||
|
nids := make(map[int]map[*Product]struct{})
|
||||||
|
for i, node := range nodes {
|
||||||
|
edgeIDs[i] = node.ID
|
||||||
|
byID[node.ID] = node
|
||||||
|
if init != nil {
|
||||||
|
init(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.Where(func(s *sql.Selector) {
|
||||||
|
joinT := sql.Table(product.ProductCategoryTable)
|
||||||
|
s.Join(joinT).On(s.C(productcategory.FieldID), joinT.C(product.ProductCategoryPrimaryKey[0]))
|
||||||
|
s.Where(sql.InValues(joinT.C(product.ProductCategoryPrimaryKey[1]), edgeIDs...))
|
||||||
|
columns := s.SelectedColumns()
|
||||||
|
s.Select(joinT.C(product.ProductCategoryPrimaryKey[1]))
|
||||||
|
s.AppendSelect(columns...)
|
||||||
|
s.SetDistinct(false)
|
||||||
|
})
|
||||||
|
if err := query.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||||
|
assign := spec.Assign
|
||||||
|
values := spec.ScanValues
|
||||||
|
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
values, err := values(columns[1:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||||
|
}
|
||||||
|
spec.Assign = func(columns []string, values []any) error {
|
||||||
|
outValue := int(values[0].(*sql.NullInt64).Int64)
|
||||||
|
inValue := int(values[1].(*sql.NullInt64).Int64)
|
||||||
|
if nids[inValue] == nil {
|
||||||
|
nids[inValue] = map[*Product]struct{}{byID[outValue]: {}}
|
||||||
|
return assign(columns[1:], values[1:])
|
||||||
|
}
|
||||||
|
nids[inValue][byID[outValue]] = struct{}{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
neighbors, err := withInterceptors[[]*ProductCategory](ctx, query, qr, query.inters)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected "productCategory" node returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for kn := range nodes {
|
||||||
|
assign(kn, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProductQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := pq.querySpec()
|
||||||
|
_spec.Node.Columns = pq.ctx.Fields
|
||||||
|
if len(pq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = pq.ctx.Unique != nil && *pq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, pq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProductQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(product.Table, product.Columns, sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt))
|
||||||
|
_spec.From = pq.sql
|
||||||
|
if unique := pq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if pq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := pq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, product.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != product.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := pq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := pq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := pq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := pq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProductQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(pq.driver.Dialect())
|
||||||
|
t1 := builder.Table(product.Table)
|
||||||
|
columns := pq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = product.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if pq.sql != nil {
|
||||||
|
selector = pq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if pq.ctx.Unique != nil && *pq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range pq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range pq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := pq.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := pq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductGroupBy is the group-by builder for Product entities.
|
||||||
|
type ProductGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *ProductQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (pgb *ProductGroupBy) Aggregate(fns ...AggregateFunc) *ProductGroupBy {
|
||||||
|
pgb.fns = append(pgb.fns, fns...)
|
||||||
|
return pgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (pgb *ProductGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, pgb.build.ctx, "GroupBy")
|
||||||
|
if err := pgb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*ProductQuery, *ProductGroupBy](ctx, pgb.build, pgb, pgb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pgb *ProductGroupBy) sqlScan(ctx context.Context, root *ProductQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(pgb.fns))
|
||||||
|
for _, fn := range pgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*pgb.flds)+len(pgb.fns))
|
||||||
|
for _, f := range *pgb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*pgb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := pgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductSelect is the builder for selecting fields of Product entities.
|
||||||
|
type ProductSelect struct {
|
||||||
|
*ProductQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (ps *ProductSelect) Aggregate(fns ...AggregateFunc) *ProductSelect {
|
||||||
|
ps.fns = append(ps.fns, fns...)
|
||||||
|
return ps
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (ps *ProductSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, ps.ctx, "Select")
|
||||||
|
if err := ps.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*ProductQuery, *ProductSelect](ctx, ps.ProductQuery, ps, ps.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *ProductSelect) sqlScan(ctx context.Context, root *ProductQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(ps.fns))
|
||||||
|
for _, fn := range ps.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*ps.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := ps.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
737
ent/product_update.go
Normal file
737
ent/product_update.go
Normal file
@ -0,0 +1,737 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductUpdate is the builder for updating Product entities.
|
||||||
|
type ProductUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProductMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProductUpdate builder.
|
||||||
|
func (pu *ProductUpdate) Where(ps ...predicate.Product) *ProductUpdate {
|
||||||
|
pu.mutation.Where(ps...)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (pu *ProductUpdate) SetName(s string) *ProductUpdate {
|
||||||
|
pu.mutation.SetName(s)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (pu *ProductUpdate) SetNillableName(s *string) *ProductUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pu.SetName(*s)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (pu *ProductUpdate) SetDescription(s string) *ProductUpdate {
|
||||||
|
pu.mutation.SetDescription(s)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (pu *ProductUpdate) SetNillableDescription(s *string) *ProductUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pu.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (pu *ProductUpdate) ClearDescription() *ProductUpdate {
|
||||||
|
pu.mutation.ClearDescription()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPrice sets the "price" field.
|
||||||
|
func (pu *ProductUpdate) SetPrice(f float64) *ProductUpdate {
|
||||||
|
pu.mutation.ResetPrice()
|
||||||
|
pu.mutation.SetPrice(f)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePrice sets the "price" field if the given value is not nil.
|
||||||
|
func (pu *ProductUpdate) SetNillablePrice(f *float64) *ProductUpdate {
|
||||||
|
if f != nil {
|
||||||
|
pu.SetPrice(*f)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPrice adds f to the "price" field.
|
||||||
|
func (pu *ProductUpdate) AddPrice(f float64) *ProductUpdate {
|
||||||
|
pu.mutation.AddPrice(f)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOriginalPrice sets the "original_price" field.
|
||||||
|
func (pu *ProductUpdate) SetOriginalPrice(f float64) *ProductUpdate {
|
||||||
|
pu.mutation.ResetOriginalPrice()
|
||||||
|
pu.mutation.SetOriginalPrice(f)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
|
||||||
|
func (pu *ProductUpdate) SetNillableOriginalPrice(f *float64) *ProductUpdate {
|
||||||
|
if f != nil {
|
||||||
|
pu.SetOriginalPrice(*f)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddOriginalPrice adds f to the "original_price" field.
|
||||||
|
func (pu *ProductUpdate) AddOriginalPrice(f float64) *ProductUpdate {
|
||||||
|
pu.mutation.AddOriginalPrice(f)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetQuantity sets the "quantity" field.
|
||||||
|
func (pu *ProductUpdate) SetQuantity(i int) *ProductUpdate {
|
||||||
|
pu.mutation.ResetQuantity()
|
||||||
|
pu.mutation.SetQuantity(i)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
|
||||||
|
func (pu *ProductUpdate) SetNillableQuantity(i *int) *ProductUpdate {
|
||||||
|
if i != nil {
|
||||||
|
pu.SetQuantity(*i)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddQuantity adds i to the "quantity" field.
|
||||||
|
func (pu *ProductUpdate) AddQuantity(i int) *ProductUpdate {
|
||||||
|
pu.mutation.AddQuantity(i)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (pu *ProductUpdate) SetStatus(b bool) *ProductUpdate {
|
||||||
|
pu.mutation.SetStatus(b)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (pu *ProductUpdate) SetNillableStatus(b *bool) *ProductUpdate {
|
||||||
|
if b != nil {
|
||||||
|
pu.SetStatus(*b)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (pu *ProductUpdate) SetCreatedAt(t time.Time) *ProductUpdate {
|
||||||
|
pu.mutation.SetCreatedAt(t)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (pu *ProductUpdate) SetNillableCreatedAt(t *time.Time) *ProductUpdate {
|
||||||
|
if t != nil {
|
||||||
|
pu.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pu *ProductUpdate) SetUpdatedAt(t time.Time) *ProductUpdate {
|
||||||
|
pu.mutation.SetUpdatedAt(t)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductCategoryIDs adds the "productCategory" edge to the ProductCategory entity by IDs.
|
||||||
|
func (pu *ProductUpdate) AddProductCategoryIDs(ids ...int) *ProductUpdate {
|
||||||
|
pu.mutation.AddProductCategoryIDs(ids...)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductCategory adds the "productCategory" edges to the ProductCategory entity.
|
||||||
|
func (pu *ProductUpdate) AddProductCategory(p ...*ProductCategory) *ProductUpdate {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pu.AddProductCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProductMutation object of the builder.
|
||||||
|
func (pu *ProductUpdate) Mutation() *ProductMutation {
|
||||||
|
return pu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProductCategory clears all "productCategory" edges to the ProductCategory entity.
|
||||||
|
func (pu *ProductUpdate) ClearProductCategory() *ProductUpdate {
|
||||||
|
pu.mutation.ClearProductCategory()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveProductCategoryIDs removes the "productCategory" edge to ProductCategory entities by IDs.
|
||||||
|
func (pu *ProductUpdate) RemoveProductCategoryIDs(ids ...int) *ProductUpdate {
|
||||||
|
pu.mutation.RemoveProductCategoryIDs(ids...)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveProductCategory removes "productCategory" edges to ProductCategory entities.
|
||||||
|
func (pu *ProductUpdate) RemoveProductCategory(p ...*ProductCategory) *ProductUpdate {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pu.RemoveProductCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (pu *ProductUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
pu.defaults()
|
||||||
|
return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pu *ProductUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := pu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pu *ProductUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := pu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pu *ProductUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := pu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pu *ProductUpdate) defaults() {
|
||||||
|
if _, ok := pu.mutation.UpdatedAt(); !ok {
|
||||||
|
v := product.UpdateDefaultUpdatedAt()
|
||||||
|
pu.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (pu *ProductUpdate) check() error {
|
||||||
|
if v, ok := pu.mutation.Price(); ok {
|
||||||
|
if err := product.PriceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "price", err: fmt.Errorf(`ent: validator failed for field "Product.price": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := pu.mutation.OriginalPrice(); ok {
|
||||||
|
if err := product.OriginalPriceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "original_price", err: fmt.Errorf(`ent: validator failed for field "Product.original_price": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := pu.mutation.Quantity(); ok {
|
||||||
|
if err := product.QuantityValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "quantity", err: fmt.Errorf(`ent: validator failed for field "Product.quantity": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pu *ProductUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
if err := pu.check(); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(product.Table, product.Columns, sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt))
|
||||||
|
if ps := pu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Name(); ok {
|
||||||
|
_spec.SetField(product.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Description(); ok {
|
||||||
|
_spec.SetField(product.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(product.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Price(); ok {
|
||||||
|
_spec.SetField(product.FieldPrice, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.AddedPrice(); ok {
|
||||||
|
_spec.AddField(product.FieldPrice, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.OriginalPrice(); ok {
|
||||||
|
_spec.SetField(product.FieldOriginalPrice, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.AddedOriginalPrice(); ok {
|
||||||
|
_spec.AddField(product.FieldOriginalPrice, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Quantity(); ok {
|
||||||
|
_spec.SetField(product.FieldQuantity, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.AddedQuantity(); ok {
|
||||||
|
_spec.AddField(product.FieldQuantity, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Status(); ok {
|
||||||
|
_spec.SetField(product.FieldStatus, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(product.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(product.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.ProductCategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: product.ProductCategoryTable,
|
||||||
|
Columns: product.ProductCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pu.mutation.RemovedProductCategoryIDs(); len(nodes) > 0 && !pu.mutation.ProductCategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: product.ProductCategoryTable,
|
||||||
|
Columns: product.ProductCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pu.mutation.ProductCategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: product.ProductCategoryTable,
|
||||||
|
Columns: product.ProductCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{product.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
pu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductUpdateOne is the builder for updating a single Product entity.
|
||||||
|
type ProductUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProductMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (puo *ProductUpdateOne) SetName(s string) *ProductUpdateOne {
|
||||||
|
puo.mutation.SetName(s)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (puo *ProductUpdateOne) SetNillableName(s *string) *ProductUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
puo.SetName(*s)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (puo *ProductUpdateOne) SetDescription(s string) *ProductUpdateOne {
|
||||||
|
puo.mutation.SetDescription(s)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (puo *ProductUpdateOne) SetNillableDescription(s *string) *ProductUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
puo.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (puo *ProductUpdateOne) ClearDescription() *ProductUpdateOne {
|
||||||
|
puo.mutation.ClearDescription()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPrice sets the "price" field.
|
||||||
|
func (puo *ProductUpdateOne) SetPrice(f float64) *ProductUpdateOne {
|
||||||
|
puo.mutation.ResetPrice()
|
||||||
|
puo.mutation.SetPrice(f)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePrice sets the "price" field if the given value is not nil.
|
||||||
|
func (puo *ProductUpdateOne) SetNillablePrice(f *float64) *ProductUpdateOne {
|
||||||
|
if f != nil {
|
||||||
|
puo.SetPrice(*f)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPrice adds f to the "price" field.
|
||||||
|
func (puo *ProductUpdateOne) AddPrice(f float64) *ProductUpdateOne {
|
||||||
|
puo.mutation.AddPrice(f)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOriginalPrice sets the "original_price" field.
|
||||||
|
func (puo *ProductUpdateOne) SetOriginalPrice(f float64) *ProductUpdateOne {
|
||||||
|
puo.mutation.ResetOriginalPrice()
|
||||||
|
puo.mutation.SetOriginalPrice(f)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
|
||||||
|
func (puo *ProductUpdateOne) SetNillableOriginalPrice(f *float64) *ProductUpdateOne {
|
||||||
|
if f != nil {
|
||||||
|
puo.SetOriginalPrice(*f)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddOriginalPrice adds f to the "original_price" field.
|
||||||
|
func (puo *ProductUpdateOne) AddOriginalPrice(f float64) *ProductUpdateOne {
|
||||||
|
puo.mutation.AddOriginalPrice(f)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetQuantity sets the "quantity" field.
|
||||||
|
func (puo *ProductUpdateOne) SetQuantity(i int) *ProductUpdateOne {
|
||||||
|
puo.mutation.ResetQuantity()
|
||||||
|
puo.mutation.SetQuantity(i)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
|
||||||
|
func (puo *ProductUpdateOne) SetNillableQuantity(i *int) *ProductUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
puo.SetQuantity(*i)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddQuantity adds i to the "quantity" field.
|
||||||
|
func (puo *ProductUpdateOne) AddQuantity(i int) *ProductUpdateOne {
|
||||||
|
puo.mutation.AddQuantity(i)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (puo *ProductUpdateOne) SetStatus(b bool) *ProductUpdateOne {
|
||||||
|
puo.mutation.SetStatus(b)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (puo *ProductUpdateOne) SetNillableStatus(b *bool) *ProductUpdateOne {
|
||||||
|
if b != nil {
|
||||||
|
puo.SetStatus(*b)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (puo *ProductUpdateOne) SetCreatedAt(t time.Time) *ProductUpdateOne {
|
||||||
|
puo.mutation.SetCreatedAt(t)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (puo *ProductUpdateOne) SetNillableCreatedAt(t *time.Time) *ProductUpdateOne {
|
||||||
|
if t != nil {
|
||||||
|
puo.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (puo *ProductUpdateOne) SetUpdatedAt(t time.Time) *ProductUpdateOne {
|
||||||
|
puo.mutation.SetUpdatedAt(t)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductCategoryIDs adds the "productCategory" edge to the ProductCategory entity by IDs.
|
||||||
|
func (puo *ProductUpdateOne) AddProductCategoryIDs(ids ...int) *ProductUpdateOne {
|
||||||
|
puo.mutation.AddProductCategoryIDs(ids...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductCategory adds the "productCategory" edges to the ProductCategory entity.
|
||||||
|
func (puo *ProductUpdateOne) AddProductCategory(p ...*ProductCategory) *ProductUpdateOne {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return puo.AddProductCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProductMutation object of the builder.
|
||||||
|
func (puo *ProductUpdateOne) Mutation() *ProductMutation {
|
||||||
|
return puo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProductCategory clears all "productCategory" edges to the ProductCategory entity.
|
||||||
|
func (puo *ProductUpdateOne) ClearProductCategory() *ProductUpdateOne {
|
||||||
|
puo.mutation.ClearProductCategory()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveProductCategoryIDs removes the "productCategory" edge to ProductCategory entities by IDs.
|
||||||
|
func (puo *ProductUpdateOne) RemoveProductCategoryIDs(ids ...int) *ProductUpdateOne {
|
||||||
|
puo.mutation.RemoveProductCategoryIDs(ids...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveProductCategory removes "productCategory" edges to ProductCategory entities.
|
||||||
|
func (puo *ProductUpdateOne) RemoveProductCategory(p ...*ProductCategory) *ProductUpdateOne {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return puo.RemoveProductCategoryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProductUpdate builder.
|
||||||
|
func (puo *ProductUpdateOne) Where(ps ...predicate.Product) *ProductUpdateOne {
|
||||||
|
puo.mutation.Where(ps...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (puo *ProductUpdateOne) Select(field string, fields ...string) *ProductUpdateOne {
|
||||||
|
puo.fields = append([]string{field}, fields...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Product entity.
|
||||||
|
func (puo *ProductUpdateOne) Save(ctx context.Context) (*Product, error) {
|
||||||
|
puo.defaults()
|
||||||
|
return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (puo *ProductUpdateOne) SaveX(ctx context.Context) *Product {
|
||||||
|
node, err := puo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (puo *ProductUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := puo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (puo *ProductUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := puo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (puo *ProductUpdateOne) defaults() {
|
||||||
|
if _, ok := puo.mutation.UpdatedAt(); !ok {
|
||||||
|
v := product.UpdateDefaultUpdatedAt()
|
||||||
|
puo.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (puo *ProductUpdateOne) check() error {
|
||||||
|
if v, ok := puo.mutation.Price(); ok {
|
||||||
|
if err := product.PriceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "price", err: fmt.Errorf(`ent: validator failed for field "Product.price": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := puo.mutation.OriginalPrice(); ok {
|
||||||
|
if err := product.OriginalPriceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "original_price", err: fmt.Errorf(`ent: validator failed for field "Product.original_price": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := puo.mutation.Quantity(); ok {
|
||||||
|
if err := product.QuantityValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "quantity", err: fmt.Errorf(`ent: validator failed for field "Product.quantity": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (puo *ProductUpdateOne) sqlSave(ctx context.Context) (_node *Product, err error) {
|
||||||
|
if err := puo.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(product.Table, product.Columns, sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt))
|
||||||
|
id, ok := puo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Product.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := puo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, product.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !product.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != product.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := puo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Name(); ok {
|
||||||
|
_spec.SetField(product.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Description(); ok {
|
||||||
|
_spec.SetField(product.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(product.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Price(); ok {
|
||||||
|
_spec.SetField(product.FieldPrice, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.AddedPrice(); ok {
|
||||||
|
_spec.AddField(product.FieldPrice, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.OriginalPrice(); ok {
|
||||||
|
_spec.SetField(product.FieldOriginalPrice, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.AddedOriginalPrice(); ok {
|
||||||
|
_spec.AddField(product.FieldOriginalPrice, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Quantity(); ok {
|
||||||
|
_spec.SetField(product.FieldQuantity, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.AddedQuantity(); ok {
|
||||||
|
_spec.AddField(product.FieldQuantity, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Status(); ok {
|
||||||
|
_spec.SetField(product.FieldStatus, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(product.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(product.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.ProductCategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: product.ProductCategoryTable,
|
||||||
|
Columns: product.ProductCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := puo.mutation.RemovedProductCategoryIDs(); len(nodes) > 0 && !puo.mutation.ProductCategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: product.ProductCategoryTable,
|
||||||
|
Columns: product.ProductCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := puo.mutation.ProductCategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: product.ProductCategoryTable,
|
||||||
|
Columns: product.ProductCategoryPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Product{config: puo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{product.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
puo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
192
ent/productcategory.go
Normal file
192
ent/productcategory.go
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductCategory is the model entity for the ProductCategory schema.
|
||||||
|
type ProductCategory 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"`
|
||||||
|
// Description holds the value of the "description" field.
|
||||||
|
Description *string `json:"description,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 ProductCategoryQuery when eager-loading is set.
|
||||||
|
Edges ProductCategoryEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategoryEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type ProductCategoryEdges struct {
|
||||||
|
// Products holds the value of the products edge.
|
||||||
|
Products []*Product `json:"products,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductsOrErr returns the Products value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e ProductCategoryEdges) ProductsOrErr() ([]*Product, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
return e.Products, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "products"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*ProductCategory) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case productcategory.FieldStatus:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case productcategory.FieldID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case productcategory.FieldName, productcategory.FieldSlug, productcategory.FieldDescription:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case productcategory.FieldCreatedAt, productcategory.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 ProductCategory fields.
|
||||||
|
func (pc *ProductCategory) 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 productcategory.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
pc.ID = int(value.Int64)
|
||||||
|
case productcategory.FieldName:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pc.Name = value.String
|
||||||
|
}
|
||||||
|
case productcategory.FieldSlug:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field slug", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pc.Slug = value.String
|
||||||
|
}
|
||||||
|
case productcategory.FieldDescription:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pc.Description = new(string)
|
||||||
|
*pc.Description = value.String
|
||||||
|
}
|
||||||
|
case productcategory.FieldStatus:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pc.Status = value.Bool
|
||||||
|
}
|
||||||
|
case productcategory.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 {
|
||||||
|
pc.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case productcategory.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 {
|
||||||
|
pc.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
pc.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the ProductCategory.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (pc *ProductCategory) Value(name string) (ent.Value, error) {
|
||||||
|
return pc.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryProducts queries the "products" edge of the ProductCategory entity.
|
||||||
|
func (pc *ProductCategory) QueryProducts() *ProductQuery {
|
||||||
|
return NewProductCategoryClient(pc.config).QueryProducts(pc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this ProductCategory.
|
||||||
|
// Note that you need to call ProductCategory.Unwrap() before calling this method if this ProductCategory
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (pc *ProductCategory) Update() *ProductCategoryUpdateOne {
|
||||||
|
return NewProductCategoryClient(pc.config).UpdateOne(pc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the ProductCategory 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 (pc *ProductCategory) Unwrap() *ProductCategory {
|
||||||
|
_tx, ok := pc.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: ProductCategory is not a transactional entity")
|
||||||
|
}
|
||||||
|
pc.config.driver = _tx.drv
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (pc *ProductCategory) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("ProductCategory(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", pc.ID))
|
||||||
|
builder.WriteString("name=")
|
||||||
|
builder.WriteString(pc.Name)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("slug=")
|
||||||
|
builder.WriteString(pc.Slug)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := pc.Description; v != nil {
|
||||||
|
builder.WriteString("description=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("status=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", pc.Status))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(pc.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(pc.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategories is a parsable slice of ProductCategory.
|
||||||
|
type ProductCategories []*ProductCategory
|
137
ent/productcategory/productcategory.go
Normal file
137
ent/productcategory/productcategory.go
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package productcategory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the productcategory type in the database.
|
||||||
|
Label = "product_category"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
FieldName = "name"
|
||||||
|
// FieldSlug holds the string denoting the slug field in the database.
|
||||||
|
FieldSlug = "slug"
|
||||||
|
// FieldDescription holds the string denoting the description field in the database.
|
||||||
|
FieldDescription = "description"
|
||||||
|
// FieldStatus holds the string denoting the status field in the database.
|
||||||
|
FieldStatus = "status"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// EdgeProducts holds the string denoting the products edge name in mutations.
|
||||||
|
EdgeProducts = "products"
|
||||||
|
// Table holds the table name of the productcategory in the database.
|
||||||
|
Table = "product_categories"
|
||||||
|
// ProductsTable is the table that holds the products relation/edge. The primary key declared below.
|
||||||
|
ProductsTable = "product_category_products"
|
||||||
|
// ProductsInverseTable is the table name for the Product entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "product" package.
|
||||||
|
ProductsInverseTable = "products"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for productcategory fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldName,
|
||||||
|
FieldSlug,
|
||||||
|
FieldDescription,
|
||||||
|
FieldStatus,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ProductsPrimaryKey and ProductsColumn2 are the table columns denoting the
|
||||||
|
// primary key for the products relation (M2M).
|
||||||
|
ProductsPrimaryKey = []string{"product_category_id", "product_id"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultName holds the default value on creation for the "name" field.
|
||||||
|
DefaultName string
|
||||||
|
// DefaultStatus holds the default value on creation for the "status" field.
|
||||||
|
DefaultStatus bool
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the ProductCategory queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByName orders the results by the name field.
|
||||||
|
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// BySlug orders the results by the slug field.
|
||||||
|
func BySlug(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldSlug, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDescription orders the results by the description field.
|
||||||
|
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByStatus orders the results by the status field.
|
||||||
|
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProductsCount orders the results by products count.
|
||||||
|
func ByProductsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newProductsStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProducts orders the results by products terms.
|
||||||
|
func ByProducts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newProductsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newProductsStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(ProductsInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, ProductsTable, ProductsPrimaryKey...),
|
||||||
|
)
|
||||||
|
}
|
419
ent/productcategory/where.go
Normal file
419
ent/productcategory/where.go
Normal file
@ -0,0 +1,419 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package productcategory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||||
|
func Name(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slug applies equality check predicate on the "slug" field. It's identical to SlugEQ.
|
||||||
|
func Slug(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||||
|
func Description(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
|
||||||
|
func Status(v bool) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEQ applies the EQ predicate on the "name" field.
|
||||||
|
func NameEQ(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||||
|
func NameNEQ(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameIn applies the In predicate on the "name" field.
|
||||||
|
func NameIn(vs ...string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||||
|
func NameNotIn(vs ...string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNotIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGT applies the GT predicate on the "name" field.
|
||||||
|
func NameGT(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGTE applies the GTE predicate on the "name" field.
|
||||||
|
func NameGTE(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLT applies the LT predicate on the "name" field.
|
||||||
|
func NameLT(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLTE applies the LTE predicate on the "name" field.
|
||||||
|
func NameLTE(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContains applies the Contains predicate on the "name" field.
|
||||||
|
func NameContains(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldContains(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||||
|
func NameHasPrefix(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldHasPrefix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||||
|
func NameHasSuffix(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldHasSuffix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||||
|
func NameEqualFold(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEqualFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||||
|
func NameContainsFold(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldContainsFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugEQ applies the EQ predicate on the "slug" field.
|
||||||
|
func SlugEQ(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugNEQ applies the NEQ predicate on the "slug" field.
|
||||||
|
func SlugNEQ(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNEQ(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugIn applies the In predicate on the "slug" field.
|
||||||
|
func SlugIn(vs ...string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldIn(FieldSlug, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugNotIn applies the NotIn predicate on the "slug" field.
|
||||||
|
func SlugNotIn(vs ...string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNotIn(FieldSlug, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugGT applies the GT predicate on the "slug" field.
|
||||||
|
func SlugGT(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGT(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugGTE applies the GTE predicate on the "slug" field.
|
||||||
|
func SlugGTE(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGTE(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugLT applies the LT predicate on the "slug" field.
|
||||||
|
func SlugLT(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLT(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugLTE applies the LTE predicate on the "slug" field.
|
||||||
|
func SlugLTE(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLTE(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugContains applies the Contains predicate on the "slug" field.
|
||||||
|
func SlugContains(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldContains(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugHasPrefix applies the HasPrefix predicate on the "slug" field.
|
||||||
|
func SlugHasPrefix(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldHasPrefix(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugHasSuffix applies the HasSuffix predicate on the "slug" field.
|
||||||
|
func SlugHasSuffix(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldHasSuffix(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugEqualFold applies the EqualFold predicate on the "slug" field.
|
||||||
|
func SlugEqualFold(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEqualFold(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SlugContainsFold applies the ContainsFold predicate on the "slug" field.
|
||||||
|
func SlugContainsFold(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldContainsFold(FieldSlug, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||||
|
func DescriptionEQ(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||||
|
func DescriptionNEQ(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIn applies the In predicate on the "description" field.
|
||||||
|
func DescriptionIn(vs ...string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||||
|
func DescriptionNotIn(vs ...string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNotIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGT applies the GT predicate on the "description" field.
|
||||||
|
func DescriptionGT(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||||
|
func DescriptionGTE(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLT applies the LT predicate on the "description" field.
|
||||||
|
func DescriptionLT(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||||
|
func DescriptionLTE(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||||
|
func DescriptionContains(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldContains(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||||
|
func DescriptionHasPrefix(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldHasPrefix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||||
|
func DescriptionHasSuffix(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldHasSuffix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||||
|
func DescriptionIsNil() predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldIsNull(FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||||
|
func DescriptionNotNil() predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNotNull(FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||||
|
func DescriptionEqualFold(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEqualFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||||
|
func DescriptionContainsFold(v string) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldContainsFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusEQ applies the EQ predicate on the "status" field.
|
||||||
|
func StatusEQ(v bool) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||||
|
func StatusNEQ(v bool) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasProducts applies the HasEdge predicate on the "products" edge.
|
||||||
|
func HasProducts() predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, ProductsTable, ProductsPrimaryKey...),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasProductsWith applies the HasEdge predicate on the "products" edge with a given conditions (other predicates).
|
||||||
|
func HasProductsWith(preds ...predicate.Product) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(func(s *sql.Selector) {
|
||||||
|
step := newProductsStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.ProductCategory) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.ProductCategory) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.ProductCategory) predicate.ProductCategory {
|
||||||
|
return predicate.ProductCategory(sql.NotPredicates(p))
|
||||||
|
}
|
340
ent/productcategory_create.go
Normal file
340
ent/productcategory_create.go
Normal file
@ -0,0 +1,340 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductCategoryCreate is the builder for creating a ProductCategory entity.
|
||||||
|
type ProductCategoryCreate struct {
|
||||||
|
config
|
||||||
|
mutation *ProductCategoryMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (pcc *ProductCategoryCreate) SetName(s string) *ProductCategoryCreate {
|
||||||
|
pcc.mutation.SetName(s)
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (pcc *ProductCategoryCreate) SetNillableName(s *string) *ProductCategoryCreate {
|
||||||
|
if s != nil {
|
||||||
|
pcc.SetName(*s)
|
||||||
|
}
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (pcc *ProductCategoryCreate) SetSlug(s string) *ProductCategoryCreate {
|
||||||
|
pcc.mutation.SetSlug(s)
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (pcc *ProductCategoryCreate) SetDescription(s string) *ProductCategoryCreate {
|
||||||
|
pcc.mutation.SetDescription(s)
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (pcc *ProductCategoryCreate) SetNillableDescription(s *string) *ProductCategoryCreate {
|
||||||
|
if s != nil {
|
||||||
|
pcc.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (pcc *ProductCategoryCreate) SetStatus(b bool) *ProductCategoryCreate {
|
||||||
|
pcc.mutation.SetStatus(b)
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (pcc *ProductCategoryCreate) SetNillableStatus(b *bool) *ProductCategoryCreate {
|
||||||
|
if b != nil {
|
||||||
|
pcc.SetStatus(*b)
|
||||||
|
}
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (pcc *ProductCategoryCreate) SetCreatedAt(t time.Time) *ProductCategoryCreate {
|
||||||
|
pcc.mutation.SetCreatedAt(t)
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (pcc *ProductCategoryCreate) SetNillableCreatedAt(t *time.Time) *ProductCategoryCreate {
|
||||||
|
if t != nil {
|
||||||
|
pcc.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pcc *ProductCategoryCreate) SetUpdatedAt(t time.Time) *ProductCategoryCreate {
|
||||||
|
pcc.mutation.SetUpdatedAt(t)
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (pcc *ProductCategoryCreate) SetNillableUpdatedAt(t *time.Time) *ProductCategoryCreate {
|
||||||
|
if t != nil {
|
||||||
|
pcc.SetUpdatedAt(*t)
|
||||||
|
}
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductIDs adds the "products" edge to the Product entity by IDs.
|
||||||
|
func (pcc *ProductCategoryCreate) AddProductIDs(ids ...int) *ProductCategoryCreate {
|
||||||
|
pcc.mutation.AddProductIDs(ids...)
|
||||||
|
return pcc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProducts adds the "products" edges to the Product entity.
|
||||||
|
func (pcc *ProductCategoryCreate) AddProducts(p ...*Product) *ProductCategoryCreate {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pcc.AddProductIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProductCategoryMutation object of the builder.
|
||||||
|
func (pcc *ProductCategoryCreate) Mutation() *ProductCategoryMutation {
|
||||||
|
return pcc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the ProductCategory in the database.
|
||||||
|
func (pcc *ProductCategoryCreate) Save(ctx context.Context) (*ProductCategory, error) {
|
||||||
|
pcc.defaults()
|
||||||
|
return withHooks(ctx, pcc.sqlSave, pcc.mutation, pcc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (pcc *ProductCategoryCreate) SaveX(ctx context.Context) *ProductCategory {
|
||||||
|
v, err := pcc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pcc *ProductCategoryCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := pcc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pcc *ProductCategoryCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := pcc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pcc *ProductCategoryCreate) defaults() {
|
||||||
|
if _, ok := pcc.mutation.Name(); !ok {
|
||||||
|
v := productcategory.DefaultName
|
||||||
|
pcc.mutation.SetName(v)
|
||||||
|
}
|
||||||
|
if _, ok := pcc.mutation.Status(); !ok {
|
||||||
|
v := productcategory.DefaultStatus
|
||||||
|
pcc.mutation.SetStatus(v)
|
||||||
|
}
|
||||||
|
if _, ok := pcc.mutation.CreatedAt(); !ok {
|
||||||
|
v := productcategory.DefaultCreatedAt
|
||||||
|
pcc.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := pcc.mutation.UpdatedAt(); !ok {
|
||||||
|
v := productcategory.DefaultUpdatedAt
|
||||||
|
pcc.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (pcc *ProductCategoryCreate) check() error {
|
||||||
|
if _, ok := pcc.mutation.Name(); !ok {
|
||||||
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "ProductCategory.name"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pcc.mutation.Slug(); !ok {
|
||||||
|
return &ValidationError{Name: "slug", err: errors.New(`ent: missing required field "ProductCategory.slug"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pcc.mutation.Status(); !ok {
|
||||||
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "ProductCategory.status"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pcc.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ProductCategory.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pcc.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "ProductCategory.updated_at"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcc *ProductCategoryCreate) sqlSave(ctx context.Context) (*ProductCategory, error) {
|
||||||
|
if err := pcc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := pcc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, pcc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int(id)
|
||||||
|
pcc.mutation.id = &_node.ID
|
||||||
|
pcc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcc *ProductCategoryCreate) createSpec() (*ProductCategory, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &ProductCategory{config: pcc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(productcategory.Table, sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt))
|
||||||
|
)
|
||||||
|
if value, ok := pcc.mutation.Name(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldName, field.TypeString, value)
|
||||||
|
_node.Name = value
|
||||||
|
}
|
||||||
|
if value, ok := pcc.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldSlug, field.TypeString, value)
|
||||||
|
_node.Slug = value
|
||||||
|
}
|
||||||
|
if value, ok := pcc.mutation.Description(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldDescription, field.TypeString, value)
|
||||||
|
_node.Description = &value
|
||||||
|
}
|
||||||
|
if value, ok := pcc.mutation.Status(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldStatus, field.TypeBool, value)
|
||||||
|
_node.Status = value
|
||||||
|
}
|
||||||
|
if value, ok := pcc.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := pcc.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if nodes := pcc.mutation.ProductsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: productcategory.ProductsTable,
|
||||||
|
Columns: productcategory.ProductsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategoryCreateBulk is the builder for creating many ProductCategory entities in bulk.
|
||||||
|
type ProductCategoryCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*ProductCategoryCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the ProductCategory entities in the database.
|
||||||
|
func (pccb *ProductCategoryCreateBulk) Save(ctx context.Context) ([]*ProductCategory, error) {
|
||||||
|
if pccb.err != nil {
|
||||||
|
return nil, pccb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(pccb.builders))
|
||||||
|
nodes := make([]*ProductCategory, len(pccb.builders))
|
||||||
|
mutators := make([]Mutator, len(pccb.builders))
|
||||||
|
for i := range pccb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := pccb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*ProductCategoryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, pccb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, pccb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, pccb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pccb *ProductCategoryCreateBulk) SaveX(ctx context.Context) []*ProductCategory {
|
||||||
|
v, err := pccb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pccb *ProductCategoryCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := pccb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pccb *ProductCategoryCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := pccb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
88
ent/productcategory_delete.go
Normal file
88
ent/productcategory_delete.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductCategoryDelete is the builder for deleting a ProductCategory entity.
|
||||||
|
type ProductCategoryDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProductCategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProductCategoryDelete builder.
|
||||||
|
func (pcd *ProductCategoryDelete) Where(ps ...predicate.ProductCategory) *ProductCategoryDelete {
|
||||||
|
pcd.mutation.Where(ps...)
|
||||||
|
return pcd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (pcd *ProductCategoryDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, pcd.sqlExec, pcd.mutation, pcd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pcd *ProductCategoryDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := pcd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcd *ProductCategoryDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(productcategory.Table, sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt))
|
||||||
|
if ps := pcd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, pcd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
pcd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategoryDeleteOne is the builder for deleting a single ProductCategory entity.
|
||||||
|
type ProductCategoryDeleteOne struct {
|
||||||
|
pcd *ProductCategoryDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProductCategoryDelete builder.
|
||||||
|
func (pcdo *ProductCategoryDeleteOne) Where(ps ...predicate.ProductCategory) *ProductCategoryDeleteOne {
|
||||||
|
pcdo.pcd.mutation.Where(ps...)
|
||||||
|
return pcdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (pcdo *ProductCategoryDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := pcdo.pcd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{productcategory.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pcdo *ProductCategoryDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := pcdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
636
ent/productcategory_query.go
Normal file
636
ent/productcategory_query.go
Normal file
@ -0,0 +1,636 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductCategoryQuery is the builder for querying ProductCategory entities.
|
||||||
|
type ProductCategoryQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []productcategory.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.ProductCategory
|
||||||
|
withProducts *ProductQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the ProductCategoryQuery builder.
|
||||||
|
func (pcq *ProductCategoryQuery) Where(ps ...predicate.ProductCategory) *ProductCategoryQuery {
|
||||||
|
pcq.predicates = append(pcq.predicates, ps...)
|
||||||
|
return pcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (pcq *ProductCategoryQuery) Limit(limit int) *ProductCategoryQuery {
|
||||||
|
pcq.ctx.Limit = &limit
|
||||||
|
return pcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (pcq *ProductCategoryQuery) Offset(offset int) *ProductCategoryQuery {
|
||||||
|
pcq.ctx.Offset = &offset
|
||||||
|
return pcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (pcq *ProductCategoryQuery) Unique(unique bool) *ProductCategoryQuery {
|
||||||
|
pcq.ctx.Unique = &unique
|
||||||
|
return pcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (pcq *ProductCategoryQuery) Order(o ...productcategory.OrderOption) *ProductCategoryQuery {
|
||||||
|
pcq.order = append(pcq.order, o...)
|
||||||
|
return pcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryProducts chains the current query on the "products" edge.
|
||||||
|
func (pcq *ProductCategoryQuery) QueryProducts() *ProductQuery {
|
||||||
|
query := (&ProductClient{config: pcq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := pcq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := pcq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(productcategory.Table, productcategory.FieldID, selector),
|
||||||
|
sqlgraph.To(product.Table, product.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, productcategory.ProductsTable, productcategory.ProductsPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(pcq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first ProductCategory entity from the query.
|
||||||
|
// Returns a *NotFoundError when no ProductCategory was found.
|
||||||
|
func (pcq *ProductCategoryQuery) First(ctx context.Context) (*ProductCategory, error) {
|
||||||
|
nodes, err := pcq.Limit(1).All(setContextOp(ctx, pcq.ctx, "First"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{productcategory.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (pcq *ProductCategoryQuery) FirstX(ctx context.Context) *ProductCategory {
|
||||||
|
node, err := pcq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first ProductCategory ID from the query.
|
||||||
|
// Returns a *NotFoundError when no ProductCategory ID was found.
|
||||||
|
func (pcq *ProductCategoryQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = pcq.Limit(1).IDs(setContextOp(ctx, pcq.ctx, "FirstID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{productcategory.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (pcq *ProductCategoryQuery) FirstIDX(ctx context.Context) int {
|
||||||
|
id, err := pcq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single ProductCategory entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one ProductCategory entity is found.
|
||||||
|
// Returns a *NotFoundError when no ProductCategory entities are found.
|
||||||
|
func (pcq *ProductCategoryQuery) Only(ctx context.Context) (*ProductCategory, error) {
|
||||||
|
nodes, err := pcq.Limit(2).All(setContextOp(ctx, pcq.ctx, "Only"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{productcategory.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{productcategory.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (pcq *ProductCategoryQuery) OnlyX(ctx context.Context) *ProductCategory {
|
||||||
|
node, err := pcq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only ProductCategory ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one ProductCategory ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (pcq *ProductCategoryQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = pcq.Limit(2).IDs(setContextOp(ctx, pcq.ctx, "OnlyID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{productcategory.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{productcategory.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (pcq *ProductCategoryQuery) OnlyIDX(ctx context.Context) int {
|
||||||
|
id, err := pcq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of ProductCategories.
|
||||||
|
func (pcq *ProductCategoryQuery) All(ctx context.Context) ([]*ProductCategory, error) {
|
||||||
|
ctx = setContextOp(ctx, pcq.ctx, "All")
|
||||||
|
if err := pcq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*ProductCategory, *ProductCategoryQuery]()
|
||||||
|
return withInterceptors[[]*ProductCategory](ctx, pcq, qr, pcq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (pcq *ProductCategoryQuery) AllX(ctx context.Context) []*ProductCategory {
|
||||||
|
nodes, err := pcq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of ProductCategory IDs.
|
||||||
|
func (pcq *ProductCategoryQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||||
|
if pcq.ctx.Unique == nil && pcq.path != nil {
|
||||||
|
pcq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, pcq.ctx, "IDs")
|
||||||
|
if err = pcq.Select(productcategory.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (pcq *ProductCategoryQuery) IDsX(ctx context.Context) []int {
|
||||||
|
ids, err := pcq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (pcq *ProductCategoryQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, pcq.ctx, "Count")
|
||||||
|
if err := pcq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, pcq, querierCount[*ProductCategoryQuery](), pcq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (pcq *ProductCategoryQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := pcq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (pcq *ProductCategoryQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, pcq.ctx, "Exist")
|
||||||
|
switch _, err := pcq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (pcq *ProductCategoryQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := pcq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the ProductCategoryQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (pcq *ProductCategoryQuery) Clone() *ProductCategoryQuery {
|
||||||
|
if pcq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &ProductCategoryQuery{
|
||||||
|
config: pcq.config,
|
||||||
|
ctx: pcq.ctx.Clone(),
|
||||||
|
order: append([]productcategory.OrderOption{}, pcq.order...),
|
||||||
|
inters: append([]Interceptor{}, pcq.inters...),
|
||||||
|
predicates: append([]predicate.ProductCategory{}, pcq.predicates...),
|
||||||
|
withProducts: pcq.withProducts.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: pcq.sql.Clone(),
|
||||||
|
path: pcq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithProducts tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "products" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (pcq *ProductCategoryQuery) WithProducts(opts ...func(*ProductQuery)) *ProductCategoryQuery {
|
||||||
|
query := (&ProductClient{config: pcq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
pcq.withProducts = query
|
||||||
|
return pcq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Name string `json:"name,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.ProductCategory.Query().
|
||||||
|
// GroupBy(productcategory.FieldName).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (pcq *ProductCategoryQuery) GroupBy(field string, fields ...string) *ProductCategoryGroupBy {
|
||||||
|
pcq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &ProductCategoryGroupBy{build: pcq}
|
||||||
|
grbuild.flds = &pcq.ctx.Fields
|
||||||
|
grbuild.label = productcategory.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Name string `json:"name,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.ProductCategory.Query().
|
||||||
|
// Select(productcategory.FieldName).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (pcq *ProductCategoryQuery) Select(fields ...string) *ProductCategorySelect {
|
||||||
|
pcq.ctx.Fields = append(pcq.ctx.Fields, fields...)
|
||||||
|
sbuild := &ProductCategorySelect{ProductCategoryQuery: pcq}
|
||||||
|
sbuild.label = productcategory.Label
|
||||||
|
sbuild.flds, sbuild.scan = &pcq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a ProductCategorySelect configured with the given aggregations.
|
||||||
|
func (pcq *ProductCategoryQuery) Aggregate(fns ...AggregateFunc) *ProductCategorySelect {
|
||||||
|
return pcq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcq *ProductCategoryQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range pcq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, pcq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range pcq.ctx.Fields {
|
||||||
|
if !productcategory.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pcq.path != nil {
|
||||||
|
prev, err := pcq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pcq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcq *ProductCategoryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ProductCategory, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*ProductCategory{}
|
||||||
|
_spec = pcq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
pcq.withProducts != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*ProductCategory).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &ProductCategory{config: pcq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, pcq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := pcq.withProducts; query != nil {
|
||||||
|
if err := pcq.loadProducts(ctx, query, nodes,
|
||||||
|
func(n *ProductCategory) { n.Edges.Products = []*Product{} },
|
||||||
|
func(n *ProductCategory, e *Product) { n.Edges.Products = append(n.Edges.Products, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcq *ProductCategoryQuery) loadProducts(ctx context.Context, query *ProductQuery, nodes []*ProductCategory, init func(*ProductCategory), assign func(*ProductCategory, *Product)) error {
|
||||||
|
edgeIDs := make([]driver.Value, len(nodes))
|
||||||
|
byID := make(map[int]*ProductCategory)
|
||||||
|
nids := make(map[int]map[*ProductCategory]struct{})
|
||||||
|
for i, node := range nodes {
|
||||||
|
edgeIDs[i] = node.ID
|
||||||
|
byID[node.ID] = node
|
||||||
|
if init != nil {
|
||||||
|
init(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.Where(func(s *sql.Selector) {
|
||||||
|
joinT := sql.Table(productcategory.ProductsTable)
|
||||||
|
s.Join(joinT).On(s.C(product.FieldID), joinT.C(productcategory.ProductsPrimaryKey[1]))
|
||||||
|
s.Where(sql.InValues(joinT.C(productcategory.ProductsPrimaryKey[0]), edgeIDs...))
|
||||||
|
columns := s.SelectedColumns()
|
||||||
|
s.Select(joinT.C(productcategory.ProductsPrimaryKey[0]))
|
||||||
|
s.AppendSelect(columns...)
|
||||||
|
s.SetDistinct(false)
|
||||||
|
})
|
||||||
|
if err := query.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||||
|
assign := spec.Assign
|
||||||
|
values := spec.ScanValues
|
||||||
|
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
values, err := values(columns[1:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||||
|
}
|
||||||
|
spec.Assign = func(columns []string, values []any) error {
|
||||||
|
outValue := int(values[0].(*sql.NullInt64).Int64)
|
||||||
|
inValue := int(values[1].(*sql.NullInt64).Int64)
|
||||||
|
if nids[inValue] == nil {
|
||||||
|
nids[inValue] = map[*ProductCategory]struct{}{byID[outValue]: {}}
|
||||||
|
return assign(columns[1:], values[1:])
|
||||||
|
}
|
||||||
|
nids[inValue][byID[outValue]] = struct{}{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
neighbors, err := withInterceptors[[]*Product](ctx, query, qr, query.inters)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected "products" node returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for kn := range nodes {
|
||||||
|
assign(kn, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcq *ProductCategoryQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := pcq.querySpec()
|
||||||
|
_spec.Node.Columns = pcq.ctx.Fields
|
||||||
|
if len(pcq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = pcq.ctx.Unique != nil && *pcq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, pcq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcq *ProductCategoryQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(productcategory.Table, productcategory.Columns, sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt))
|
||||||
|
_spec.From = pcq.sql
|
||||||
|
if unique := pcq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if pcq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := pcq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, productcategory.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != productcategory.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := pcq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := pcq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := pcq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := pcq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcq *ProductCategoryQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(pcq.driver.Dialect())
|
||||||
|
t1 := builder.Table(productcategory.Table)
|
||||||
|
columns := pcq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = productcategory.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if pcq.sql != nil {
|
||||||
|
selector = pcq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if pcq.ctx.Unique != nil && *pcq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range pcq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range pcq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := pcq.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := pcq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategoryGroupBy is the group-by builder for ProductCategory entities.
|
||||||
|
type ProductCategoryGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *ProductCategoryQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (pcgb *ProductCategoryGroupBy) Aggregate(fns ...AggregateFunc) *ProductCategoryGroupBy {
|
||||||
|
pcgb.fns = append(pcgb.fns, fns...)
|
||||||
|
return pcgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (pcgb *ProductCategoryGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, pcgb.build.ctx, "GroupBy")
|
||||||
|
if err := pcgb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*ProductCategoryQuery, *ProductCategoryGroupBy](ctx, pcgb.build, pcgb, pcgb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcgb *ProductCategoryGroupBy) sqlScan(ctx context.Context, root *ProductCategoryQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(pcgb.fns))
|
||||||
|
for _, fn := range pcgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*pcgb.flds)+len(pcgb.fns))
|
||||||
|
for _, f := range *pcgb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*pcgb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := pcgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategorySelect is the builder for selecting fields of ProductCategory entities.
|
||||||
|
type ProductCategorySelect struct {
|
||||||
|
*ProductCategoryQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (pcs *ProductCategorySelect) Aggregate(fns ...AggregateFunc) *ProductCategorySelect {
|
||||||
|
pcs.fns = append(pcs.fns, fns...)
|
||||||
|
return pcs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (pcs *ProductCategorySelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, pcs.ctx, "Select")
|
||||||
|
if err := pcs.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*ProductCategoryQuery, *ProductCategorySelect](ctx, pcs.ProductCategoryQuery, pcs, pcs.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcs *ProductCategorySelect) sqlScan(ctx context.Context, root *ProductCategoryQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(pcs.fns))
|
||||||
|
for _, fn := range pcs.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*pcs.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := pcs.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
547
ent/productcategory_update.go
Normal file
547
ent/productcategory_update.go
Normal file
@ -0,0 +1,547 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"tel-commerce/ent/predicate"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductCategoryUpdate is the builder for updating ProductCategory entities.
|
||||||
|
type ProductCategoryUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProductCategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProductCategoryUpdate builder.
|
||||||
|
func (pcu *ProductCategoryUpdate) Where(ps ...predicate.ProductCategory) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.Where(ps...)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetName(s string) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.SetName(s)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetNillableName(s *string) *ProductCategoryUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pcu.SetName(*s)
|
||||||
|
}
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetSlug(s string) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.SetSlug(s)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetDescription(s string) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.SetDescription(s)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetNillableDescription(s *string) *ProductCategoryUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pcu.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (pcu *ProductCategoryUpdate) ClearDescription() *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.ClearDescription()
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetStatus(b bool) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.SetStatus(b)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetNillableStatus(b *bool) *ProductCategoryUpdate {
|
||||||
|
if b != nil {
|
||||||
|
pcu.SetStatus(*b)
|
||||||
|
}
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetCreatedAt(t time.Time) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.SetCreatedAt(t)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetNillableCreatedAt(t *time.Time) *ProductCategoryUpdate {
|
||||||
|
if t != nil {
|
||||||
|
pcu.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pcu *ProductCategoryUpdate) SetUpdatedAt(t time.Time) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.SetUpdatedAt(t)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductIDs adds the "products" edge to the Product entity by IDs.
|
||||||
|
func (pcu *ProductCategoryUpdate) AddProductIDs(ids ...int) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.AddProductIDs(ids...)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProducts adds the "products" edges to the Product entity.
|
||||||
|
func (pcu *ProductCategoryUpdate) AddProducts(p ...*Product) *ProductCategoryUpdate {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pcu.AddProductIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProductCategoryMutation object of the builder.
|
||||||
|
func (pcu *ProductCategoryUpdate) Mutation() *ProductCategoryMutation {
|
||||||
|
return pcu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProducts clears all "products" edges to the Product entity.
|
||||||
|
func (pcu *ProductCategoryUpdate) ClearProducts() *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.ClearProducts()
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveProductIDs removes the "products" edge to Product entities by IDs.
|
||||||
|
func (pcu *ProductCategoryUpdate) RemoveProductIDs(ids ...int) *ProductCategoryUpdate {
|
||||||
|
pcu.mutation.RemoveProductIDs(ids...)
|
||||||
|
return pcu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveProducts removes "products" edges to Product entities.
|
||||||
|
func (pcu *ProductCategoryUpdate) RemoveProducts(p ...*Product) *ProductCategoryUpdate {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pcu.RemoveProductIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (pcu *ProductCategoryUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
pcu.defaults()
|
||||||
|
return withHooks(ctx, pcu.sqlSave, pcu.mutation, pcu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pcu *ProductCategoryUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := pcu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pcu *ProductCategoryUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := pcu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pcu *ProductCategoryUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := pcu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pcu *ProductCategoryUpdate) defaults() {
|
||||||
|
if _, ok := pcu.mutation.UpdatedAt(); !ok {
|
||||||
|
v := productcategory.UpdateDefaultUpdatedAt()
|
||||||
|
pcu.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcu *ProductCategoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(productcategory.Table, productcategory.Columns, sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt))
|
||||||
|
if ps := pcu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := pcu.mutation.Name(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := pcu.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldSlug, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := pcu.mutation.Description(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if pcu.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(productcategory.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := pcu.mutation.Status(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldStatus, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := pcu.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := pcu.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if pcu.mutation.ProductsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: productcategory.ProductsTable,
|
||||||
|
Columns: productcategory.ProductsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pcu.mutation.RemovedProductsIDs(); len(nodes) > 0 && !pcu.mutation.ProductsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: productcategory.ProductsTable,
|
||||||
|
Columns: productcategory.ProductsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pcu.mutation.ProductsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: productcategory.ProductsTable,
|
||||||
|
Columns: productcategory.ProductsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, pcu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{productcategory.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
pcu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategoryUpdateOne is the builder for updating a single ProductCategory entity.
|
||||||
|
type ProductCategoryUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProductCategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetName(s string) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.SetName(s)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetNillableName(s *string) *ProductCategoryUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
pcuo.SetName(*s)
|
||||||
|
}
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSlug sets the "slug" field.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetSlug(s string) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.SetSlug(s)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetDescription(s string) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.SetDescription(s)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetNillableDescription(s *string) *ProductCategoryUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
pcuo.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) ClearDescription() *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.ClearDescription()
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetStatus(b bool) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.SetStatus(b)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetNillableStatus(b *bool) *ProductCategoryUpdateOne {
|
||||||
|
if b != nil {
|
||||||
|
pcuo.SetStatus(*b)
|
||||||
|
}
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetCreatedAt(t time.Time) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.SetCreatedAt(t)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetNillableCreatedAt(t *time.Time) *ProductCategoryUpdateOne {
|
||||||
|
if t != nil {
|
||||||
|
pcuo.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SetUpdatedAt(t time.Time) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.SetUpdatedAt(t)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProductIDs adds the "products" edge to the Product entity by IDs.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) AddProductIDs(ids ...int) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.AddProductIDs(ids...)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddProducts adds the "products" edges to the Product entity.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) AddProducts(p ...*Product) *ProductCategoryUpdateOne {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pcuo.AddProductIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProductCategoryMutation object of the builder.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) Mutation() *ProductCategoryMutation {
|
||||||
|
return pcuo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProducts clears all "products" edges to the Product entity.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) ClearProducts() *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.ClearProducts()
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveProductIDs removes the "products" edge to Product entities by IDs.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) RemoveProductIDs(ids ...int) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.RemoveProductIDs(ids...)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveProducts removes "products" edges to Product entities.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) RemoveProducts(p ...*Product) *ProductCategoryUpdateOne {
|
||||||
|
ids := make([]int, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pcuo.RemoveProductIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProductCategoryUpdate builder.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) Where(ps ...predicate.ProductCategory) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.mutation.Where(ps...)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) Select(field string, fields ...string) *ProductCategoryUpdateOne {
|
||||||
|
pcuo.fields = append([]string{field}, fields...)
|
||||||
|
return pcuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated ProductCategory entity.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) Save(ctx context.Context) (*ProductCategory, error) {
|
||||||
|
pcuo.defaults()
|
||||||
|
return withHooks(ctx, pcuo.sqlSave, pcuo.mutation, pcuo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) SaveX(ctx context.Context) *ProductCategory {
|
||||||
|
node, err := pcuo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := pcuo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := pcuo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) defaults() {
|
||||||
|
if _, ok := pcuo.mutation.UpdatedAt(); !ok {
|
||||||
|
v := productcategory.UpdateDefaultUpdatedAt()
|
||||||
|
pcuo.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pcuo *ProductCategoryUpdateOne) sqlSave(ctx context.Context) (_node *ProductCategory, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(productcategory.Table, productcategory.Columns, sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt))
|
||||||
|
id, ok := pcuo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ProductCategory.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := pcuo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, productcategory.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !productcategory.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != productcategory.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := pcuo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := pcuo.mutation.Name(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := pcuo.mutation.Slug(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldSlug, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := pcuo.mutation.Description(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if pcuo.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(productcategory.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := pcuo.mutation.Status(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldStatus, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := pcuo.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := pcuo.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(productcategory.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if pcuo.mutation.ProductsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: productcategory.ProductsTable,
|
||||||
|
Columns: productcategory.ProductsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pcuo.mutation.RemovedProductsIDs(); len(nodes) > 0 && !pcuo.mutation.ProductsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: productcategory.ProductsTable,
|
||||||
|
Columns: productcategory.ProductsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pcuo.mutation.ProductsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: productcategory.ProductsTable,
|
||||||
|
Columns: productcategory.ProductsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(product.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &ProductCategory{config: pcuo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, pcuo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{productcategory.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pcuo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
106
ent/runtime.go
Normal file
106
ent/runtime.go
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"tel-commerce/ent/business"
|
||||||
|
"tel-commerce/ent/businesscategory"
|
||||||
|
"tel-commerce/ent/product"
|
||||||
|
"tel-commerce/ent/productcategory"
|
||||||
|
"tel-commerce/ent/schema"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The init function reads all schema descriptors with runtime code
|
||||||
|
// (default values, validators, hooks and policies) and stitches it
|
||||||
|
// to their package variables.
|
||||||
|
func init() {
|
||||||
|
businessFields := schema.Business{}.Fields()
|
||||||
|
_ = businessFields
|
||||||
|
// businessDescName is the schema descriptor for name field.
|
||||||
|
businessDescName := businessFields[0].Descriptor()
|
||||||
|
// business.DefaultName holds the default value on creation for the name field.
|
||||||
|
business.DefaultName = businessDescName.Default.(string)
|
||||||
|
// businessDescCompany is the schema descriptor for company field.
|
||||||
|
businessDescCompany := businessFields[4].Descriptor()
|
||||||
|
// business.DefaultCompany holds the default value on creation for the company field.
|
||||||
|
business.DefaultCompany = businessDescCompany.Default.(string)
|
||||||
|
// businessDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
businessDescCreatedAt := businessFields[6].Descriptor()
|
||||||
|
// business.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
business.DefaultCreatedAt = businessDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// businessDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
businessDescUpdatedAt := businessFields[7].Descriptor()
|
||||||
|
// business.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
business.DefaultUpdatedAt = businessDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// business.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
business.UpdateDefaultUpdatedAt = businessDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
businesscategoryFields := schema.BusinessCategory{}.Fields()
|
||||||
|
_ = businesscategoryFields
|
||||||
|
// businesscategoryDescName is the schema descriptor for name field.
|
||||||
|
businesscategoryDescName := businesscategoryFields[1].Descriptor()
|
||||||
|
// businesscategory.DefaultName holds the default value on creation for the name field.
|
||||||
|
businesscategory.DefaultName = businesscategoryDescName.Default.(string)
|
||||||
|
// businesscategoryDescDescription is the schema descriptor for description field.
|
||||||
|
businesscategoryDescDescription := businesscategoryFields[2].Descriptor()
|
||||||
|
// businesscategory.DefaultDescription holds the default value on creation for the description field.
|
||||||
|
businesscategory.DefaultDescription = businesscategoryDescDescription.Default.(string)
|
||||||
|
productFields := schema.Product{}.Fields()
|
||||||
|
_ = productFields
|
||||||
|
// productDescName is the schema descriptor for name field.
|
||||||
|
productDescName := productFields[0].Descriptor()
|
||||||
|
// product.DefaultName holds the default value on creation for the name field.
|
||||||
|
product.DefaultName = productDescName.Default.(string)
|
||||||
|
// productDescPrice is the schema descriptor for price field.
|
||||||
|
productDescPrice := productFields[2].Descriptor()
|
||||||
|
// product.DefaultPrice holds the default value on creation for the price field.
|
||||||
|
product.DefaultPrice = productDescPrice.Default.(float64)
|
||||||
|
// product.PriceValidator is a validator for the "price" field. It is called by the builders before save.
|
||||||
|
product.PriceValidator = productDescPrice.Validators[0].(func(float64) error)
|
||||||
|
// productDescOriginalPrice is the schema descriptor for original_price field.
|
||||||
|
productDescOriginalPrice := productFields[3].Descriptor()
|
||||||
|
// product.DefaultOriginalPrice holds the default value on creation for the original_price field.
|
||||||
|
product.DefaultOriginalPrice = productDescOriginalPrice.Default.(float64)
|
||||||
|
// product.OriginalPriceValidator is a validator for the "original_price" field. It is called by the builders before save.
|
||||||
|
product.OriginalPriceValidator = productDescOriginalPrice.Validators[0].(func(float64) error)
|
||||||
|
// productDescQuantity is the schema descriptor for quantity field.
|
||||||
|
productDescQuantity := productFields[4].Descriptor()
|
||||||
|
// product.DefaultQuantity holds the default value on creation for the quantity field.
|
||||||
|
product.DefaultQuantity = productDescQuantity.Default.(int)
|
||||||
|
// product.QuantityValidator is a validator for the "quantity" field. It is called by the builders before save.
|
||||||
|
product.QuantityValidator = productDescQuantity.Validators[0].(func(int) error)
|
||||||
|
// productDescStatus is the schema descriptor for status field.
|
||||||
|
productDescStatus := productFields[5].Descriptor()
|
||||||
|
// product.DefaultStatus holds the default value on creation for the status field.
|
||||||
|
product.DefaultStatus = productDescStatus.Default.(bool)
|
||||||
|
// productDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
productDescCreatedAt := productFields[6].Descriptor()
|
||||||
|
// product.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
product.DefaultCreatedAt = productDescCreatedAt.Default.(time.Time)
|
||||||
|
// productDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
productDescUpdatedAt := productFields[7].Descriptor()
|
||||||
|
// product.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
product.DefaultUpdatedAt = productDescUpdatedAt.Default.(time.Time)
|
||||||
|
// product.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
product.UpdateDefaultUpdatedAt = productDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
productcategoryFields := schema.ProductCategory{}.Fields()
|
||||||
|
_ = productcategoryFields
|
||||||
|
// productcategoryDescName is the schema descriptor for name field.
|
||||||
|
productcategoryDescName := productcategoryFields[0].Descriptor()
|
||||||
|
// productcategory.DefaultName holds the default value on creation for the name field.
|
||||||
|
productcategory.DefaultName = productcategoryDescName.Default.(string)
|
||||||
|
// productcategoryDescStatus is the schema descriptor for status field.
|
||||||
|
productcategoryDescStatus := productcategoryFields[3].Descriptor()
|
||||||
|
// productcategory.DefaultStatus holds the default value on creation for the status field.
|
||||||
|
productcategory.DefaultStatus = productcategoryDescStatus.Default.(bool)
|
||||||
|
// productcategoryDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
productcategoryDescCreatedAt := productcategoryFields[4].Descriptor()
|
||||||
|
// productcategory.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
productcategory.DefaultCreatedAt = productcategoryDescCreatedAt.Default.(time.Time)
|
||||||
|
// productcategoryDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
productcategoryDescUpdatedAt := productcategoryFields[5].Descriptor()
|
||||||
|
// productcategory.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
productcategory.DefaultUpdatedAt = productcategoryDescUpdatedAt.Default.(time.Time)
|
||||||
|
// productcategory.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
productcategory.UpdateDefaultUpdatedAt = productcategoryDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
}
|
10
ent/runtime/runtime.go
Normal file
10
ent/runtime/runtime.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
// The schema-stitching logic is generated in tel-commerce/ent/runtime.go
|
||||||
|
|
||||||
|
const (
|
||||||
|
Version = "v0.12.4" // Version of ent codegen.
|
||||||
|
Sum = "h1:LddPnAyxls/O7DTXZvUGDj0NZIdGSu317+aoNLJWbD8=" // Sum of ent codegen.
|
||||||
|
)
|
34
ent/schema/business.go
Normal file
34
ent/schema/business.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Business holds the schema definition for the Business entity.
|
||||||
|
type Business struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the Business.
|
||||||
|
func (Business) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.String("name").Default("unknown"),
|
||||||
|
field.String("slug").Unique(),
|
||||||
|
field.String("bot_id").Nillable().Unique(),
|
||||||
|
field.String("description").Optional().Nillable(),
|
||||||
|
field.String("company").Default("main"),
|
||||||
|
field.String("about_us").Optional().Nillable(),
|
||||||
|
field.Time("created_at").Default(time.Now),
|
||||||
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the Business.
|
||||||
|
func (Business) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("businessCategory", BusinessCategory.Type).Ref("businesses"),
|
||||||
|
}
|
||||||
|
}
|
31
ent/schema/businesscategory.go
Normal file
31
ent/schema/businesscategory.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessCategory holds the schema definition for the BusinessCategory entity.
|
||||||
|
type BusinessCategory struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the BusinessCategory.
|
||||||
|
func (BusinessCategory) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.String("slug").
|
||||||
|
Unique(),
|
||||||
|
field.String("name").
|
||||||
|
Default("unknown"),
|
||||||
|
field.String("description").
|
||||||
|
Default("unknown"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the BusinessCategory.
|
||||||
|
func (BusinessCategory) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.To("businesses", Business.Type),
|
||||||
|
}
|
||||||
|
}
|
34
ent/schema/product.go
Normal file
34
ent/schema/product.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Product holds the schema definition for the Product entity.
|
||||||
|
type Product struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the Product.
|
||||||
|
func (Product) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.String("name").Default("unknown"),
|
||||||
|
field.String("description").Optional().Nillable(),
|
||||||
|
field.Float("price").Default(0).Positive(),
|
||||||
|
field.Float("original_price").Default(0).Positive(),
|
||||||
|
field.Int("quantity").Default(0).Positive(),
|
||||||
|
field.Bool("status").Default(true),
|
||||||
|
field.Time("created_at").Default(time.Now()),
|
||||||
|
field.Time("updated_at").Default(time.Now()).UpdateDefault(time.Now),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the Product.
|
||||||
|
func (Product) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("productCategory", ProductCategory.Type).Ref("products"),
|
||||||
|
}
|
||||||
|
}
|
32
ent/schema/productcategory.go
Normal file
32
ent/schema/productcategory.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductCategory holds the schema definition for the ProductCategory entity.
|
||||||
|
type ProductCategory struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the ProductCategory.
|
||||||
|
func (ProductCategory) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.String("name").Default("unknown"),
|
||||||
|
field.String("slug").Unique(),
|
||||||
|
field.String("description").Optional().Nillable(),
|
||||||
|
field.Bool("status").Default(true),
|
||||||
|
field.Time("created_at").Default(time.Now()),
|
||||||
|
field.Time("updated_at").Default(time.Now()).UpdateDefault(time.Now),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the ProductCategory.
|
||||||
|
func (ProductCategory) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.To("products", Product.Type),
|
||||||
|
}
|
||||||
|
}
|
219
ent/tx.go
Normal file
219
ent/tx.go
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tx is a transactional client that is created by calling Client.Tx().
|
||||||
|
type Tx struct {
|
||||||
|
config
|
||||||
|
// Business is the client for interacting with the Business builders.
|
||||||
|
Business *BusinessClient
|
||||||
|
// BusinessCategory is the client for interacting with the BusinessCategory builders.
|
||||||
|
BusinessCategory *BusinessCategoryClient
|
||||||
|
// Product is the client for interacting with the Product builders.
|
||||||
|
Product *ProductClient
|
||||||
|
// ProductCategory is the client for interacting with the ProductCategory builders.
|
||||||
|
ProductCategory *ProductCategoryClient
|
||||||
|
|
||||||
|
// lazily loaded.
|
||||||
|
client *Client
|
||||||
|
clientOnce sync.Once
|
||||||
|
// ctx lives for the life of the transaction. It is
|
||||||
|
// the same context used by the underlying connection.
|
||||||
|
ctx context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Committer is the interface that wraps the Commit method.
|
||||||
|
Committer interface {
|
||||||
|
Commit(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Committer. If f is a function with the appropriate
|
||||||
|
// signature, CommitFunc(f) is a Committer that calls f.
|
||||||
|
CommitFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||||
|
// and returns a Committer. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Committer) ent.Committer {
|
||||||
|
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Commit(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
CommitHook func(Committer) Committer
|
||||||
|
)
|
||||||
|
|
||||||
|
// Commit calls f(ctx, m).
|
||||||
|
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit commits the transaction.
|
||||||
|
func (tx *Tx) Commit() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Commit()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]CommitHook(nil), txDriver.onCommit...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Commit(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnCommit adds a hook to call on commit.
|
||||||
|
func (tx *Tx) OnCommit(f CommitHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onCommit = append(txDriver.onCommit, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Rollbacker is the interface that wraps the Rollback method.
|
||||||
|
Rollbacker interface {
|
||||||
|
Rollback(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Rollbacker. If f is a function with the appropriate
|
||||||
|
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||||
|
RollbackFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||||
|
// and returns a Rollbacker. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||||
|
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Rollback(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
RollbackHook func(Rollbacker) Rollbacker
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rollback calls f(ctx, m).
|
||||||
|
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollback rollbacks the transaction.
|
||||||
|
func (tx *Tx) Rollback() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Rollback()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Rollback(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnRollback adds a hook to call on rollback.
|
||||||
|
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onRollback = append(txDriver.onRollback, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a Client that binds to current transaction.
|
||||||
|
func (tx *Tx) Client() *Client {
|
||||||
|
tx.clientOnce.Do(func() {
|
||||||
|
tx.client = &Client{config: tx.config}
|
||||||
|
tx.client.init()
|
||||||
|
})
|
||||||
|
return tx.client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) init() {
|
||||||
|
tx.Business = NewBusinessClient(tx.config)
|
||||||
|
tx.BusinessCategory = NewBusinessCategoryClient(tx.config)
|
||||||
|
tx.Product = NewProductClient(tx.config)
|
||||||
|
tx.ProductCategory = NewProductCategoryClient(tx.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||||
|
// The idea is to support transactions without adding any extra code to the builders.
|
||||||
|
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||||
|
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||||
|
// of them in order to commit or rollback the transaction.
|
||||||
|
//
|
||||||
|
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||||
|
// applies a query, for example: Business.QueryXXX(), the query will be executed
|
||||||
|
// through the driver which created this transaction.
|
||||||
|
//
|
||||||
|
// Note that txDriver is not goroutine safe.
|
||||||
|
type txDriver struct {
|
||||||
|
// the driver we started the transaction from.
|
||||||
|
drv dialect.Driver
|
||||||
|
// tx is the underlying transaction.
|
||||||
|
tx dialect.Tx
|
||||||
|
// completion hooks.
|
||||||
|
mu sync.Mutex
|
||||||
|
onCommit []CommitHook
|
||||||
|
onRollback []RollbackHook
|
||||||
|
}
|
||||||
|
|
||||||
|
// newTx creates a new transactional driver.
|
||||||
|
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||||
|
tx, err := drv.Tx(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &txDriver{tx: tx, drv: drv}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||||
|
// from the internal builders. Should be called only by the internal builders.
|
||||||
|
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||||
|
|
||||||
|
// Dialect returns the dialect of the driver we started the transaction from.
|
||||||
|
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||||
|
|
||||||
|
// Close is a nop close.
|
||||||
|
func (*txDriver) Close() error { return nil }
|
||||||
|
|
||||||
|
// Commit is a nop commit for the internal builders.
|
||||||
|
// User must call `Tx.Commit` in order to commit the transaction.
|
||||||
|
func (*txDriver) Commit() error { return nil }
|
||||||
|
|
||||||
|
// Rollback is a nop rollback for the internal builders.
|
||||||
|
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||||
|
func (*txDriver) Rollback() error { return nil }
|
||||||
|
|
||||||
|
// Exec calls tx.Exec.
|
||||||
|
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Exec(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query calls tx.Query.
|
||||||
|
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Query(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ dialect.Driver = (*txDriver)(nil)
|
47
go.mod
Normal file
47
go.mod
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
module tel-commerce
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require (
|
||||||
|
entgo.io/ent v0.12.4
|
||||||
|
github.com/gin-gonic/gin v1.9.1
|
||||||
|
github.com/go-sql-driver/mysql v1.7.1
|
||||||
|
github.com/joho/godotenv v1.5.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
ariga.io/atlas v0.14.1-0.20230918065911-83ad451a4935 // indirect
|
||||||
|
github.com/agext/levenshtein v1.2.1 // indirect
|
||||||
|
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
||||||
|
github.com/bytedance/sonic v1.9.1 // indirect
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-openapi/inflect v0.19.0 // indirect
|
||||||
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0 // indirect
|
||||||
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
|
github.com/google/go-cmp v0.5.6 // indirect
|
||||||
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.4 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||||
|
github.com/zclconf/go-cty v1.8.0 // indirect
|
||||||
|
golang.org/x/arch v0.3.0 // indirect
|
||||||
|
golang.org/x/crypto v0.9.0 // indirect
|
||||||
|
golang.org/x/mod v0.10.0 // indirect
|
||||||
|
golang.org/x/net v0.10.0 // indirect
|
||||||
|
golang.org/x/sys v0.8.0 // indirect
|
||||||
|
golang.org/x/text v0.9.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.30.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
147
go.sum
Normal file
147
go.sum
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
ariga.io/atlas v0.14.1-0.20230918065911-83ad451a4935 h1:JnYs/y8RJ3+MiIUp+3RgyyeO48VHLAZimqiaZYnMKk8=
|
||||||
|
ariga.io/atlas v0.14.1-0.20230918065911-83ad451a4935/go.mod h1:isZrlzJ5cpoCoKFoY9knZug7Lq4pP1cm8g3XciLZ0Pw=
|
||||||
|
entgo.io/ent v0.12.4 h1:LddPnAyxls/O7DTXZvUGDj0NZIdGSu317+aoNLJWbD8=
|
||||||
|
entgo.io/ent v0.12.4/go.mod h1:Y3JVAjtlIk8xVZYSn3t3mf8xlZIn5SAOXZQxD6kKI+Q=
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
|
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
||||||
|
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
||||||
|
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
|
||||||
|
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
|
||||||
|
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
||||||
|
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
|
||||||
|
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||||
|
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
|
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
|
||||||
|
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
|
||||||
|
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
|
||||||
|
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||||
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||||
|
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||||
|
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||||
|
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
|
||||||
|
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||||
|
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||||
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||||
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||||
|
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc=
|
||||||
|
github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||||
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
|
||||||
|
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
||||||
|
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||||
|
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||||
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
|
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||||
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
||||||
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||||
|
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||||
|
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||||
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
|
||||||
|
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||||
|
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||||
|
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||||
|
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
|
||||||
|
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
|
||||||
|
github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA=
|
||||||
|
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
|
||||||
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
|
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||||
|
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
||||||
|
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
||||||
|
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
|
||||||
|
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||||
|
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||||
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||||
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.8.1-0.20230428195545-5283a0178901 h1:0wxTF6pSjIIhNt7mo9GvjDfzyCOiWhmICgtO/Ah948s=
|
||||||
|
golang.org/x/tools v0.8.1-0.20230428195545-5283a0178901/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||||
|
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||||
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||||
|
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
45
main.go
Normal file
45
main.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"log"
|
||||||
|
"tel-commerce/config"
|
||||||
|
"tel-commerce/database/seeds"
|
||||||
|
"tel-commerce/ent"
|
||||||
|
"tel-commerce/router"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func seederTable(ctx *context.Context, client *ent.Client) {
|
||||||
|
seeds.RunDatabaseSeeder(client, ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
dbConf := config.DatabaseConfig()
|
||||||
|
|
||||||
|
client, err := ent.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=True", dbConf.Username, dbConf.Password, dbConf.Host, dbConf.Port, dbConf.Dbname))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed opening connection to mysql: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer client.Close()
|
||||||
|
client = client.Debug()
|
||||||
|
|
||||||
|
log.Println("Database Connected!")
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10000*time.Second)
|
||||||
|
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Dump migration changes to stdout.
|
||||||
|
//if err := client.Schema.WriteTo(ctx, os.Stdout); err != nil {
|
||||||
|
//log.Fatalf("failed printing schema changes: %v", err)
|
||||||
|
//}
|
||||||
|
if err := client.Schema.Create(context.Background()); err != nil {
|
||||||
|
log.Fatalf("failed creating schema resources: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
router.RunAPI(ctx, client)
|
||||||
|
}
|
29
router/main.go
Normal file
29
router/main.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"strconv"
|
||||||
|
"tel-commerce/app/Http/Controllers"
|
||||||
|
"tel-commerce/ent"
|
||||||
|
)
|
||||||
|
|
||||||
|
type API struct {
|
||||||
|
Router *gin.Engine
|
||||||
|
Controller *Controllers.Controller
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api API) GetIdParameter(ctx *gin.Context, param string) (int, error) {
|
||||||
|
return strconv.Atoi(ctx.Param(param))
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunAPI(ctx context.Context, client *ent.Client) {
|
||||||
|
api := API{Router: gin.New(), Controller: &Controllers.Controller{Ctx: ctx, Client: client}}
|
||||||
|
|
||||||
|
api.Router.Use(gin.Logger())
|
||||||
|
api.Router.Use(gin.Recovery())
|
||||||
|
|
||||||
|
api.ProductRouter()
|
||||||
|
|
||||||
|
api.Router.Run("localhost:8080")
|
||||||
|
}
|
6
router/product.go
Normal file
6
router/product.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
func (api API) ProductRouter() {
|
||||||
|
category := api.Router.Group("/products")
|
||||||
|
category.GET("/", api.Controller.GetProducts())
|
||||||
|
}
|
36
start.go
Normal file
36
start.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"tel-commerce/ent"
|
||||||
|
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
client, err := ent.Open("mysql", "root@tcp(localhost:3306)/tel_commerce?parseTime=True")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed opening connection to mysql: %v", err)
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
// Run the auto migration tool.
|
||||||
|
if err := client.Schema.Create(context.Background()); err != nil {
|
||||||
|
log.Fatalf("failed creating schema resources: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateBusiness(ctx context.Context, client *ent.Client) (*ent.Business, error) {
|
||||||
|
u, err := client.Business.
|
||||||
|
Create().
|
||||||
|
SetName("saeid").
|
||||||
|
SetBusinessCategoryID(1).
|
||||||
|
Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed creating user: %w", err)
|
||||||
|
}
|
||||||
|
log.Println("user was created: ", u)
|
||||||
|
return u, nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user