// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "log" "reflect" "online-order/ent/migrate" "online-order/ent/business" "online-order/ent/businesscategory" "online-order/ent/businessconfig" "online-order/ent/domain" "online-order/ent/product" "online-order/ent/productcategory" "online-order/ent/user" "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 // BusinessConfig is the client for interacting with the BusinessConfig builders. BusinessConfig *BusinessConfigClient // Domain is the client for interacting with the Domain builders. Domain *DomainClient // Product is the client for interacting with the Product builders. Product *ProductClient // ProductCategory is the client for interacting with the ProductCategory builders. ProductCategory *ProductCategoryClient // User is the client for interacting with the User builders. User *UserClient } // 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.BusinessConfig = NewBusinessConfigClient(c.config) c.Domain = NewDomainClient(c.config) c.Product = NewProductClient(c.config) c.ProductCategory = NewProductCategoryClient(c.config) c.User = NewUserClient(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), BusinessConfig: NewBusinessConfigClient(cfg), Domain: NewDomainClient(cfg), Product: NewProductClient(cfg), ProductCategory: NewProductCategoryClient(cfg), User: NewUserClient(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), BusinessConfig: NewBusinessConfigClient(cfg), Domain: NewDomainClient(cfg), Product: NewProductClient(cfg), ProductCategory: NewProductCategoryClient(cfg), User: NewUserClient(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) { for _, n := range []interface{ Use(...Hook) }{ c.Business, c.BusinessCategory, c.BusinessConfig, c.Domain, c.Product, c.ProductCategory, c.User, } { n.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) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.Business, c.BusinessCategory, c.BusinessConfig, c.Domain, c.Product, c.ProductCategory, c.User, } { n.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 *BusinessConfigMutation: return c.BusinessConfig.mutate(ctx, m) case *DomainMutation: return c.Domain.mutate(ctx, m) case *ProductMutation: return c.Product.mutate(ctx, m) case *ProductCategoryMutation: return c.ProductCategory.mutate(ctx, m) case *UserMutation: return c.User.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 } // QueryBusinessCategories queries the business_categories edge of a Business. func (c *BusinessClient) QueryBusinessCategories(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.M2O, true, business.BusinessCategoriesTable, business.BusinessCategoriesColumn), ) fromV = sqlgraph.Neighbors(b.driver.Dialect(), step) return fromV, nil } return query } // QueryUsers queries the users edge of a Business. func (c *BusinessClient) QueryUsers(b *Business) *UserQuery { query := (&UserClient{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(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, business.UsersTable, business.UsersColumn), ) fromV = sqlgraph.Neighbors(b.driver.Dialect(), step) return fromV, nil } return query } // QueryProducts queries the products edge of a Business. func (c *BusinessClient) QueryProducts(b *Business) *ProductQuery { query := (&ProductClient{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(product.Table, product.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, business.ProductsTable, business.ProductsColumn), ) fromV = sqlgraph.Neighbors(b.driver.Dialect(), step) return fromV, nil } return query } // QueryProductCategories queries the product_categories edge of a Business. func (c *BusinessClient) QueryProductCategories(b *Business) *ProductCategoryQuery { query := (&ProductCategoryClient{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(productcategory.Table, productcategory.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, business.ProductCategoriesTable, business.ProductCategoriesColumn), ) fromV = sqlgraph.Neighbors(b.driver.Dialect(), step) return fromV, nil } return query } // QueryDomains queries the domains edge of a Business. func (c *BusinessClient) QueryDomains(b *Business) *DomainQuery { query := (&DomainClient{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(domain.Table, domain.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, business.DomainsTable, business.DomainsColumn), ) fromV = sqlgraph.Neighbors(b.driver.Dialect(), step) return fromV, nil } return query } // QueryBusinessConfigs queries the business_configs edge of a Business. func (c *BusinessClient) QueryBusinessConfigs(b *Business) *BusinessConfigQuery { query := (&BusinessConfigClient{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(businessconfig.Table, businessconfig.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, business.BusinessConfigsTable, business.BusinessConfigsColumn), ) 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.O2M, false, businesscategory.BusinessesTable, businesscategory.BusinessesColumn), ) 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()) } } // BusinessConfigClient is a client for the BusinessConfig schema. type BusinessConfigClient struct { config } // NewBusinessConfigClient returns a client for the BusinessConfig from the given config. func NewBusinessConfigClient(c config) *BusinessConfigClient { return &BusinessConfigClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `businessconfig.Hooks(f(g(h())))`. func (c *BusinessConfigClient) Use(hooks ...Hook) { c.hooks.BusinessConfig = append(c.hooks.BusinessConfig, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `businessconfig.Intercept(f(g(h())))`. func (c *BusinessConfigClient) Intercept(interceptors ...Interceptor) { c.inters.BusinessConfig = append(c.inters.BusinessConfig, interceptors...) } // Create returns a builder for creating a BusinessConfig entity. func (c *BusinessConfigClient) Create() *BusinessConfigCreate { mutation := newBusinessConfigMutation(c.config, OpCreate) return &BusinessConfigCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of BusinessConfig entities. func (c *BusinessConfigClient) CreateBulk(builders ...*BusinessConfigCreate) *BusinessConfigCreateBulk { return &BusinessConfigCreateBulk{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 *BusinessConfigClient) MapCreateBulk(slice any, setFunc func(*BusinessConfigCreate, int)) *BusinessConfigCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &BusinessConfigCreateBulk{err: fmt.Errorf("calling to BusinessConfigClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*BusinessConfigCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &BusinessConfigCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for BusinessConfig. func (c *BusinessConfigClient) Update() *BusinessConfigUpdate { mutation := newBusinessConfigMutation(c.config, OpUpdate) return &BusinessConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *BusinessConfigClient) UpdateOne(bc *BusinessConfig) *BusinessConfigUpdateOne { mutation := newBusinessConfigMutation(c.config, OpUpdateOne, withBusinessConfig(bc)) return &BusinessConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *BusinessConfigClient) UpdateOneID(id int) *BusinessConfigUpdateOne { mutation := newBusinessConfigMutation(c.config, OpUpdateOne, withBusinessConfigID(id)) return &BusinessConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for BusinessConfig. func (c *BusinessConfigClient) Delete() *BusinessConfigDelete { mutation := newBusinessConfigMutation(c.config, OpDelete) return &BusinessConfigDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *BusinessConfigClient) DeleteOne(bc *BusinessConfig) *BusinessConfigDeleteOne { return c.DeleteOneID(bc.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *BusinessConfigClient) DeleteOneID(id int) *BusinessConfigDeleteOne { builder := c.Delete().Where(businessconfig.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &BusinessConfigDeleteOne{builder} } // Query returns a query builder for BusinessConfig. func (c *BusinessConfigClient) Query() *BusinessConfigQuery { return &BusinessConfigQuery{ config: c.config, ctx: &QueryContext{Type: TypeBusinessConfig}, inters: c.Interceptors(), } } // Get returns a BusinessConfig entity by its id. func (c *BusinessConfigClient) Get(ctx context.Context, id int) (*BusinessConfig, error) { return c.Query().Where(businessconfig.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *BusinessConfigClient) GetX(ctx context.Context, id int) *BusinessConfig { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryBusinesses queries the businesses edge of a BusinessConfig. func (c *BusinessConfigClient) QueryBusinesses(bc *BusinessConfig) *BusinessQuery { query := (&BusinessClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := bc.ID step := sqlgraph.NewStep( sqlgraph.From(businessconfig.Table, businessconfig.FieldID, id), sqlgraph.To(business.Table, business.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, businessconfig.BusinessesTable, businessconfig.BusinessesColumn), ) fromV = sqlgraph.Neighbors(bc.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *BusinessConfigClient) Hooks() []Hook { return c.hooks.BusinessConfig } // Interceptors returns the client interceptors. func (c *BusinessConfigClient) Interceptors() []Interceptor { return c.inters.BusinessConfig } func (c *BusinessConfigClient) mutate(ctx context.Context, m *BusinessConfigMutation) (Value, error) { switch m.Op() { case OpCreate: return (&BusinessConfigCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&BusinessConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&BusinessConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&BusinessConfigDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown BusinessConfig mutation op: %q", m.Op()) } } // DomainClient is a client for the Domain schema. type DomainClient struct { config } // NewDomainClient returns a client for the Domain from the given config. func NewDomainClient(c config) *DomainClient { return &DomainClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `domain.Hooks(f(g(h())))`. func (c *DomainClient) Use(hooks ...Hook) { c.hooks.Domain = append(c.hooks.Domain, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `domain.Intercept(f(g(h())))`. func (c *DomainClient) Intercept(interceptors ...Interceptor) { c.inters.Domain = append(c.inters.Domain, interceptors...) } // Create returns a builder for creating a Domain entity. func (c *DomainClient) Create() *DomainCreate { mutation := newDomainMutation(c.config, OpCreate) return &DomainCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Domain entities. func (c *DomainClient) CreateBulk(builders ...*DomainCreate) *DomainCreateBulk { return &DomainCreateBulk{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 *DomainClient) MapCreateBulk(slice any, setFunc func(*DomainCreate, int)) *DomainCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &DomainCreateBulk{err: fmt.Errorf("calling to DomainClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*DomainCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &DomainCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Domain. func (c *DomainClient) Update() *DomainUpdate { mutation := newDomainMutation(c.config, OpUpdate) return &DomainUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *DomainClient) UpdateOne(d *Domain) *DomainUpdateOne { mutation := newDomainMutation(c.config, OpUpdateOne, withDomain(d)) return &DomainUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *DomainClient) UpdateOneID(id int) *DomainUpdateOne { mutation := newDomainMutation(c.config, OpUpdateOne, withDomainID(id)) return &DomainUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Domain. func (c *DomainClient) Delete() *DomainDelete { mutation := newDomainMutation(c.config, OpDelete) return &DomainDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *DomainClient) DeleteOne(d *Domain) *DomainDeleteOne { return c.DeleteOneID(d.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *DomainClient) DeleteOneID(id int) *DomainDeleteOne { builder := c.Delete().Where(domain.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &DomainDeleteOne{builder} } // Query returns a query builder for Domain. func (c *DomainClient) Query() *DomainQuery { return &DomainQuery{ config: c.config, ctx: &QueryContext{Type: TypeDomain}, inters: c.Interceptors(), } } // Get returns a Domain entity by its id. func (c *DomainClient) Get(ctx context.Context, id int) (*Domain, error) { return c.Query().Where(domain.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *DomainClient) GetX(ctx context.Context, id int) *Domain { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryBusinesses queries the businesses edge of a Domain. func (c *DomainClient) QueryBusinesses(d *Domain) *BusinessQuery { query := (&BusinessClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := d.ID step := sqlgraph.NewStep( sqlgraph.From(domain.Table, domain.FieldID, id), sqlgraph.To(business.Table, business.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, domain.BusinessesTable, domain.BusinessesColumn), ) fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) return fromV, nil } return query } // QueryUsers queries the users edge of a Domain. func (c *DomainClient) QueryUsers(d *Domain) *UserQuery { query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := d.ID step := sqlgraph.NewStep( sqlgraph.From(domain.Table, domain.FieldID, id), sqlgraph.To(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, domain.UsersTable, domain.UsersColumn), ) fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *DomainClient) Hooks() []Hook { return c.hooks.Domain } // Interceptors returns the client interceptors. func (c *DomainClient) Interceptors() []Interceptor { return c.inters.Domain } func (c *DomainClient) mutate(ctx context.Context, m *DomainMutation) (Value, error) { switch m.Op() { case OpCreate: return (&DomainCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&DomainUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&DomainUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&DomainDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Domain 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 } // QueryProductCategories queries the product_categories edge of a Product. func (c *ProductClient) QueryProductCategories(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.M2O, true, product.ProductCategoriesTable, product.ProductCategoriesColumn), ) fromV = sqlgraph.Neighbors(pr.driver.Dialect(), step) return fromV, nil } return query } // QueryBusinesses queries the businesses edge of a Product. func (c *ProductClient) QueryBusinesses(pr *Product) *BusinessQuery { query := (&BusinessClient{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(business.Table, business.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, product.BusinessesTable, product.BusinessesColumn), ) fromV = sqlgraph.Neighbors(pr.driver.Dialect(), step) return fromV, nil } return query } // QueryUsers queries the users edge of a Product. func (c *ProductClient) QueryUsers(pr *Product) *UserQuery { query := (&UserClient{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(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, product.UsersTable, product.UsersColumn), ) 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.O2M, false, productcategory.ProductsTable, productcategory.ProductsColumn), ) fromV = sqlgraph.Neighbors(pc.driver.Dialect(), step) return fromV, nil } return query } // QueryBusinesses queries the businesses edge of a ProductCategory. func (c *ProductCategoryClient) QueryBusinesses(pc *ProductCategory) *BusinessQuery { query := (&BusinessClient{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(business.Table, business.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, productcategory.BusinessesTable, productcategory.BusinessesColumn), ) 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()) } } // UserClient is a client for the User schema. type UserClient struct { config } // NewUserClient returns a client for the User from the given config. func NewUserClient(c config) *UserClient { return &UserClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`. func (c *UserClient) Use(hooks ...Hook) { c.hooks.User = append(c.hooks.User, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`. func (c *UserClient) Intercept(interceptors ...Interceptor) { c.inters.User = append(c.inters.User, interceptors...) } // Create returns a builder for creating a User entity. func (c *UserClient) Create() *UserCreate { mutation := newUserMutation(c.config, OpCreate) return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of User entities. func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{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 *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*UserCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &UserCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { mutation := newUserMutation(c.config, OpUpdateOne, withUser(u)) return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *UserClient) UpdateOneID(id int) *UserUpdateOne { mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id)) return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for User. func (c *UserClient) Delete() *UserDelete { mutation := newUserMutation(c.config, OpDelete) return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { return c.DeleteOneID(u.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *UserClient) DeleteOneID(id int) *UserDeleteOne { builder := c.Delete().Where(user.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &UserDeleteOne{builder} } // Query returns a query builder for User. func (c *UserClient) Query() *UserQuery { return &UserQuery{ config: c.config, ctx: &QueryContext{Type: TypeUser}, inters: c.Interceptors(), } } // Get returns a User entity by its id. func (c *UserClient) Get(ctx context.Context, id int) (*User, error) { return c.Query().Where(user.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *UserClient) GetX(ctx context.Context, id int) *User { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryProducts queries the products edge of a User. func (c *UserClient) QueryProducts(u *User) *ProductQuery { query := (&ProductClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(product.Table, product.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, user.ProductsTable, user.ProductsColumn), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil } return query } // QueryDomains queries the domains edge of a User. func (c *UserClient) QueryDomains(u *User) *DomainQuery { query := (&DomainClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(domain.Table, domain.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, user.DomainsTable, user.DomainsColumn), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil } return query } // QueryBusinesses queries the businesses edge of a User. func (c *UserClient) QueryBusinesses(u *User) *BusinessQuery { query := (&BusinessClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(business.Table, business.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, user.BusinessesTable, user.BusinessesColumn), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *UserClient) Hooks() []Hook { return c.hooks.User } // Interceptors returns the client interceptors. func (c *UserClient) Interceptors() []Interceptor { return c.inters.User } func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { switch m.Op() { case OpCreate: return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } // hooks and interceptors per client, for fast access. type ( hooks struct { Business, BusinessCategory, BusinessConfig, Domain, Product, ProductCategory, User []ent.Hook } inters struct { Business, BusinessCategory, BusinessConfig, Domain, Product, ProductCategory, User []ent.Interceptor } )