831 lines
29 KiB
Go
831 lines
29 KiB
Go
|
// 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
|
||
|
}
|
||
|
)
|