// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "online-order/ent/business" "online-order/ent/businesscategory" "online-order/ent/businessconfig" "online-order/ent/domain" "online-order/ent/predicate" "online-order/ent/product" "online-order/ent/productcategory" "online-order/ent/schema" "online-order/ent/user" "sync" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeBusiness = "Business" TypeBusinessCategory = "BusinessCategory" TypeBusinessConfig = "BusinessConfig" TypeDomain = "Domain" TypeProduct = "Product" TypeProductCategory = "ProductCategory" TypeUser = "User" ) // BusinessMutation represents an operation that mutates the Business nodes in the graph. type BusinessMutation struct { config op Op typ string id *int name *string slug *string bot_id *string description *string about_us *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} business_categories *int clearedbusiness_categories bool users *int clearedusers bool products map[int]struct{} removedproducts map[int]struct{} clearedproducts bool product_categories map[int]struct{} removedproduct_categories map[int]struct{} clearedproduct_categories bool domains map[int]struct{} removeddomains map[int]struct{} cleareddomains bool business_configs map[int]struct{} removedbusiness_configs map[int]struct{} clearedbusiness_configs bool done bool oldValue func(context.Context) (*Business, error) predicates []predicate.Business } var _ ent.Mutation = (*BusinessMutation)(nil) // businessOption allows management of the mutation configuration using functional options. type businessOption func(*BusinessMutation) // newBusinessMutation creates new mutation for the Business entity. func newBusinessMutation(c config, op Op, opts ...businessOption) *BusinessMutation { m := &BusinessMutation{ config: c, op: op, typ: TypeBusiness, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withBusinessID sets the ID field of the mutation. func withBusinessID(id int) businessOption { return func(m *BusinessMutation) { var ( err error once sync.Once value *Business ) m.oldValue = func(ctx context.Context) (*Business, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Business.Get(ctx, id) } }) return value, err } m.id = &id } } // withBusiness sets the old Business of the mutation. func withBusiness(node *Business) businessOption { return func(m *BusinessMutation) { m.oldValue = func(context.Context) (*Business, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m BusinessMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m BusinessMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *BusinessMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *BusinessMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Business.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *BusinessMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *BusinessMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *BusinessMutation) ResetName() { m.name = nil } // SetSlug sets the "slug" field. func (m *BusinessMutation) SetSlug(s string) { m.slug = &s } // Slug returns the value of the "slug" field in the mutation. func (m *BusinessMutation) Slug() (r string, exists bool) { v := m.slug if v == nil { return } return *v, true } // OldSlug returns the old "slug" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldSlug(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSlug is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSlug requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSlug: %w", err) } return oldValue.Slug, nil } // ResetSlug resets all changes to the "slug" field. func (m *BusinessMutation) ResetSlug() { m.slug = nil } // SetBotID sets the "bot_id" field. func (m *BusinessMutation) SetBotID(s string) { m.bot_id = &s } // BotID returns the value of the "bot_id" field in the mutation. func (m *BusinessMutation) BotID() (r string, exists bool) { v := m.bot_id if v == nil { return } return *v, true } // OldBotID returns the old "bot_id" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldBotID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldBotID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldBotID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldBotID: %w", err) } return oldValue.BotID, nil } // ResetBotID resets all changes to the "bot_id" field. func (m *BusinessMutation) ResetBotID() { m.bot_id = nil } // SetDescription sets the "description" field. func (m *BusinessMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *BusinessMutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // OldDescription returns the old "description" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldDescription(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ClearDescription clears the value of the "description" field. func (m *BusinessMutation) ClearDescription() { m.description = nil m.clearedFields[business.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *BusinessMutation) DescriptionCleared() bool { _, ok := m.clearedFields[business.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *BusinessMutation) ResetDescription() { m.description = nil delete(m.clearedFields, business.FieldDescription) } // SetAboutUs sets the "about_us" field. func (m *BusinessMutation) SetAboutUs(s string) { m.about_us = &s } // AboutUs returns the value of the "about_us" field in the mutation. func (m *BusinessMutation) AboutUs() (r string, exists bool) { v := m.about_us if v == nil { return } return *v, true } // OldAboutUs returns the old "about_us" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldAboutUs(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAboutUs is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAboutUs requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAboutUs: %w", err) } return oldValue.AboutUs, nil } // ClearAboutUs clears the value of the "about_us" field. func (m *BusinessMutation) ClearAboutUs() { m.about_us = nil m.clearedFields[business.FieldAboutUs] = struct{}{} } // AboutUsCleared returns if the "about_us" field was cleared in this mutation. func (m *BusinessMutation) AboutUsCleared() bool { _, ok := m.clearedFields[business.FieldAboutUs] return ok } // ResetAboutUs resets all changes to the "about_us" field. func (m *BusinessMutation) ResetAboutUs() { m.about_us = nil delete(m.clearedFields, business.FieldAboutUs) } // SetBusinessCategoryID sets the "business_category_id" field. func (m *BusinessMutation) SetBusinessCategoryID(i int) { m.business_categories = &i } // BusinessCategoryID returns the value of the "business_category_id" field in the mutation. func (m *BusinessMutation) BusinessCategoryID() (r int, exists bool) { v := m.business_categories if v == nil { return } return *v, true } // OldBusinessCategoryID returns the old "business_category_id" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldBusinessCategoryID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldBusinessCategoryID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldBusinessCategoryID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldBusinessCategoryID: %w", err) } return oldValue.BusinessCategoryID, nil } // ClearBusinessCategoryID clears the value of the "business_category_id" field. func (m *BusinessMutation) ClearBusinessCategoryID() { m.business_categories = nil m.clearedFields[business.FieldBusinessCategoryID] = struct{}{} } // BusinessCategoryIDCleared returns if the "business_category_id" field was cleared in this mutation. func (m *BusinessMutation) BusinessCategoryIDCleared() bool { _, ok := m.clearedFields[business.FieldBusinessCategoryID] return ok } // ResetBusinessCategoryID resets all changes to the "business_category_id" field. func (m *BusinessMutation) ResetBusinessCategoryID() { m.business_categories = nil delete(m.clearedFields, business.FieldBusinessCategoryID) } // SetUserID sets the "user_id" field. func (m *BusinessMutation) SetUserID(i int) { m.users = &i } // UserID returns the value of the "user_id" field in the mutation. func (m *BusinessMutation) UserID() (r int, exists bool) { v := m.users if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldUserID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ClearUserID clears the value of the "user_id" field. func (m *BusinessMutation) ClearUserID() { m.users = nil m.clearedFields[business.FieldUserID] = struct{}{} } // UserIDCleared returns if the "user_id" field was cleared in this mutation. func (m *BusinessMutation) UserIDCleared() bool { _, ok := m.clearedFields[business.FieldUserID] return ok } // ResetUserID resets all changes to the "user_id" field. func (m *BusinessMutation) ResetUserID() { m.users = nil delete(m.clearedFields, business.FieldUserID) } // SetCreatedAt sets the "created_at" field. func (m *BusinessMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *BusinessMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ResetCreatedAt resets all changes to the "created_at" field. func (m *BusinessMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *BusinessMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *BusinessMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Business entity. // If the Business object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *BusinessMutation) ResetUpdatedAt() { m.updated_at = nil } // SetBusinessCategoriesID sets the "business_categories" edge to the BusinessCategory entity by id. func (m *BusinessMutation) SetBusinessCategoriesID(id int) { m.business_categories = &id } // ClearBusinessCategories clears the "business_categories" edge to the BusinessCategory entity. func (m *BusinessMutation) ClearBusinessCategories() { m.clearedbusiness_categories = true m.clearedFields[business.FieldBusinessCategoryID] = struct{}{} } // BusinessCategoriesCleared reports if the "business_categories" edge to the BusinessCategory entity was cleared. func (m *BusinessMutation) BusinessCategoriesCleared() bool { return m.BusinessCategoryIDCleared() || m.clearedbusiness_categories } // BusinessCategoriesID returns the "business_categories" edge ID in the mutation. func (m *BusinessMutation) BusinessCategoriesID() (id int, exists bool) { if m.business_categories != nil { return *m.business_categories, true } return } // BusinessCategoriesIDs returns the "business_categories" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // BusinessCategoriesID instead. It exists only for internal usage by the builders. func (m *BusinessMutation) BusinessCategoriesIDs() (ids []int) { if id := m.business_categories; id != nil { ids = append(ids, *id) } return } // ResetBusinessCategories resets all changes to the "business_categories" edge. func (m *BusinessMutation) ResetBusinessCategories() { m.business_categories = nil m.clearedbusiness_categories = false } // SetUsersID sets the "users" edge to the User entity by id. func (m *BusinessMutation) SetUsersID(id int) { m.users = &id } // ClearUsers clears the "users" edge to the User entity. func (m *BusinessMutation) ClearUsers() { m.clearedusers = true m.clearedFields[business.FieldUserID] = struct{}{} } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *BusinessMutation) UsersCleared() bool { return m.UserIDCleared() || m.clearedusers } // UsersID returns the "users" edge ID in the mutation. func (m *BusinessMutation) UsersID() (id int, exists bool) { if m.users != nil { return *m.users, true } return } // UsersIDs returns the "users" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UsersID instead. It exists only for internal usage by the builders. func (m *BusinessMutation) UsersIDs() (ids []int) { if id := m.users; id != nil { ids = append(ids, *id) } return } // ResetUsers resets all changes to the "users" edge. func (m *BusinessMutation) ResetUsers() { m.users = nil m.clearedusers = false } // AddProductIDs adds the "products" edge to the Product entity by ids. func (m *BusinessMutation) AddProductIDs(ids ...int) { if m.products == nil { m.products = make(map[int]struct{}) } for i := range ids { m.products[ids[i]] = struct{}{} } } // ClearProducts clears the "products" edge to the Product entity. func (m *BusinessMutation) ClearProducts() { m.clearedproducts = true } // ProductsCleared reports if the "products" edge to the Product entity was cleared. func (m *BusinessMutation) ProductsCleared() bool { return m.clearedproducts } // RemoveProductIDs removes the "products" edge to the Product entity by IDs. func (m *BusinessMutation) RemoveProductIDs(ids ...int) { if m.removedproducts == nil { m.removedproducts = make(map[int]struct{}) } for i := range ids { delete(m.products, ids[i]) m.removedproducts[ids[i]] = struct{}{} } } // RemovedProducts returns the removed IDs of the "products" edge to the Product entity. func (m *BusinessMutation) RemovedProductsIDs() (ids []int) { for id := range m.removedproducts { ids = append(ids, id) } return } // ProductsIDs returns the "products" edge IDs in the mutation. func (m *BusinessMutation) ProductsIDs() (ids []int) { for id := range m.products { ids = append(ids, id) } return } // ResetProducts resets all changes to the "products" edge. func (m *BusinessMutation) ResetProducts() { m.products = nil m.clearedproducts = false m.removedproducts = nil } // AddProductCategoryIDs adds the "product_categories" edge to the ProductCategory entity by ids. func (m *BusinessMutation) AddProductCategoryIDs(ids ...int) { if m.product_categories == nil { m.product_categories = make(map[int]struct{}) } for i := range ids { m.product_categories[ids[i]] = struct{}{} } } // ClearProductCategories clears the "product_categories" edge to the ProductCategory entity. func (m *BusinessMutation) ClearProductCategories() { m.clearedproduct_categories = true } // ProductCategoriesCleared reports if the "product_categories" edge to the ProductCategory entity was cleared. func (m *BusinessMutation) ProductCategoriesCleared() bool { return m.clearedproduct_categories } // RemoveProductCategoryIDs removes the "product_categories" edge to the ProductCategory entity by IDs. func (m *BusinessMutation) RemoveProductCategoryIDs(ids ...int) { if m.removedproduct_categories == nil { m.removedproduct_categories = make(map[int]struct{}) } for i := range ids { delete(m.product_categories, ids[i]) m.removedproduct_categories[ids[i]] = struct{}{} } } // RemovedProductCategories returns the removed IDs of the "product_categories" edge to the ProductCategory entity. func (m *BusinessMutation) RemovedProductCategoriesIDs() (ids []int) { for id := range m.removedproduct_categories { ids = append(ids, id) } return } // ProductCategoriesIDs returns the "product_categories" edge IDs in the mutation. func (m *BusinessMutation) ProductCategoriesIDs() (ids []int) { for id := range m.product_categories { ids = append(ids, id) } return } // ResetProductCategories resets all changes to the "product_categories" edge. func (m *BusinessMutation) ResetProductCategories() { m.product_categories = nil m.clearedproduct_categories = false m.removedproduct_categories = nil } // AddDomainIDs adds the "domains" edge to the Domain entity by ids. func (m *BusinessMutation) AddDomainIDs(ids ...int) { if m.domains == nil { m.domains = make(map[int]struct{}) } for i := range ids { m.domains[ids[i]] = struct{}{} } } // ClearDomains clears the "domains" edge to the Domain entity. func (m *BusinessMutation) ClearDomains() { m.cleareddomains = true } // DomainsCleared reports if the "domains" edge to the Domain entity was cleared. func (m *BusinessMutation) DomainsCleared() bool { return m.cleareddomains } // RemoveDomainIDs removes the "domains" edge to the Domain entity by IDs. func (m *BusinessMutation) RemoveDomainIDs(ids ...int) { if m.removeddomains == nil { m.removeddomains = make(map[int]struct{}) } for i := range ids { delete(m.domains, ids[i]) m.removeddomains[ids[i]] = struct{}{} } } // RemovedDomains returns the removed IDs of the "domains" edge to the Domain entity. func (m *BusinessMutation) RemovedDomainsIDs() (ids []int) { for id := range m.removeddomains { ids = append(ids, id) } return } // DomainsIDs returns the "domains" edge IDs in the mutation. func (m *BusinessMutation) DomainsIDs() (ids []int) { for id := range m.domains { ids = append(ids, id) } return } // ResetDomains resets all changes to the "domains" edge. func (m *BusinessMutation) ResetDomains() { m.domains = nil m.cleareddomains = false m.removeddomains = nil } // AddBusinessConfigIDs adds the "business_configs" edge to the BusinessConfig entity by ids. func (m *BusinessMutation) AddBusinessConfigIDs(ids ...int) { if m.business_configs == nil { m.business_configs = make(map[int]struct{}) } for i := range ids { m.business_configs[ids[i]] = struct{}{} } } // ClearBusinessConfigs clears the "business_configs" edge to the BusinessConfig entity. func (m *BusinessMutation) ClearBusinessConfigs() { m.clearedbusiness_configs = true } // BusinessConfigsCleared reports if the "business_configs" edge to the BusinessConfig entity was cleared. func (m *BusinessMutation) BusinessConfigsCleared() bool { return m.clearedbusiness_configs } // RemoveBusinessConfigIDs removes the "business_configs" edge to the BusinessConfig entity by IDs. func (m *BusinessMutation) RemoveBusinessConfigIDs(ids ...int) { if m.removedbusiness_configs == nil { m.removedbusiness_configs = make(map[int]struct{}) } for i := range ids { delete(m.business_configs, ids[i]) m.removedbusiness_configs[ids[i]] = struct{}{} } } // RemovedBusinessConfigs returns the removed IDs of the "business_configs" edge to the BusinessConfig entity. func (m *BusinessMutation) RemovedBusinessConfigsIDs() (ids []int) { for id := range m.removedbusiness_configs { ids = append(ids, id) } return } // BusinessConfigsIDs returns the "business_configs" edge IDs in the mutation. func (m *BusinessMutation) BusinessConfigsIDs() (ids []int) { for id := range m.business_configs { ids = append(ids, id) } return } // ResetBusinessConfigs resets all changes to the "business_configs" edge. func (m *BusinessMutation) ResetBusinessConfigs() { m.business_configs = nil m.clearedbusiness_configs = false m.removedbusiness_configs = nil } // Where appends a list predicates to the BusinessMutation builder. func (m *BusinessMutation) Where(ps ...predicate.Business) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the BusinessMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *BusinessMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Business, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *BusinessMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *BusinessMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Business). func (m *BusinessMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *BusinessMutation) Fields() []string { fields := make([]string, 0, 9) if m.name != nil { fields = append(fields, business.FieldName) } if m.slug != nil { fields = append(fields, business.FieldSlug) } if m.bot_id != nil { fields = append(fields, business.FieldBotID) } if m.description != nil { fields = append(fields, business.FieldDescription) } if m.about_us != nil { fields = append(fields, business.FieldAboutUs) } if m.business_categories != nil { fields = append(fields, business.FieldBusinessCategoryID) } if m.users != nil { fields = append(fields, business.FieldUserID) } if m.created_at != nil { fields = append(fields, business.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, business.FieldUpdatedAt) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *BusinessMutation) Field(name string) (ent.Value, bool) { switch name { case business.FieldName: return m.Name() case business.FieldSlug: return m.Slug() case business.FieldBotID: return m.BotID() case business.FieldDescription: return m.Description() case business.FieldAboutUs: return m.AboutUs() case business.FieldBusinessCategoryID: return m.BusinessCategoryID() case business.FieldUserID: return m.UserID() case business.FieldCreatedAt: return m.CreatedAt() case business.FieldUpdatedAt: return m.UpdatedAt() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *BusinessMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case business.FieldName: return m.OldName(ctx) case business.FieldSlug: return m.OldSlug(ctx) case business.FieldBotID: return m.OldBotID(ctx) case business.FieldDescription: return m.OldDescription(ctx) case business.FieldAboutUs: return m.OldAboutUs(ctx) case business.FieldBusinessCategoryID: return m.OldBusinessCategoryID(ctx) case business.FieldUserID: return m.OldUserID(ctx) case business.FieldCreatedAt: return m.OldCreatedAt(ctx) case business.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Business field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *BusinessMutation) SetField(name string, value ent.Value) error { switch name { case business.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case business.FieldSlug: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSlug(v) return nil case business.FieldBotID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBotID(v) return nil case business.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case business.FieldAboutUs: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAboutUs(v) return nil case business.FieldBusinessCategoryID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBusinessCategoryID(v) return nil case business.FieldUserID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case business.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case business.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Business field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *BusinessMutation) AddedFields() []string { var fields []string return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *BusinessMutation) AddedField(name string) (ent.Value, bool) { switch name { } return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *BusinessMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Business numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *BusinessMutation) ClearedFields() []string { var fields []string if m.FieldCleared(business.FieldDescription) { fields = append(fields, business.FieldDescription) } if m.FieldCleared(business.FieldAboutUs) { fields = append(fields, business.FieldAboutUs) } if m.FieldCleared(business.FieldBusinessCategoryID) { fields = append(fields, business.FieldBusinessCategoryID) } if m.FieldCleared(business.FieldUserID) { fields = append(fields, business.FieldUserID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *BusinessMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *BusinessMutation) ClearField(name string) error { switch name { case business.FieldDescription: m.ClearDescription() return nil case business.FieldAboutUs: m.ClearAboutUs() return nil case business.FieldBusinessCategoryID: m.ClearBusinessCategoryID() return nil case business.FieldUserID: m.ClearUserID() return nil } return fmt.Errorf("unknown Business nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *BusinessMutation) ResetField(name string) error { switch name { case business.FieldName: m.ResetName() return nil case business.FieldSlug: m.ResetSlug() return nil case business.FieldBotID: m.ResetBotID() return nil case business.FieldDescription: m.ResetDescription() return nil case business.FieldAboutUs: m.ResetAboutUs() return nil case business.FieldBusinessCategoryID: m.ResetBusinessCategoryID() return nil case business.FieldUserID: m.ResetUserID() return nil case business.FieldCreatedAt: m.ResetCreatedAt() return nil case business.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Business field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *BusinessMutation) AddedEdges() []string { edges := make([]string, 0, 6) if m.business_categories != nil { edges = append(edges, business.EdgeBusinessCategories) } if m.users != nil { edges = append(edges, business.EdgeUsers) } if m.products != nil { edges = append(edges, business.EdgeProducts) } if m.product_categories != nil { edges = append(edges, business.EdgeProductCategories) } if m.domains != nil { edges = append(edges, business.EdgeDomains) } if m.business_configs != nil { edges = append(edges, business.EdgeBusinessConfigs) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *BusinessMutation) AddedIDs(name string) []ent.Value { switch name { case business.EdgeBusinessCategories: if id := m.business_categories; id != nil { return []ent.Value{*id} } case business.EdgeUsers: if id := m.users; id != nil { return []ent.Value{*id} } case business.EdgeProducts: ids := make([]ent.Value, 0, len(m.products)) for id := range m.products { ids = append(ids, id) } return ids case business.EdgeProductCategories: ids := make([]ent.Value, 0, len(m.product_categories)) for id := range m.product_categories { ids = append(ids, id) } return ids case business.EdgeDomains: ids := make([]ent.Value, 0, len(m.domains)) for id := range m.domains { ids = append(ids, id) } return ids case business.EdgeBusinessConfigs: ids := make([]ent.Value, 0, len(m.business_configs)) for id := range m.business_configs { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *BusinessMutation) RemovedEdges() []string { edges := make([]string, 0, 6) if m.removedproducts != nil { edges = append(edges, business.EdgeProducts) } if m.removedproduct_categories != nil { edges = append(edges, business.EdgeProductCategories) } if m.removeddomains != nil { edges = append(edges, business.EdgeDomains) } if m.removedbusiness_configs != nil { edges = append(edges, business.EdgeBusinessConfigs) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *BusinessMutation) RemovedIDs(name string) []ent.Value { switch name { case business.EdgeProducts: ids := make([]ent.Value, 0, len(m.removedproducts)) for id := range m.removedproducts { ids = append(ids, id) } return ids case business.EdgeProductCategories: ids := make([]ent.Value, 0, len(m.removedproduct_categories)) for id := range m.removedproduct_categories { ids = append(ids, id) } return ids case business.EdgeDomains: ids := make([]ent.Value, 0, len(m.removeddomains)) for id := range m.removeddomains { ids = append(ids, id) } return ids case business.EdgeBusinessConfigs: ids := make([]ent.Value, 0, len(m.removedbusiness_configs)) for id := range m.removedbusiness_configs { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BusinessMutation) ClearedEdges() []string { edges := make([]string, 0, 6) if m.clearedbusiness_categories { edges = append(edges, business.EdgeBusinessCategories) } if m.clearedusers { edges = append(edges, business.EdgeUsers) } if m.clearedproducts { edges = append(edges, business.EdgeProducts) } if m.clearedproduct_categories { edges = append(edges, business.EdgeProductCategories) } if m.cleareddomains { edges = append(edges, business.EdgeDomains) } if m.clearedbusiness_configs { edges = append(edges, business.EdgeBusinessConfigs) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *BusinessMutation) EdgeCleared(name string) bool { switch name { case business.EdgeBusinessCategories: return m.clearedbusiness_categories case business.EdgeUsers: return m.clearedusers case business.EdgeProducts: return m.clearedproducts case business.EdgeProductCategories: return m.clearedproduct_categories case business.EdgeDomains: return m.cleareddomains case business.EdgeBusinessConfigs: return m.clearedbusiness_configs } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *BusinessMutation) ClearEdge(name string) error { switch name { case business.EdgeBusinessCategories: m.ClearBusinessCategories() return nil case business.EdgeUsers: m.ClearUsers() return nil } return fmt.Errorf("unknown Business unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *BusinessMutation) ResetEdge(name string) error { switch name { case business.EdgeBusinessCategories: m.ResetBusinessCategories() return nil case business.EdgeUsers: m.ResetUsers() return nil case business.EdgeProducts: m.ResetProducts() return nil case business.EdgeProductCategories: m.ResetProductCategories() return nil case business.EdgeDomains: m.ResetDomains() return nil case business.EdgeBusinessConfigs: m.ResetBusinessConfigs() return nil } return fmt.Errorf("unknown Business edge %s", name) } // BusinessCategoryMutation represents an operation that mutates the BusinessCategory nodes in the graph. type BusinessCategoryMutation struct { config op Op typ string id *int slug *string name *string description *string clearedFields map[string]struct{} businesses map[int]struct{} removedbusinesses map[int]struct{} clearedbusinesses bool done bool oldValue func(context.Context) (*BusinessCategory, error) predicates []predicate.BusinessCategory } var _ ent.Mutation = (*BusinessCategoryMutation)(nil) // businesscategoryOption allows management of the mutation configuration using functional options. type businesscategoryOption func(*BusinessCategoryMutation) // newBusinessCategoryMutation creates new mutation for the BusinessCategory entity. func newBusinessCategoryMutation(c config, op Op, opts ...businesscategoryOption) *BusinessCategoryMutation { m := &BusinessCategoryMutation{ config: c, op: op, typ: TypeBusinessCategory, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withBusinessCategoryID sets the ID field of the mutation. func withBusinessCategoryID(id int) businesscategoryOption { return func(m *BusinessCategoryMutation) { var ( err error once sync.Once value *BusinessCategory ) m.oldValue = func(ctx context.Context) (*BusinessCategory, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().BusinessCategory.Get(ctx, id) } }) return value, err } m.id = &id } } // withBusinessCategory sets the old BusinessCategory of the mutation. func withBusinessCategory(node *BusinessCategory) businesscategoryOption { return func(m *BusinessCategoryMutation) { m.oldValue = func(context.Context) (*BusinessCategory, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m BusinessCategoryMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m BusinessCategoryMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *BusinessCategoryMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *BusinessCategoryMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().BusinessCategory.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetSlug sets the "slug" field. func (m *BusinessCategoryMutation) SetSlug(s string) { m.slug = &s } // Slug returns the value of the "slug" field in the mutation. func (m *BusinessCategoryMutation) Slug() (r string, exists bool) { v := m.slug if v == nil { return } return *v, true } // OldSlug returns the old "slug" field's value of the BusinessCategory entity. // If the BusinessCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessCategoryMutation) OldSlug(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSlug is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSlug requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSlug: %w", err) } return oldValue.Slug, nil } // ResetSlug resets all changes to the "slug" field. func (m *BusinessCategoryMutation) ResetSlug() { m.slug = nil } // SetName sets the "name" field. func (m *BusinessCategoryMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *BusinessCategoryMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the BusinessCategory entity. // If the BusinessCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessCategoryMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *BusinessCategoryMutation) ResetName() { m.name = nil } // SetDescription sets the "description" field. func (m *BusinessCategoryMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *BusinessCategoryMutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // OldDescription returns the old "description" field's value of the BusinessCategory entity. // If the BusinessCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessCategoryMutation) OldDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ResetDescription resets all changes to the "description" field. func (m *BusinessCategoryMutation) ResetDescription() { m.description = nil } // AddBusinessIDs adds the "businesses" edge to the Business entity by ids. func (m *BusinessCategoryMutation) AddBusinessIDs(ids ...int) { if m.businesses == nil { m.businesses = make(map[int]struct{}) } for i := range ids { m.businesses[ids[i]] = struct{}{} } } // ClearBusinesses clears the "businesses" edge to the Business entity. func (m *BusinessCategoryMutation) ClearBusinesses() { m.clearedbusinesses = true } // BusinessesCleared reports if the "businesses" edge to the Business entity was cleared. func (m *BusinessCategoryMutation) BusinessesCleared() bool { return m.clearedbusinesses } // RemoveBusinessIDs removes the "businesses" edge to the Business entity by IDs. func (m *BusinessCategoryMutation) RemoveBusinessIDs(ids ...int) { if m.removedbusinesses == nil { m.removedbusinesses = make(map[int]struct{}) } for i := range ids { delete(m.businesses, ids[i]) m.removedbusinesses[ids[i]] = struct{}{} } } // RemovedBusinesses returns the removed IDs of the "businesses" edge to the Business entity. func (m *BusinessCategoryMutation) RemovedBusinessesIDs() (ids []int) { for id := range m.removedbusinesses { ids = append(ids, id) } return } // BusinessesIDs returns the "businesses" edge IDs in the mutation. func (m *BusinessCategoryMutation) BusinessesIDs() (ids []int) { for id := range m.businesses { ids = append(ids, id) } return } // ResetBusinesses resets all changes to the "businesses" edge. func (m *BusinessCategoryMutation) ResetBusinesses() { m.businesses = nil m.clearedbusinesses = false m.removedbusinesses = nil } // Where appends a list predicates to the BusinessCategoryMutation builder. func (m *BusinessCategoryMutation) Where(ps ...predicate.BusinessCategory) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the BusinessCategoryMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *BusinessCategoryMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.BusinessCategory, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *BusinessCategoryMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *BusinessCategoryMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (BusinessCategory). func (m *BusinessCategoryMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *BusinessCategoryMutation) Fields() []string { fields := make([]string, 0, 3) if m.slug != nil { fields = append(fields, businesscategory.FieldSlug) } if m.name != nil { fields = append(fields, businesscategory.FieldName) } if m.description != nil { fields = append(fields, businesscategory.FieldDescription) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *BusinessCategoryMutation) Field(name string) (ent.Value, bool) { switch name { case businesscategory.FieldSlug: return m.Slug() case businesscategory.FieldName: return m.Name() case businesscategory.FieldDescription: return m.Description() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *BusinessCategoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case businesscategory.FieldSlug: return m.OldSlug(ctx) case businesscategory.FieldName: return m.OldName(ctx) case businesscategory.FieldDescription: return m.OldDescription(ctx) } return nil, fmt.Errorf("unknown BusinessCategory field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *BusinessCategoryMutation) SetField(name string, value ent.Value) error { switch name { case businesscategory.FieldSlug: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSlug(v) return nil case businesscategory.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case businesscategory.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil } return fmt.Errorf("unknown BusinessCategory field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *BusinessCategoryMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *BusinessCategoryMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *BusinessCategoryMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown BusinessCategory numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *BusinessCategoryMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *BusinessCategoryMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *BusinessCategoryMutation) ClearField(name string) error { return fmt.Errorf("unknown BusinessCategory nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *BusinessCategoryMutation) ResetField(name string) error { switch name { case businesscategory.FieldSlug: m.ResetSlug() return nil case businesscategory.FieldName: m.ResetName() return nil case businesscategory.FieldDescription: m.ResetDescription() return nil } return fmt.Errorf("unknown BusinessCategory field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *BusinessCategoryMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.businesses != nil { edges = append(edges, businesscategory.EdgeBusinesses) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *BusinessCategoryMutation) AddedIDs(name string) []ent.Value { switch name { case businesscategory.EdgeBusinesses: ids := make([]ent.Value, 0, len(m.businesses)) for id := range m.businesses { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *BusinessCategoryMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedbusinesses != nil { edges = append(edges, businesscategory.EdgeBusinesses) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *BusinessCategoryMutation) RemovedIDs(name string) []ent.Value { switch name { case businesscategory.EdgeBusinesses: ids := make([]ent.Value, 0, len(m.removedbusinesses)) for id := range m.removedbusinesses { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BusinessCategoryMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedbusinesses { edges = append(edges, businesscategory.EdgeBusinesses) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *BusinessCategoryMutation) EdgeCleared(name string) bool { switch name { case businesscategory.EdgeBusinesses: return m.clearedbusinesses } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *BusinessCategoryMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown BusinessCategory unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *BusinessCategoryMutation) ResetEdge(name string) error { switch name { case businesscategory.EdgeBusinesses: m.ResetBusinesses() return nil } return fmt.Errorf("unknown BusinessCategory edge %s", name) } // BusinessConfigMutation represents an operation that mutates the BusinessConfig nodes in the graph. type BusinessConfigMutation struct { config op Op typ string id *int company *string auth_config *schema.AuthConfig _config *[]string append_config []string clearedFields map[string]struct{} businesses *int clearedbusinesses bool done bool oldValue func(context.Context) (*BusinessConfig, error) predicates []predicate.BusinessConfig } var _ ent.Mutation = (*BusinessConfigMutation)(nil) // businessconfigOption allows management of the mutation configuration using functional options. type businessconfigOption func(*BusinessConfigMutation) // newBusinessConfigMutation creates new mutation for the BusinessConfig entity. func newBusinessConfigMutation(c config, op Op, opts ...businessconfigOption) *BusinessConfigMutation { m := &BusinessConfigMutation{ config: c, op: op, typ: TypeBusinessConfig, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withBusinessConfigID sets the ID field of the mutation. func withBusinessConfigID(id int) businessconfigOption { return func(m *BusinessConfigMutation) { var ( err error once sync.Once value *BusinessConfig ) m.oldValue = func(ctx context.Context) (*BusinessConfig, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().BusinessConfig.Get(ctx, id) } }) return value, err } m.id = &id } } // withBusinessConfig sets the old BusinessConfig of the mutation. func withBusinessConfig(node *BusinessConfig) businessconfigOption { return func(m *BusinessConfigMutation) { m.oldValue = func(context.Context) (*BusinessConfig, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m BusinessConfigMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m BusinessConfigMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *BusinessConfigMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *BusinessConfigMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().BusinessConfig.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCompany sets the "company" field. func (m *BusinessConfigMutation) SetCompany(s string) { m.company = &s } // Company returns the value of the "company" field in the mutation. func (m *BusinessConfigMutation) Company() (r string, exists bool) { v := m.company if v == nil { return } return *v, true } // OldCompany returns the old "company" field's value of the BusinessConfig entity. // If the BusinessConfig object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessConfigMutation) OldCompany(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCompany is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCompany requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCompany: %w", err) } return oldValue.Company, nil } // ResetCompany resets all changes to the "company" field. func (m *BusinessConfigMutation) ResetCompany() { m.company = nil } // SetAuthConfig sets the "auth_config" field. func (m *BusinessConfigMutation) SetAuthConfig(sc schema.AuthConfig) { m.auth_config = &sc } // AuthConfig returns the value of the "auth_config" field in the mutation. func (m *BusinessConfigMutation) AuthConfig() (r schema.AuthConfig, exists bool) { v := m.auth_config if v == nil { return } return *v, true } // OldAuthConfig returns the old "auth_config" field's value of the BusinessConfig entity. // If the BusinessConfig object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessConfigMutation) OldAuthConfig(ctx context.Context) (v schema.AuthConfig, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAuthConfig is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAuthConfig requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAuthConfig: %w", err) } return oldValue.AuthConfig, nil } // ResetAuthConfig resets all changes to the "auth_config" field. func (m *BusinessConfigMutation) ResetAuthConfig() { m.auth_config = nil } // SetConfig sets the "config" field. func (m *BusinessConfigMutation) SetConfig(s []string) { m._config = &s m.append_config = nil } // Config returns the value of the "config" field in the mutation. func (m *BusinessConfigMutation) Config() (r []string, exists bool) { v := m._config if v == nil { return } return *v, true } // OldConfig returns the old "config" field's value of the BusinessConfig entity. // If the BusinessConfig object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessConfigMutation) OldConfig(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldConfig is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldConfig requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldConfig: %w", err) } return oldValue.Config, nil } // AppendConfig adds s to the "config" field. func (m *BusinessConfigMutation) AppendConfig(s []string) { m.append_config = append(m.append_config, s...) } // AppendedConfig returns the list of values that were appended to the "config" field in this mutation. func (m *BusinessConfigMutation) AppendedConfig() ([]string, bool) { if len(m.append_config) == 0 { return nil, false } return m.append_config, true } // ResetConfig resets all changes to the "config" field. func (m *BusinessConfigMutation) ResetConfig() { m._config = nil m.append_config = nil } // SetBusinessID sets the "business_id" field. func (m *BusinessConfigMutation) SetBusinessID(i int) { m.businesses = &i } // BusinessID returns the value of the "business_id" field in the mutation. func (m *BusinessConfigMutation) BusinessID() (r int, exists bool) { v := m.businesses if v == nil { return } return *v, true } // OldBusinessID returns the old "business_id" field's value of the BusinessConfig entity. // If the BusinessConfig object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BusinessConfigMutation) OldBusinessID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldBusinessID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldBusinessID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldBusinessID: %w", err) } return oldValue.BusinessID, nil } // ClearBusinessID clears the value of the "business_id" field. func (m *BusinessConfigMutation) ClearBusinessID() { m.businesses = nil m.clearedFields[businessconfig.FieldBusinessID] = struct{}{} } // BusinessIDCleared returns if the "business_id" field was cleared in this mutation. func (m *BusinessConfigMutation) BusinessIDCleared() bool { _, ok := m.clearedFields[businessconfig.FieldBusinessID] return ok } // ResetBusinessID resets all changes to the "business_id" field. func (m *BusinessConfigMutation) ResetBusinessID() { m.businesses = nil delete(m.clearedFields, businessconfig.FieldBusinessID) } // SetBusinessesID sets the "businesses" edge to the Business entity by id. func (m *BusinessConfigMutation) SetBusinessesID(id int) { m.businesses = &id } // ClearBusinesses clears the "businesses" edge to the Business entity. func (m *BusinessConfigMutation) ClearBusinesses() { m.clearedbusinesses = true m.clearedFields[businessconfig.FieldBusinessID] = struct{}{} } // BusinessesCleared reports if the "businesses" edge to the Business entity was cleared. func (m *BusinessConfigMutation) BusinessesCleared() bool { return m.BusinessIDCleared() || m.clearedbusinesses } // BusinessesID returns the "businesses" edge ID in the mutation. func (m *BusinessConfigMutation) BusinessesID() (id int, exists bool) { if m.businesses != nil { return *m.businesses, true } return } // BusinessesIDs returns the "businesses" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // BusinessesID instead. It exists only for internal usage by the builders. func (m *BusinessConfigMutation) BusinessesIDs() (ids []int) { if id := m.businesses; id != nil { ids = append(ids, *id) } return } // ResetBusinesses resets all changes to the "businesses" edge. func (m *BusinessConfigMutation) ResetBusinesses() { m.businesses = nil m.clearedbusinesses = false } // Where appends a list predicates to the BusinessConfigMutation builder. func (m *BusinessConfigMutation) Where(ps ...predicate.BusinessConfig) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the BusinessConfigMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *BusinessConfigMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.BusinessConfig, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *BusinessConfigMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *BusinessConfigMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (BusinessConfig). func (m *BusinessConfigMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *BusinessConfigMutation) Fields() []string { fields := make([]string, 0, 4) if m.company != nil { fields = append(fields, businessconfig.FieldCompany) } if m.auth_config != nil { fields = append(fields, businessconfig.FieldAuthConfig) } if m._config != nil { fields = append(fields, businessconfig.FieldConfig) } if m.businesses != nil { fields = append(fields, businessconfig.FieldBusinessID) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *BusinessConfigMutation) Field(name string) (ent.Value, bool) { switch name { case businessconfig.FieldCompany: return m.Company() case businessconfig.FieldAuthConfig: return m.AuthConfig() case businessconfig.FieldConfig: return m.Config() case businessconfig.FieldBusinessID: return m.BusinessID() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *BusinessConfigMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case businessconfig.FieldCompany: return m.OldCompany(ctx) case businessconfig.FieldAuthConfig: return m.OldAuthConfig(ctx) case businessconfig.FieldConfig: return m.OldConfig(ctx) case businessconfig.FieldBusinessID: return m.OldBusinessID(ctx) } return nil, fmt.Errorf("unknown BusinessConfig field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *BusinessConfigMutation) SetField(name string, value ent.Value) error { switch name { case businessconfig.FieldCompany: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCompany(v) return nil case businessconfig.FieldAuthConfig: v, ok := value.(schema.AuthConfig) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAuthConfig(v) return nil case businessconfig.FieldConfig: v, ok := value.([]string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetConfig(v) return nil case businessconfig.FieldBusinessID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBusinessID(v) return nil } return fmt.Errorf("unknown BusinessConfig field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *BusinessConfigMutation) AddedFields() []string { var fields []string return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *BusinessConfigMutation) AddedField(name string) (ent.Value, bool) { switch name { } return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *BusinessConfigMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown BusinessConfig numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *BusinessConfigMutation) ClearedFields() []string { var fields []string if m.FieldCleared(businessconfig.FieldBusinessID) { fields = append(fields, businessconfig.FieldBusinessID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *BusinessConfigMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *BusinessConfigMutation) ClearField(name string) error { switch name { case businessconfig.FieldBusinessID: m.ClearBusinessID() return nil } return fmt.Errorf("unknown BusinessConfig nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *BusinessConfigMutation) ResetField(name string) error { switch name { case businessconfig.FieldCompany: m.ResetCompany() return nil case businessconfig.FieldAuthConfig: m.ResetAuthConfig() return nil case businessconfig.FieldConfig: m.ResetConfig() return nil case businessconfig.FieldBusinessID: m.ResetBusinessID() return nil } return fmt.Errorf("unknown BusinessConfig field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *BusinessConfigMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.businesses != nil { edges = append(edges, businessconfig.EdgeBusinesses) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *BusinessConfigMutation) AddedIDs(name string) []ent.Value { switch name { case businessconfig.EdgeBusinesses: if id := m.businesses; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *BusinessConfigMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *BusinessConfigMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BusinessConfigMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedbusinesses { edges = append(edges, businessconfig.EdgeBusinesses) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *BusinessConfigMutation) EdgeCleared(name string) bool { switch name { case businessconfig.EdgeBusinesses: return m.clearedbusinesses } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *BusinessConfigMutation) ClearEdge(name string) error { switch name { case businessconfig.EdgeBusinesses: m.ClearBusinesses() return nil } return fmt.Errorf("unknown BusinessConfig unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *BusinessConfigMutation) ResetEdge(name string) error { switch name { case businessconfig.EdgeBusinesses: m.ResetBusinesses() return nil } return fmt.Errorf("unknown BusinessConfig edge %s", name) } // DomainMutation represents an operation that mutates the Domain nodes in the graph. type DomainMutation struct { config op Op typ string id *int domain *string _config *[]string append_config []string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} businesses *int clearedbusinesses bool users *int clearedusers bool done bool oldValue func(context.Context) (*Domain, error) predicates []predicate.Domain } var _ ent.Mutation = (*DomainMutation)(nil) // domainOption allows management of the mutation configuration using functional options. type domainOption func(*DomainMutation) // newDomainMutation creates new mutation for the Domain entity. func newDomainMutation(c config, op Op, opts ...domainOption) *DomainMutation { m := &DomainMutation{ config: c, op: op, typ: TypeDomain, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDomainID sets the ID field of the mutation. func withDomainID(id int) domainOption { return func(m *DomainMutation) { var ( err error once sync.Once value *Domain ) m.oldValue = func(ctx context.Context) (*Domain, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Domain.Get(ctx, id) } }) return value, err } m.id = &id } } // withDomain sets the old Domain of the mutation. func withDomain(node *Domain) domainOption { return func(m *DomainMutation) { m.oldValue = func(context.Context) (*Domain, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m DomainMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m DomainMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *DomainMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *DomainMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Domain.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetDomain sets the "domain" field. func (m *DomainMutation) SetDomain(s string) { m.domain = &s } // Domain returns the value of the "domain" field in the mutation. func (m *DomainMutation) Domain() (r string, exists bool) { v := m.domain if v == nil { return } return *v, true } // OldDomain returns the old "domain" field's value of the Domain entity. // If the Domain object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DomainMutation) OldDomain(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDomain is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDomain requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDomain: %w", err) } return oldValue.Domain, nil } // ResetDomain resets all changes to the "domain" field. func (m *DomainMutation) ResetDomain() { m.domain = nil } // SetBusinessID sets the "business_id" field. func (m *DomainMutation) SetBusinessID(i int) { m.businesses = &i } // BusinessID returns the value of the "business_id" field in the mutation. func (m *DomainMutation) BusinessID() (r int, exists bool) { v := m.businesses if v == nil { return } return *v, true } // OldBusinessID returns the old "business_id" field's value of the Domain entity. // If the Domain object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DomainMutation) OldBusinessID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldBusinessID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldBusinessID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldBusinessID: %w", err) } return oldValue.BusinessID, nil } // ClearBusinessID clears the value of the "business_id" field. func (m *DomainMutation) ClearBusinessID() { m.businesses = nil m.clearedFields[domain.FieldBusinessID] = struct{}{} } // BusinessIDCleared returns if the "business_id" field was cleared in this mutation. func (m *DomainMutation) BusinessIDCleared() bool { _, ok := m.clearedFields[domain.FieldBusinessID] return ok } // ResetBusinessID resets all changes to the "business_id" field. func (m *DomainMutation) ResetBusinessID() { m.businesses = nil delete(m.clearedFields, domain.FieldBusinessID) } // SetUserID sets the "user_id" field. func (m *DomainMutation) SetUserID(i int) { m.users = &i } // UserID returns the value of the "user_id" field in the mutation. func (m *DomainMutation) UserID() (r int, exists bool) { v := m.users if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the Domain entity. // If the Domain object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DomainMutation) OldUserID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ClearUserID clears the value of the "user_id" field. func (m *DomainMutation) ClearUserID() { m.users = nil m.clearedFields[domain.FieldUserID] = struct{}{} } // UserIDCleared returns if the "user_id" field was cleared in this mutation. func (m *DomainMutation) UserIDCleared() bool { _, ok := m.clearedFields[domain.FieldUserID] return ok } // ResetUserID resets all changes to the "user_id" field. func (m *DomainMutation) ResetUserID() { m.users = nil delete(m.clearedFields, domain.FieldUserID) } // SetConfig sets the "config" field. func (m *DomainMutation) SetConfig(s []string) { m._config = &s m.append_config = nil } // Config returns the value of the "config" field in the mutation. func (m *DomainMutation) Config() (r []string, exists bool) { v := m._config if v == nil { return } return *v, true } // OldConfig returns the old "config" field's value of the Domain entity. // If the Domain object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DomainMutation) OldConfig(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldConfig is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldConfig requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldConfig: %w", err) } return oldValue.Config, nil } // AppendConfig adds s to the "config" field. func (m *DomainMutation) AppendConfig(s []string) { m.append_config = append(m.append_config, s...) } // AppendedConfig returns the list of values that were appended to the "config" field in this mutation. func (m *DomainMutation) AppendedConfig() ([]string, bool) { if len(m.append_config) == 0 { return nil, false } return m.append_config, true } // ClearConfig clears the value of the "config" field. func (m *DomainMutation) ClearConfig() { m._config = nil m.append_config = nil m.clearedFields[domain.FieldConfig] = struct{}{} } // ConfigCleared returns if the "config" field was cleared in this mutation. func (m *DomainMutation) ConfigCleared() bool { _, ok := m.clearedFields[domain.FieldConfig] return ok } // ResetConfig resets all changes to the "config" field. func (m *DomainMutation) ResetConfig() { m._config = nil m.append_config = nil delete(m.clearedFields, domain.FieldConfig) } // SetCreatedAt sets the "created_at" field. func (m *DomainMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *DomainMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Domain entity. // If the Domain object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DomainMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ResetCreatedAt resets all changes to the "created_at" field. func (m *DomainMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *DomainMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *DomainMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Domain entity. // If the Domain object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DomainMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *DomainMutation) ResetUpdatedAt() { m.updated_at = nil } // SetBusinessesID sets the "businesses" edge to the Business entity by id. func (m *DomainMutation) SetBusinessesID(id int) { m.businesses = &id } // ClearBusinesses clears the "businesses" edge to the Business entity. func (m *DomainMutation) ClearBusinesses() { m.clearedbusinesses = true m.clearedFields[domain.FieldBusinessID] = struct{}{} } // BusinessesCleared reports if the "businesses" edge to the Business entity was cleared. func (m *DomainMutation) BusinessesCleared() bool { return m.BusinessIDCleared() || m.clearedbusinesses } // BusinessesID returns the "businesses" edge ID in the mutation. func (m *DomainMutation) BusinessesID() (id int, exists bool) { if m.businesses != nil { return *m.businesses, true } return } // BusinessesIDs returns the "businesses" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // BusinessesID instead. It exists only for internal usage by the builders. func (m *DomainMutation) BusinessesIDs() (ids []int) { if id := m.businesses; id != nil { ids = append(ids, *id) } return } // ResetBusinesses resets all changes to the "businesses" edge. func (m *DomainMutation) ResetBusinesses() { m.businesses = nil m.clearedbusinesses = false } // SetUsersID sets the "users" edge to the User entity by id. func (m *DomainMutation) SetUsersID(id int) { m.users = &id } // ClearUsers clears the "users" edge to the User entity. func (m *DomainMutation) ClearUsers() { m.clearedusers = true m.clearedFields[domain.FieldUserID] = struct{}{} } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *DomainMutation) UsersCleared() bool { return m.UserIDCleared() || m.clearedusers } // UsersID returns the "users" edge ID in the mutation. func (m *DomainMutation) UsersID() (id int, exists bool) { if m.users != nil { return *m.users, true } return } // UsersIDs returns the "users" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UsersID instead. It exists only for internal usage by the builders. func (m *DomainMutation) UsersIDs() (ids []int) { if id := m.users; id != nil { ids = append(ids, *id) } return } // ResetUsers resets all changes to the "users" edge. func (m *DomainMutation) ResetUsers() { m.users = nil m.clearedusers = false } // Where appends a list predicates to the DomainMutation builder. func (m *DomainMutation) Where(ps ...predicate.Domain) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DomainMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DomainMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Domain, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DomainMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DomainMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Domain). func (m *DomainMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *DomainMutation) Fields() []string { fields := make([]string, 0, 6) if m.domain != nil { fields = append(fields, domain.FieldDomain) } if m.businesses != nil { fields = append(fields, domain.FieldBusinessID) } if m.users != nil { fields = append(fields, domain.FieldUserID) } if m._config != nil { fields = append(fields, domain.FieldConfig) } if m.created_at != nil { fields = append(fields, domain.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, domain.FieldUpdatedAt) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *DomainMutation) Field(name string) (ent.Value, bool) { switch name { case domain.FieldDomain: return m.Domain() case domain.FieldBusinessID: return m.BusinessID() case domain.FieldUserID: return m.UserID() case domain.FieldConfig: return m.Config() case domain.FieldCreatedAt: return m.CreatedAt() case domain.FieldUpdatedAt: return m.UpdatedAt() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *DomainMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case domain.FieldDomain: return m.OldDomain(ctx) case domain.FieldBusinessID: return m.OldBusinessID(ctx) case domain.FieldUserID: return m.OldUserID(ctx) case domain.FieldConfig: return m.OldConfig(ctx) case domain.FieldCreatedAt: return m.OldCreatedAt(ctx) case domain.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Domain field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *DomainMutation) SetField(name string, value ent.Value) error { switch name { case domain.FieldDomain: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDomain(v) return nil case domain.FieldBusinessID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBusinessID(v) return nil case domain.FieldUserID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case domain.FieldConfig: v, ok := value.([]string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetConfig(v) return nil case domain.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case domain.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Domain field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DomainMutation) AddedFields() []string { var fields []string return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *DomainMutation) AddedField(name string) (ent.Value, bool) { switch name { } return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *DomainMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Domain numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DomainMutation) ClearedFields() []string { var fields []string if m.FieldCleared(domain.FieldBusinessID) { fields = append(fields, domain.FieldBusinessID) } if m.FieldCleared(domain.FieldUserID) { fields = append(fields, domain.FieldUserID) } if m.FieldCleared(domain.FieldConfig) { fields = append(fields, domain.FieldConfig) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DomainMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *DomainMutation) ClearField(name string) error { switch name { case domain.FieldBusinessID: m.ClearBusinessID() return nil case domain.FieldUserID: m.ClearUserID() return nil case domain.FieldConfig: m.ClearConfig() return nil } return fmt.Errorf("unknown Domain nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *DomainMutation) ResetField(name string) error { switch name { case domain.FieldDomain: m.ResetDomain() return nil case domain.FieldBusinessID: m.ResetBusinessID() return nil case domain.FieldUserID: m.ResetUserID() return nil case domain.FieldConfig: m.ResetConfig() return nil case domain.FieldCreatedAt: m.ResetCreatedAt() return nil case domain.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Domain field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DomainMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.businesses != nil { edges = append(edges, domain.EdgeBusinesses) } if m.users != nil { edges = append(edges, domain.EdgeUsers) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DomainMutation) AddedIDs(name string) []ent.Value { switch name { case domain.EdgeBusinesses: if id := m.businesses; id != nil { return []ent.Value{*id} } case domain.EdgeUsers: if id := m.users; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DomainMutation) RemovedEdges() []string { edges := make([]string, 0, 2) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *DomainMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DomainMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedbusinesses { edges = append(edges, domain.EdgeBusinesses) } if m.clearedusers { edges = append(edges, domain.EdgeUsers) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DomainMutation) EdgeCleared(name string) bool { switch name { case domain.EdgeBusinesses: return m.clearedbusinesses case domain.EdgeUsers: return m.clearedusers } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *DomainMutation) ClearEdge(name string) error { switch name { case domain.EdgeBusinesses: m.ClearBusinesses() return nil case domain.EdgeUsers: m.ClearUsers() return nil } return fmt.Errorf("unknown Domain unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *DomainMutation) ResetEdge(name string) error { switch name { case domain.EdgeBusinesses: m.ResetBusinesses() return nil case domain.EdgeUsers: m.ResetUsers() return nil } return fmt.Errorf("unknown Domain edge %s", name) } // ProductMutation represents an operation that mutates the Product nodes in the graph. type ProductMutation struct { config op Op typ string id *int name *string summary *string description *string price *float64 addprice *float64 original_price *float64 addoriginal_price *float64 quantity *int addquantity *int status *bool created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} product_categories *int clearedproduct_categories bool businesses *int clearedbusinesses bool users *int clearedusers bool done bool oldValue func(context.Context) (*Product, error) predicates []predicate.Product } var _ ent.Mutation = (*ProductMutation)(nil) // productOption allows management of the mutation configuration using functional options. type productOption func(*ProductMutation) // newProductMutation creates new mutation for the Product entity. func newProductMutation(c config, op Op, opts ...productOption) *ProductMutation { m := &ProductMutation{ config: c, op: op, typ: TypeProduct, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withProductID sets the ID field of the mutation. func withProductID(id int) productOption { return func(m *ProductMutation) { var ( err error once sync.Once value *Product ) m.oldValue = func(ctx context.Context) (*Product, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Product.Get(ctx, id) } }) return value, err } m.id = &id } } // withProduct sets the old Product of the mutation. func withProduct(node *Product) productOption { return func(m *ProductMutation) { m.oldValue = func(context.Context) (*Product, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m ProductMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m ProductMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *ProductMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *ProductMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Product.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *ProductMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *ProductMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *ProductMutation) ResetName() { m.name = nil } // SetSummary sets the "summary" field. func (m *ProductMutation) SetSummary(s string) { m.summary = &s } // Summary returns the value of the "summary" field in the mutation. func (m *ProductMutation) Summary() (r string, exists bool) { v := m.summary if v == nil { return } return *v, true } // OldSummary returns the old "summary" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldSummary(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSummary is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSummary requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSummary: %w", err) } return oldValue.Summary, nil } // ClearSummary clears the value of the "summary" field. func (m *ProductMutation) ClearSummary() { m.summary = nil m.clearedFields[product.FieldSummary] = struct{}{} } // SummaryCleared returns if the "summary" field was cleared in this mutation. func (m *ProductMutation) SummaryCleared() bool { _, ok := m.clearedFields[product.FieldSummary] return ok } // ResetSummary resets all changes to the "summary" field. func (m *ProductMutation) ResetSummary() { m.summary = nil delete(m.clearedFields, product.FieldSummary) } // SetDescription sets the "description" field. func (m *ProductMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *ProductMutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // OldDescription returns the old "description" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldDescription(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ClearDescription clears the value of the "description" field. func (m *ProductMutation) ClearDescription() { m.description = nil m.clearedFields[product.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *ProductMutation) DescriptionCleared() bool { _, ok := m.clearedFields[product.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *ProductMutation) ResetDescription() { m.description = nil delete(m.clearedFields, product.FieldDescription) } // SetPrice sets the "price" field. func (m *ProductMutation) SetPrice(f float64) { m.price = &f m.addprice = nil } // Price returns the value of the "price" field in the mutation. func (m *ProductMutation) Price() (r float64, exists bool) { v := m.price if v == nil { return } return *v, true } // OldPrice returns the old "price" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldPrice(ctx context.Context) (v float64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPrice is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPrice requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPrice: %w", err) } return oldValue.Price, nil } // AddPrice adds f to the "price" field. func (m *ProductMutation) AddPrice(f float64) { if m.addprice != nil { *m.addprice += f } else { m.addprice = &f } } // AddedPrice returns the value that was added to the "price" field in this mutation. func (m *ProductMutation) AddedPrice() (r float64, exists bool) { v := m.addprice if v == nil { return } return *v, true } // ResetPrice resets all changes to the "price" field. func (m *ProductMutation) ResetPrice() { m.price = nil m.addprice = nil } // SetOriginalPrice sets the "original_price" field. func (m *ProductMutation) SetOriginalPrice(f float64) { m.original_price = &f m.addoriginal_price = nil } // OriginalPrice returns the value of the "original_price" field in the mutation. func (m *ProductMutation) OriginalPrice() (r float64, exists bool) { v := m.original_price if v == nil { return } return *v, true } // OldOriginalPrice returns the old "original_price" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldOriginalPrice(ctx context.Context) (v float64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldOriginalPrice is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldOriginalPrice requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldOriginalPrice: %w", err) } return oldValue.OriginalPrice, nil } // AddOriginalPrice adds f to the "original_price" field. func (m *ProductMutation) AddOriginalPrice(f float64) { if m.addoriginal_price != nil { *m.addoriginal_price += f } else { m.addoriginal_price = &f } } // AddedOriginalPrice returns the value that was added to the "original_price" field in this mutation. func (m *ProductMutation) AddedOriginalPrice() (r float64, exists bool) { v := m.addoriginal_price if v == nil { return } return *v, true } // ResetOriginalPrice resets all changes to the "original_price" field. func (m *ProductMutation) ResetOriginalPrice() { m.original_price = nil m.addoriginal_price = nil } // SetQuantity sets the "quantity" field. func (m *ProductMutation) SetQuantity(i int) { m.quantity = &i m.addquantity = nil } // Quantity returns the value of the "quantity" field in the mutation. func (m *ProductMutation) Quantity() (r int, exists bool) { v := m.quantity if v == nil { return } return *v, true } // OldQuantity returns the old "quantity" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldQuantity(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldQuantity is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldQuantity requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldQuantity: %w", err) } return oldValue.Quantity, nil } // AddQuantity adds i to the "quantity" field. func (m *ProductMutation) AddQuantity(i int) { if m.addquantity != nil { *m.addquantity += i } else { m.addquantity = &i } } // AddedQuantity returns the value that was added to the "quantity" field in this mutation. func (m *ProductMutation) AddedQuantity() (r int, exists bool) { v := m.addquantity if v == nil { return } return *v, true } // ResetQuantity resets all changes to the "quantity" field. func (m *ProductMutation) ResetQuantity() { m.quantity = nil m.addquantity = nil } // SetStatus sets the "status" field. func (m *ProductMutation) SetStatus(b bool) { m.status = &b } // Status returns the value of the "status" field in the mutation. func (m *ProductMutation) Status() (r bool, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldStatus(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ResetStatus resets all changes to the "status" field. func (m *ProductMutation) ResetStatus() { m.status = nil } // SetProductCategoryID sets the "product_category_id" field. func (m *ProductMutation) SetProductCategoryID(i int) { m.product_categories = &i } // ProductCategoryID returns the value of the "product_category_id" field in the mutation. func (m *ProductMutation) ProductCategoryID() (r int, exists bool) { v := m.product_categories if v == nil { return } return *v, true } // OldProductCategoryID returns the old "product_category_id" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldProductCategoryID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldProductCategoryID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldProductCategoryID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldProductCategoryID: %w", err) } return oldValue.ProductCategoryID, nil } // ClearProductCategoryID clears the value of the "product_category_id" field. func (m *ProductMutation) ClearProductCategoryID() { m.product_categories = nil m.clearedFields[product.FieldProductCategoryID] = struct{}{} } // ProductCategoryIDCleared returns if the "product_category_id" field was cleared in this mutation. func (m *ProductMutation) ProductCategoryIDCleared() bool { _, ok := m.clearedFields[product.FieldProductCategoryID] return ok } // ResetProductCategoryID resets all changes to the "product_category_id" field. func (m *ProductMutation) ResetProductCategoryID() { m.product_categories = nil delete(m.clearedFields, product.FieldProductCategoryID) } // SetBusinessID sets the "business_id" field. func (m *ProductMutation) SetBusinessID(i int) { m.businesses = &i } // BusinessID returns the value of the "business_id" field in the mutation. func (m *ProductMutation) BusinessID() (r int, exists bool) { v := m.businesses if v == nil { return } return *v, true } // OldBusinessID returns the old "business_id" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldBusinessID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldBusinessID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldBusinessID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldBusinessID: %w", err) } return oldValue.BusinessID, nil } // ClearBusinessID clears the value of the "business_id" field. func (m *ProductMutation) ClearBusinessID() { m.businesses = nil m.clearedFields[product.FieldBusinessID] = struct{}{} } // BusinessIDCleared returns if the "business_id" field was cleared in this mutation. func (m *ProductMutation) BusinessIDCleared() bool { _, ok := m.clearedFields[product.FieldBusinessID] return ok } // ResetBusinessID resets all changes to the "business_id" field. func (m *ProductMutation) ResetBusinessID() { m.businesses = nil delete(m.clearedFields, product.FieldBusinessID) } // SetUserID sets the "user_id" field. func (m *ProductMutation) SetUserID(i int) { m.users = &i } // UserID returns the value of the "user_id" field in the mutation. func (m *ProductMutation) UserID() (r int, exists bool) { v := m.users if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldUserID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ClearUserID clears the value of the "user_id" field. func (m *ProductMutation) ClearUserID() { m.users = nil m.clearedFields[product.FieldUserID] = struct{}{} } // UserIDCleared returns if the "user_id" field was cleared in this mutation. func (m *ProductMutation) UserIDCleared() bool { _, ok := m.clearedFields[product.FieldUserID] return ok } // ResetUserID resets all changes to the "user_id" field. func (m *ProductMutation) ResetUserID() { m.users = nil delete(m.clearedFields, product.FieldUserID) } // SetCreatedAt sets the "created_at" field. func (m *ProductMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *ProductMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ResetCreatedAt resets all changes to the "created_at" field. func (m *ProductMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *ProductMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *ProductMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Product entity. // If the Product object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *ProductMutation) ResetUpdatedAt() { m.updated_at = nil } // SetProductCategoriesID sets the "product_categories" edge to the ProductCategory entity by id. func (m *ProductMutation) SetProductCategoriesID(id int) { m.product_categories = &id } // ClearProductCategories clears the "product_categories" edge to the ProductCategory entity. func (m *ProductMutation) ClearProductCategories() { m.clearedproduct_categories = true m.clearedFields[product.FieldProductCategoryID] = struct{}{} } // ProductCategoriesCleared reports if the "product_categories" edge to the ProductCategory entity was cleared. func (m *ProductMutation) ProductCategoriesCleared() bool { return m.ProductCategoryIDCleared() || m.clearedproduct_categories } // ProductCategoriesID returns the "product_categories" edge ID in the mutation. func (m *ProductMutation) ProductCategoriesID() (id int, exists bool) { if m.product_categories != nil { return *m.product_categories, true } return } // ProductCategoriesIDs returns the "product_categories" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // ProductCategoriesID instead. It exists only for internal usage by the builders. func (m *ProductMutation) ProductCategoriesIDs() (ids []int) { if id := m.product_categories; id != nil { ids = append(ids, *id) } return } // ResetProductCategories resets all changes to the "product_categories" edge. func (m *ProductMutation) ResetProductCategories() { m.product_categories = nil m.clearedproduct_categories = false } // SetBusinessesID sets the "businesses" edge to the Business entity by id. func (m *ProductMutation) SetBusinessesID(id int) { m.businesses = &id } // ClearBusinesses clears the "businesses" edge to the Business entity. func (m *ProductMutation) ClearBusinesses() { m.clearedbusinesses = true m.clearedFields[product.FieldBusinessID] = struct{}{} } // BusinessesCleared reports if the "businesses" edge to the Business entity was cleared. func (m *ProductMutation) BusinessesCleared() bool { return m.BusinessIDCleared() || m.clearedbusinesses } // BusinessesID returns the "businesses" edge ID in the mutation. func (m *ProductMutation) BusinessesID() (id int, exists bool) { if m.businesses != nil { return *m.businesses, true } return } // BusinessesIDs returns the "businesses" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // BusinessesID instead. It exists only for internal usage by the builders. func (m *ProductMutation) BusinessesIDs() (ids []int) { if id := m.businesses; id != nil { ids = append(ids, *id) } return } // ResetBusinesses resets all changes to the "businesses" edge. func (m *ProductMutation) ResetBusinesses() { m.businesses = nil m.clearedbusinesses = false } // SetUsersID sets the "users" edge to the User entity by id. func (m *ProductMutation) SetUsersID(id int) { m.users = &id } // ClearUsers clears the "users" edge to the User entity. func (m *ProductMutation) ClearUsers() { m.clearedusers = true m.clearedFields[product.FieldUserID] = struct{}{} } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *ProductMutation) UsersCleared() bool { return m.UserIDCleared() || m.clearedusers } // UsersID returns the "users" edge ID in the mutation. func (m *ProductMutation) UsersID() (id int, exists bool) { if m.users != nil { return *m.users, true } return } // UsersIDs returns the "users" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UsersID instead. It exists only for internal usage by the builders. func (m *ProductMutation) UsersIDs() (ids []int) { if id := m.users; id != nil { ids = append(ids, *id) } return } // ResetUsers resets all changes to the "users" edge. func (m *ProductMutation) ResetUsers() { m.users = nil m.clearedusers = false } // Where appends a list predicates to the ProductMutation builder. func (m *ProductMutation) Where(ps ...predicate.Product) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ProductMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ProductMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Product, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ProductMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ProductMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Product). func (m *ProductMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ProductMutation) Fields() []string { fields := make([]string, 0, 12) if m.name != nil { fields = append(fields, product.FieldName) } if m.summary != nil { fields = append(fields, product.FieldSummary) } if m.description != nil { fields = append(fields, product.FieldDescription) } if m.price != nil { fields = append(fields, product.FieldPrice) } if m.original_price != nil { fields = append(fields, product.FieldOriginalPrice) } if m.quantity != nil { fields = append(fields, product.FieldQuantity) } if m.status != nil { fields = append(fields, product.FieldStatus) } if m.product_categories != nil { fields = append(fields, product.FieldProductCategoryID) } if m.businesses != nil { fields = append(fields, product.FieldBusinessID) } if m.users != nil { fields = append(fields, product.FieldUserID) } if m.created_at != nil { fields = append(fields, product.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, product.FieldUpdatedAt) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *ProductMutation) Field(name string) (ent.Value, bool) { switch name { case product.FieldName: return m.Name() case product.FieldSummary: return m.Summary() case product.FieldDescription: return m.Description() case product.FieldPrice: return m.Price() case product.FieldOriginalPrice: return m.OriginalPrice() case product.FieldQuantity: return m.Quantity() case product.FieldStatus: return m.Status() case product.FieldProductCategoryID: return m.ProductCategoryID() case product.FieldBusinessID: return m.BusinessID() case product.FieldUserID: return m.UserID() case product.FieldCreatedAt: return m.CreatedAt() case product.FieldUpdatedAt: return m.UpdatedAt() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *ProductMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case product.FieldName: return m.OldName(ctx) case product.FieldSummary: return m.OldSummary(ctx) case product.FieldDescription: return m.OldDescription(ctx) case product.FieldPrice: return m.OldPrice(ctx) case product.FieldOriginalPrice: return m.OldOriginalPrice(ctx) case product.FieldQuantity: return m.OldQuantity(ctx) case product.FieldStatus: return m.OldStatus(ctx) case product.FieldProductCategoryID: return m.OldProductCategoryID(ctx) case product.FieldBusinessID: return m.OldBusinessID(ctx) case product.FieldUserID: return m.OldUserID(ctx) case product.FieldCreatedAt: return m.OldCreatedAt(ctx) case product.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Product field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *ProductMutation) SetField(name string, value ent.Value) error { switch name { case product.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case product.FieldSummary: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSummary(v) return nil case product.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case product.FieldPrice: v, ok := value.(float64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPrice(v) return nil case product.FieldOriginalPrice: v, ok := value.(float64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOriginalPrice(v) return nil case product.FieldQuantity: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetQuantity(v) return nil case product.FieldStatus: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case product.FieldProductCategoryID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProductCategoryID(v) return nil case product.FieldBusinessID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBusinessID(v) return nil case product.FieldUserID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case product.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case product.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Product field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ProductMutation) AddedFields() []string { var fields []string if m.addprice != nil { fields = append(fields, product.FieldPrice) } if m.addoriginal_price != nil { fields = append(fields, product.FieldOriginalPrice) } if m.addquantity != nil { fields = append(fields, product.FieldQuantity) } return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *ProductMutation) AddedField(name string) (ent.Value, bool) { switch name { case product.FieldPrice: return m.AddedPrice() case product.FieldOriginalPrice: return m.AddedOriginalPrice() case product.FieldQuantity: return m.AddedQuantity() } return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *ProductMutation) AddField(name string, value ent.Value) error { switch name { case product.FieldPrice: v, ok := value.(float64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddPrice(v) return nil case product.FieldOriginalPrice: v, ok := value.(float64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddOriginalPrice(v) return nil case product.FieldQuantity: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddQuantity(v) return nil } return fmt.Errorf("unknown Product numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ProductMutation) ClearedFields() []string { var fields []string if m.FieldCleared(product.FieldSummary) { fields = append(fields, product.FieldSummary) } if m.FieldCleared(product.FieldDescription) { fields = append(fields, product.FieldDescription) } if m.FieldCleared(product.FieldProductCategoryID) { fields = append(fields, product.FieldProductCategoryID) } if m.FieldCleared(product.FieldBusinessID) { fields = append(fields, product.FieldBusinessID) } if m.FieldCleared(product.FieldUserID) { fields = append(fields, product.FieldUserID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ProductMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *ProductMutation) ClearField(name string) error { switch name { case product.FieldSummary: m.ClearSummary() return nil case product.FieldDescription: m.ClearDescription() return nil case product.FieldProductCategoryID: m.ClearProductCategoryID() return nil case product.FieldBusinessID: m.ClearBusinessID() return nil case product.FieldUserID: m.ClearUserID() return nil } return fmt.Errorf("unknown Product nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *ProductMutation) ResetField(name string) error { switch name { case product.FieldName: m.ResetName() return nil case product.FieldSummary: m.ResetSummary() return nil case product.FieldDescription: m.ResetDescription() return nil case product.FieldPrice: m.ResetPrice() return nil case product.FieldOriginalPrice: m.ResetOriginalPrice() return nil case product.FieldQuantity: m.ResetQuantity() return nil case product.FieldStatus: m.ResetStatus() return nil case product.FieldProductCategoryID: m.ResetProductCategoryID() return nil case product.FieldBusinessID: m.ResetBusinessID() return nil case product.FieldUserID: m.ResetUserID() return nil case product.FieldCreatedAt: m.ResetCreatedAt() return nil case product.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Product field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ProductMutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.product_categories != nil { edges = append(edges, product.EdgeProductCategories) } if m.businesses != nil { edges = append(edges, product.EdgeBusinesses) } if m.users != nil { edges = append(edges, product.EdgeUsers) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ProductMutation) AddedIDs(name string) []ent.Value { switch name { case product.EdgeProductCategories: if id := m.product_categories; id != nil { return []ent.Value{*id} } case product.EdgeBusinesses: if id := m.businesses; id != nil { return []ent.Value{*id} } case product.EdgeUsers: if id := m.users; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ProductMutation) RemovedEdges() []string { edges := make([]string, 0, 3) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *ProductMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ProductMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedproduct_categories { edges = append(edges, product.EdgeProductCategories) } if m.clearedbusinesses { edges = append(edges, product.EdgeBusinesses) } if m.clearedusers { edges = append(edges, product.EdgeUsers) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ProductMutation) EdgeCleared(name string) bool { switch name { case product.EdgeProductCategories: return m.clearedproduct_categories case product.EdgeBusinesses: return m.clearedbusinesses case product.EdgeUsers: return m.clearedusers } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *ProductMutation) ClearEdge(name string) error { switch name { case product.EdgeProductCategories: m.ClearProductCategories() return nil case product.EdgeBusinesses: m.ClearBusinesses() return nil case product.EdgeUsers: m.ClearUsers() return nil } return fmt.Errorf("unknown Product unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *ProductMutation) ResetEdge(name string) error { switch name { case product.EdgeProductCategories: m.ResetProductCategories() return nil case product.EdgeBusinesses: m.ResetBusinesses() return nil case product.EdgeUsers: m.ResetUsers() return nil } return fmt.Errorf("unknown Product edge %s", name) } // ProductCategoryMutation represents an operation that mutates the ProductCategory nodes in the graph. type ProductCategoryMutation struct { config op Op typ string id *int name *string slug *string description *string status *bool created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} products map[int]struct{} removedproducts map[int]struct{} clearedproducts bool businesses *int clearedbusinesses bool done bool oldValue func(context.Context) (*ProductCategory, error) predicates []predicate.ProductCategory } var _ ent.Mutation = (*ProductCategoryMutation)(nil) // productcategoryOption allows management of the mutation configuration using functional options. type productcategoryOption func(*ProductCategoryMutation) // newProductCategoryMutation creates new mutation for the ProductCategory entity. func newProductCategoryMutation(c config, op Op, opts ...productcategoryOption) *ProductCategoryMutation { m := &ProductCategoryMutation{ config: c, op: op, typ: TypeProductCategory, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withProductCategoryID sets the ID field of the mutation. func withProductCategoryID(id int) productcategoryOption { return func(m *ProductCategoryMutation) { var ( err error once sync.Once value *ProductCategory ) m.oldValue = func(ctx context.Context) (*ProductCategory, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().ProductCategory.Get(ctx, id) } }) return value, err } m.id = &id } } // withProductCategory sets the old ProductCategory of the mutation. func withProductCategory(node *ProductCategory) productcategoryOption { return func(m *ProductCategoryMutation) { m.oldValue = func(context.Context) (*ProductCategory, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m ProductCategoryMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m ProductCategoryMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *ProductCategoryMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *ProductCategoryMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().ProductCategory.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *ProductCategoryMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *ProductCategoryMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the ProductCategory entity. // If the ProductCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductCategoryMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *ProductCategoryMutation) ResetName() { m.name = nil } // SetSlug sets the "slug" field. func (m *ProductCategoryMutation) SetSlug(s string) { m.slug = &s } // Slug returns the value of the "slug" field in the mutation. func (m *ProductCategoryMutation) Slug() (r string, exists bool) { v := m.slug if v == nil { return } return *v, true } // OldSlug returns the old "slug" field's value of the ProductCategory entity. // If the ProductCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductCategoryMutation) OldSlug(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSlug is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSlug requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSlug: %w", err) } return oldValue.Slug, nil } // ResetSlug resets all changes to the "slug" field. func (m *ProductCategoryMutation) ResetSlug() { m.slug = nil } // SetDescription sets the "description" field. func (m *ProductCategoryMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *ProductCategoryMutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // OldDescription returns the old "description" field's value of the ProductCategory entity. // If the ProductCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductCategoryMutation) OldDescription(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ClearDescription clears the value of the "description" field. func (m *ProductCategoryMutation) ClearDescription() { m.description = nil m.clearedFields[productcategory.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *ProductCategoryMutation) DescriptionCleared() bool { _, ok := m.clearedFields[productcategory.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *ProductCategoryMutation) ResetDescription() { m.description = nil delete(m.clearedFields, productcategory.FieldDescription) } // SetStatus sets the "status" field. func (m *ProductCategoryMutation) SetStatus(b bool) { m.status = &b } // Status returns the value of the "status" field in the mutation. func (m *ProductCategoryMutation) Status() (r bool, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the ProductCategory entity. // If the ProductCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductCategoryMutation) OldStatus(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ResetStatus resets all changes to the "status" field. func (m *ProductCategoryMutation) ResetStatus() { m.status = nil } // SetBusinessID sets the "business_id" field. func (m *ProductCategoryMutation) SetBusinessID(i int) { m.businesses = &i } // BusinessID returns the value of the "business_id" field in the mutation. func (m *ProductCategoryMutation) BusinessID() (r int, exists bool) { v := m.businesses if v == nil { return } return *v, true } // OldBusinessID returns the old "business_id" field's value of the ProductCategory entity. // If the ProductCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductCategoryMutation) OldBusinessID(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldBusinessID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldBusinessID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldBusinessID: %w", err) } return oldValue.BusinessID, nil } // ClearBusinessID clears the value of the "business_id" field. func (m *ProductCategoryMutation) ClearBusinessID() { m.businesses = nil m.clearedFields[productcategory.FieldBusinessID] = struct{}{} } // BusinessIDCleared returns if the "business_id" field was cleared in this mutation. func (m *ProductCategoryMutation) BusinessIDCleared() bool { _, ok := m.clearedFields[productcategory.FieldBusinessID] return ok } // ResetBusinessID resets all changes to the "business_id" field. func (m *ProductCategoryMutation) ResetBusinessID() { m.businesses = nil delete(m.clearedFields, productcategory.FieldBusinessID) } // SetCreatedAt sets the "created_at" field. func (m *ProductCategoryMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *ProductCategoryMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the ProductCategory entity. // If the ProductCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductCategoryMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ResetCreatedAt resets all changes to the "created_at" field. func (m *ProductCategoryMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *ProductCategoryMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *ProductCategoryMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the ProductCategory entity. // If the ProductCategory object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProductCategoryMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *ProductCategoryMutation) ResetUpdatedAt() { m.updated_at = nil } // AddProductIDs adds the "products" edge to the Product entity by ids. func (m *ProductCategoryMutation) AddProductIDs(ids ...int) { if m.products == nil { m.products = make(map[int]struct{}) } for i := range ids { m.products[ids[i]] = struct{}{} } } // ClearProducts clears the "products" edge to the Product entity. func (m *ProductCategoryMutation) ClearProducts() { m.clearedproducts = true } // ProductsCleared reports if the "products" edge to the Product entity was cleared. func (m *ProductCategoryMutation) ProductsCleared() bool { return m.clearedproducts } // RemoveProductIDs removes the "products" edge to the Product entity by IDs. func (m *ProductCategoryMutation) RemoveProductIDs(ids ...int) { if m.removedproducts == nil { m.removedproducts = make(map[int]struct{}) } for i := range ids { delete(m.products, ids[i]) m.removedproducts[ids[i]] = struct{}{} } } // RemovedProducts returns the removed IDs of the "products" edge to the Product entity. func (m *ProductCategoryMutation) RemovedProductsIDs() (ids []int) { for id := range m.removedproducts { ids = append(ids, id) } return } // ProductsIDs returns the "products" edge IDs in the mutation. func (m *ProductCategoryMutation) ProductsIDs() (ids []int) { for id := range m.products { ids = append(ids, id) } return } // ResetProducts resets all changes to the "products" edge. func (m *ProductCategoryMutation) ResetProducts() { m.products = nil m.clearedproducts = false m.removedproducts = nil } // SetBusinessesID sets the "businesses" edge to the Business entity by id. func (m *ProductCategoryMutation) SetBusinessesID(id int) { m.businesses = &id } // ClearBusinesses clears the "businesses" edge to the Business entity. func (m *ProductCategoryMutation) ClearBusinesses() { m.clearedbusinesses = true m.clearedFields[productcategory.FieldBusinessID] = struct{}{} } // BusinessesCleared reports if the "businesses" edge to the Business entity was cleared. func (m *ProductCategoryMutation) BusinessesCleared() bool { return m.BusinessIDCleared() || m.clearedbusinesses } // BusinessesID returns the "businesses" edge ID in the mutation. func (m *ProductCategoryMutation) BusinessesID() (id int, exists bool) { if m.businesses != nil { return *m.businesses, true } return } // BusinessesIDs returns the "businesses" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // BusinessesID instead. It exists only for internal usage by the builders. func (m *ProductCategoryMutation) BusinessesIDs() (ids []int) { if id := m.businesses; id != nil { ids = append(ids, *id) } return } // ResetBusinesses resets all changes to the "businesses" edge. func (m *ProductCategoryMutation) ResetBusinesses() { m.businesses = nil m.clearedbusinesses = false } // Where appends a list predicates to the ProductCategoryMutation builder. func (m *ProductCategoryMutation) Where(ps ...predicate.ProductCategory) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ProductCategoryMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ProductCategoryMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.ProductCategory, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ProductCategoryMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ProductCategoryMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (ProductCategory). func (m *ProductCategoryMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ProductCategoryMutation) Fields() []string { fields := make([]string, 0, 7) if m.name != nil { fields = append(fields, productcategory.FieldName) } if m.slug != nil { fields = append(fields, productcategory.FieldSlug) } if m.description != nil { fields = append(fields, productcategory.FieldDescription) } if m.status != nil { fields = append(fields, productcategory.FieldStatus) } if m.businesses != nil { fields = append(fields, productcategory.FieldBusinessID) } if m.created_at != nil { fields = append(fields, productcategory.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, productcategory.FieldUpdatedAt) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *ProductCategoryMutation) Field(name string) (ent.Value, bool) { switch name { case productcategory.FieldName: return m.Name() case productcategory.FieldSlug: return m.Slug() case productcategory.FieldDescription: return m.Description() case productcategory.FieldStatus: return m.Status() case productcategory.FieldBusinessID: return m.BusinessID() case productcategory.FieldCreatedAt: return m.CreatedAt() case productcategory.FieldUpdatedAt: return m.UpdatedAt() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *ProductCategoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case productcategory.FieldName: return m.OldName(ctx) case productcategory.FieldSlug: return m.OldSlug(ctx) case productcategory.FieldDescription: return m.OldDescription(ctx) case productcategory.FieldStatus: return m.OldStatus(ctx) case productcategory.FieldBusinessID: return m.OldBusinessID(ctx) case productcategory.FieldCreatedAt: return m.OldCreatedAt(ctx) case productcategory.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown ProductCategory field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *ProductCategoryMutation) SetField(name string, value ent.Value) error { switch name { case productcategory.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case productcategory.FieldSlug: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSlug(v) return nil case productcategory.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case productcategory.FieldStatus: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case productcategory.FieldBusinessID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBusinessID(v) return nil case productcategory.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case productcategory.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown ProductCategory field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ProductCategoryMutation) AddedFields() []string { var fields []string return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *ProductCategoryMutation) AddedField(name string) (ent.Value, bool) { switch name { } return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *ProductCategoryMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown ProductCategory numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ProductCategoryMutation) ClearedFields() []string { var fields []string if m.FieldCleared(productcategory.FieldDescription) { fields = append(fields, productcategory.FieldDescription) } if m.FieldCleared(productcategory.FieldBusinessID) { fields = append(fields, productcategory.FieldBusinessID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ProductCategoryMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *ProductCategoryMutation) ClearField(name string) error { switch name { case productcategory.FieldDescription: m.ClearDescription() return nil case productcategory.FieldBusinessID: m.ClearBusinessID() return nil } return fmt.Errorf("unknown ProductCategory nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *ProductCategoryMutation) ResetField(name string) error { switch name { case productcategory.FieldName: m.ResetName() return nil case productcategory.FieldSlug: m.ResetSlug() return nil case productcategory.FieldDescription: m.ResetDescription() return nil case productcategory.FieldStatus: m.ResetStatus() return nil case productcategory.FieldBusinessID: m.ResetBusinessID() return nil case productcategory.FieldCreatedAt: m.ResetCreatedAt() return nil case productcategory.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown ProductCategory field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ProductCategoryMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.products != nil { edges = append(edges, productcategory.EdgeProducts) } if m.businesses != nil { edges = append(edges, productcategory.EdgeBusinesses) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ProductCategoryMutation) AddedIDs(name string) []ent.Value { switch name { case productcategory.EdgeProducts: ids := make([]ent.Value, 0, len(m.products)) for id := range m.products { ids = append(ids, id) } return ids case productcategory.EdgeBusinesses: if id := m.businesses; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ProductCategoryMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedproducts != nil { edges = append(edges, productcategory.EdgeProducts) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *ProductCategoryMutation) RemovedIDs(name string) []ent.Value { switch name { case productcategory.EdgeProducts: ids := make([]ent.Value, 0, len(m.removedproducts)) for id := range m.removedproducts { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ProductCategoryMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedproducts { edges = append(edges, productcategory.EdgeProducts) } if m.clearedbusinesses { edges = append(edges, productcategory.EdgeBusinesses) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ProductCategoryMutation) EdgeCleared(name string) bool { switch name { case productcategory.EdgeProducts: return m.clearedproducts case productcategory.EdgeBusinesses: return m.clearedbusinesses } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *ProductCategoryMutation) ClearEdge(name string) error { switch name { case productcategory.EdgeBusinesses: m.ClearBusinesses() return nil } return fmt.Errorf("unknown ProductCategory unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *ProductCategoryMutation) ResetEdge(name string) error { switch name { case productcategory.EdgeProducts: m.ResetProducts() return nil case productcategory.EdgeBusinesses: m.ResetBusinesses() return nil } return fmt.Errorf("unknown ProductCategory edge %s", name) } // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config op Op typ string id *int email *string cell_phone *string first_name *string last_name *string password *string is_active *bool is_admin *bool created_at *time.Time updated_at *time.Time last_authentication_at *time.Time clearedFields map[string]struct{} products map[int]struct{} removedproducts map[int]struct{} clearedproducts bool domains map[int]struct{} removeddomains map[int]struct{} cleareddomains bool businesses map[int]struct{} removedbusinesses map[int]struct{} clearedbusinesses bool done bool oldValue func(context.Context) (*User, error) predicates []predicate.User } var _ ent.Mutation = (*UserMutation)(nil) // userOption allows management of the mutation configuration using functional options. type userOption func(*UserMutation) // newUserMutation creates new mutation for the User entity. func newUserMutation(c config, op Op, opts ...userOption) *UserMutation { m := &UserMutation{ config: c, op: op, typ: TypeUser, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserID sets the ID field of the mutation. func withUserID(id int) userOption { return func(m *UserMutation) { var ( err error once sync.Once value *User ) m.oldValue = func(ctx context.Context) (*User, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().User.Get(ctx, id) } }) return value, err } m.id = &id } } // withUser sets the old User of the mutation. func withUser(node *User) userOption { return func(m *UserMutation) { m.oldValue = func(context.Context) (*User, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m UserMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m UserMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *UserMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *UserMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().User.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetEmail sets the "email" field. func (m *UserMutation) SetEmail(s string) { m.email = &s } // Email returns the value of the "email" field in the mutation. func (m *UserMutation) Email() (r string, exists bool) { v := m.email if v == nil { return } return *v, true } // OldEmail returns the old "email" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldEmail(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEmail: %w", err) } return oldValue.Email, nil } // ClearEmail clears the value of the "email" field. func (m *UserMutation) ClearEmail() { m.email = nil m.clearedFields[user.FieldEmail] = struct{}{} } // EmailCleared returns if the "email" field was cleared in this mutation. func (m *UserMutation) EmailCleared() bool { _, ok := m.clearedFields[user.FieldEmail] return ok } // ResetEmail resets all changes to the "email" field. func (m *UserMutation) ResetEmail() { m.email = nil delete(m.clearedFields, user.FieldEmail) } // SetCellPhone sets the "cell_phone" field. func (m *UserMutation) SetCellPhone(s string) { m.cell_phone = &s } // CellPhone returns the value of the "cell_phone" field in the mutation. func (m *UserMutation) CellPhone() (r string, exists bool) { v := m.cell_phone if v == nil { return } return *v, true } // OldCellPhone returns the old "cell_phone" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldCellPhone(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCellPhone is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCellPhone requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCellPhone: %w", err) } return oldValue.CellPhone, nil } // ResetCellPhone resets all changes to the "cell_phone" field. func (m *UserMutation) ResetCellPhone() { m.cell_phone = nil } // SetFirstName sets the "first_name" field. func (m *UserMutation) SetFirstName(s string) { m.first_name = &s } // FirstName returns the value of the "first_name" field in the mutation. func (m *UserMutation) FirstName() (r string, exists bool) { v := m.first_name if v == nil { return } return *v, true } // OldFirstName returns the old "first_name" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldFirstName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldFirstName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldFirstName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldFirstName: %w", err) } return oldValue.FirstName, nil } // ResetFirstName resets all changes to the "first_name" field. func (m *UserMutation) ResetFirstName() { m.first_name = nil } // SetLastName sets the "last_name" field. func (m *UserMutation) SetLastName(s string) { m.last_name = &s } // LastName returns the value of the "last_name" field in the mutation. func (m *UserMutation) LastName() (r string, exists bool) { v := m.last_name if v == nil { return } return *v, true } // OldLastName returns the old "last_name" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldLastName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastName: %w", err) } return oldValue.LastName, nil } // ResetLastName resets all changes to the "last_name" field. func (m *UserMutation) ResetLastName() { m.last_name = nil } // SetPassword sets the "password" field. func (m *UserMutation) SetPassword(s string) { m.password = &s } // Password returns the value of the "password" field in the mutation. func (m *UserMutation) Password() (r string, exists bool) { v := m.password if v == nil { return } return *v, true } // OldPassword returns the old "password" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldPassword(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPassword is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPassword requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPassword: %w", err) } return oldValue.Password, nil } // ClearPassword clears the value of the "password" field. func (m *UserMutation) ClearPassword() { m.password = nil m.clearedFields[user.FieldPassword] = struct{}{} } // PasswordCleared returns if the "password" field was cleared in this mutation. func (m *UserMutation) PasswordCleared() bool { _, ok := m.clearedFields[user.FieldPassword] return ok } // ResetPassword resets all changes to the "password" field. func (m *UserMutation) ResetPassword() { m.password = nil delete(m.clearedFields, user.FieldPassword) } // SetIsActive sets the "is_active" field. func (m *UserMutation) SetIsActive(b bool) { m.is_active = &b } // IsActive returns the value of the "is_active" field in the mutation. func (m *UserMutation) IsActive() (r bool, exists bool) { v := m.is_active if v == nil { return } return *v, true } // OldIsActive returns the old "is_active" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldIsActive(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIsActive is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIsActive requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIsActive: %w", err) } return oldValue.IsActive, nil } // ResetIsActive resets all changes to the "is_active" field. func (m *UserMutation) ResetIsActive() { m.is_active = nil } // SetIsAdmin sets the "is_admin" field. func (m *UserMutation) SetIsAdmin(b bool) { m.is_admin = &b } // IsAdmin returns the value of the "is_admin" field in the mutation. func (m *UserMutation) IsAdmin() (r bool, exists bool) { v := m.is_admin if v == nil { return } return *v, true } // OldIsAdmin returns the old "is_admin" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldIsAdmin(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIsAdmin is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIsAdmin requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIsAdmin: %w", err) } return oldValue.IsAdmin, nil } // ResetIsAdmin resets all changes to the "is_admin" field. func (m *UserMutation) ResetIsAdmin() { m.is_admin = nil } // SetCreatedAt sets the "created_at" field. func (m *UserMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *UserMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ResetCreatedAt resets all changes to the "created_at" field. func (m *UserMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *UserMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *UserMutation) ResetUpdatedAt() { m.updated_at = nil } // SetLastAuthenticationAt sets the "last_authentication_at" field. func (m *UserMutation) SetLastAuthenticationAt(t time.Time) { m.last_authentication_at = &t } // LastAuthenticationAt returns the value of the "last_authentication_at" field in the mutation. func (m *UserMutation) LastAuthenticationAt() (r time.Time, exists bool) { v := m.last_authentication_at if v == nil { return } return *v, true } // OldLastAuthenticationAt returns the old "last_authentication_at" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldLastAuthenticationAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastAuthenticationAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastAuthenticationAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastAuthenticationAt: %w", err) } return oldValue.LastAuthenticationAt, nil } // ClearLastAuthenticationAt clears the value of the "last_authentication_at" field. func (m *UserMutation) ClearLastAuthenticationAt() { m.last_authentication_at = nil m.clearedFields[user.FieldLastAuthenticationAt] = struct{}{} } // LastAuthenticationAtCleared returns if the "last_authentication_at" field was cleared in this mutation. func (m *UserMutation) LastAuthenticationAtCleared() bool { _, ok := m.clearedFields[user.FieldLastAuthenticationAt] return ok } // ResetLastAuthenticationAt resets all changes to the "last_authentication_at" field. func (m *UserMutation) ResetLastAuthenticationAt() { m.last_authentication_at = nil delete(m.clearedFields, user.FieldLastAuthenticationAt) } // AddProductIDs adds the "products" edge to the Product entity by ids. func (m *UserMutation) AddProductIDs(ids ...int) { if m.products == nil { m.products = make(map[int]struct{}) } for i := range ids { m.products[ids[i]] = struct{}{} } } // ClearProducts clears the "products" edge to the Product entity. func (m *UserMutation) ClearProducts() { m.clearedproducts = true } // ProductsCleared reports if the "products" edge to the Product entity was cleared. func (m *UserMutation) ProductsCleared() bool { return m.clearedproducts } // RemoveProductIDs removes the "products" edge to the Product entity by IDs. func (m *UserMutation) RemoveProductIDs(ids ...int) { if m.removedproducts == nil { m.removedproducts = make(map[int]struct{}) } for i := range ids { delete(m.products, ids[i]) m.removedproducts[ids[i]] = struct{}{} } } // RemovedProducts returns the removed IDs of the "products" edge to the Product entity. func (m *UserMutation) RemovedProductsIDs() (ids []int) { for id := range m.removedproducts { ids = append(ids, id) } return } // ProductsIDs returns the "products" edge IDs in the mutation. func (m *UserMutation) ProductsIDs() (ids []int) { for id := range m.products { ids = append(ids, id) } return } // ResetProducts resets all changes to the "products" edge. func (m *UserMutation) ResetProducts() { m.products = nil m.clearedproducts = false m.removedproducts = nil } // AddDomainIDs adds the "domains" edge to the Domain entity by ids. func (m *UserMutation) AddDomainIDs(ids ...int) { if m.domains == nil { m.domains = make(map[int]struct{}) } for i := range ids { m.domains[ids[i]] = struct{}{} } } // ClearDomains clears the "domains" edge to the Domain entity. func (m *UserMutation) ClearDomains() { m.cleareddomains = true } // DomainsCleared reports if the "domains" edge to the Domain entity was cleared. func (m *UserMutation) DomainsCleared() bool { return m.cleareddomains } // RemoveDomainIDs removes the "domains" edge to the Domain entity by IDs. func (m *UserMutation) RemoveDomainIDs(ids ...int) { if m.removeddomains == nil { m.removeddomains = make(map[int]struct{}) } for i := range ids { delete(m.domains, ids[i]) m.removeddomains[ids[i]] = struct{}{} } } // RemovedDomains returns the removed IDs of the "domains" edge to the Domain entity. func (m *UserMutation) RemovedDomainsIDs() (ids []int) { for id := range m.removeddomains { ids = append(ids, id) } return } // DomainsIDs returns the "domains" edge IDs in the mutation. func (m *UserMutation) DomainsIDs() (ids []int) { for id := range m.domains { ids = append(ids, id) } return } // ResetDomains resets all changes to the "domains" edge. func (m *UserMutation) ResetDomains() { m.domains = nil m.cleareddomains = false m.removeddomains = nil } // AddBusinessIDs adds the "businesses" edge to the Business entity by ids. func (m *UserMutation) AddBusinessIDs(ids ...int) { if m.businesses == nil { m.businesses = make(map[int]struct{}) } for i := range ids { m.businesses[ids[i]] = struct{}{} } } // ClearBusinesses clears the "businesses" edge to the Business entity. func (m *UserMutation) ClearBusinesses() { m.clearedbusinesses = true } // BusinessesCleared reports if the "businesses" edge to the Business entity was cleared. func (m *UserMutation) BusinessesCleared() bool { return m.clearedbusinesses } // RemoveBusinessIDs removes the "businesses" edge to the Business entity by IDs. func (m *UserMutation) RemoveBusinessIDs(ids ...int) { if m.removedbusinesses == nil { m.removedbusinesses = make(map[int]struct{}) } for i := range ids { delete(m.businesses, ids[i]) m.removedbusinesses[ids[i]] = struct{}{} } } // RemovedBusinesses returns the removed IDs of the "businesses" edge to the Business entity. func (m *UserMutation) RemovedBusinessesIDs() (ids []int) { for id := range m.removedbusinesses { ids = append(ids, id) } return } // BusinessesIDs returns the "businesses" edge IDs in the mutation. func (m *UserMutation) BusinessesIDs() (ids []int) { for id := range m.businesses { ids = append(ids, id) } return } // ResetBusinesses resets all changes to the "businesses" edge. func (m *UserMutation) ResetBusinesses() { m.businesses = nil m.clearedbusinesses = false m.removedbusinesses = nil } // Where appends a list predicates to the UserMutation builder. func (m *UserMutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.User, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { fields := make([]string, 0, 10) if m.email != nil { fields = append(fields, user.FieldEmail) } if m.cell_phone != nil { fields = append(fields, user.FieldCellPhone) } if m.first_name != nil { fields = append(fields, user.FieldFirstName) } if m.last_name != nil { fields = append(fields, user.FieldLastName) } if m.password != nil { fields = append(fields, user.FieldPassword) } if m.is_active != nil { fields = append(fields, user.FieldIsActive) } if m.is_admin != nil { fields = append(fields, user.FieldIsAdmin) } if m.created_at != nil { fields = append(fields, user.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, user.FieldUpdatedAt) } if m.last_authentication_at != nil { fields = append(fields, user.FieldLastAuthenticationAt) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *UserMutation) Field(name string) (ent.Value, bool) { switch name { case user.FieldEmail: return m.Email() case user.FieldCellPhone: return m.CellPhone() case user.FieldFirstName: return m.FirstName() case user.FieldLastName: return m.LastName() case user.FieldPassword: return m.Password() case user.FieldIsActive: return m.IsActive() case user.FieldIsAdmin: return m.IsAdmin() case user.FieldCreatedAt: return m.CreatedAt() case user.FieldUpdatedAt: return m.UpdatedAt() case user.FieldLastAuthenticationAt: return m.LastAuthenticationAt() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case user.FieldEmail: return m.OldEmail(ctx) case user.FieldCellPhone: return m.OldCellPhone(ctx) case user.FieldFirstName: return m.OldFirstName(ctx) case user.FieldLastName: return m.OldLastName(ctx) case user.FieldPassword: return m.OldPassword(ctx) case user.FieldIsActive: return m.OldIsActive(ctx) case user.FieldIsAdmin: return m.OldIsAdmin(ctx) case user.FieldCreatedAt: return m.OldCreatedAt(ctx) case user.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case user.FieldLastAuthenticationAt: return m.OldLastAuthenticationAt(ctx) } return nil, fmt.Errorf("unknown User field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *UserMutation) SetField(name string, value ent.Value) error { switch name { case user.FieldEmail: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEmail(v) return nil case user.FieldCellPhone: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCellPhone(v) return nil case user.FieldFirstName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetFirstName(v) return nil case user.FieldLastName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastName(v) return nil case user.FieldPassword: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPassword(v) return nil case user.FieldIsActive: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIsActive(v) return nil case user.FieldIsAdmin: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIsAdmin(v) return nil case user.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case user.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil case user.FieldLastAuthenticationAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastAuthenticationAt(v) return nil } return fmt.Errorf("unknown User field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *UserMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *UserMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown User numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserMutation) ClearedFields() []string { var fields []string if m.FieldCleared(user.FieldEmail) { fields = append(fields, user.FieldEmail) } if m.FieldCleared(user.FieldPassword) { fields = append(fields, user.FieldPassword) } if m.FieldCleared(user.FieldLastAuthenticationAt) { fields = append(fields, user.FieldLastAuthenticationAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *UserMutation) ClearField(name string) error { switch name { case user.FieldEmail: m.ClearEmail() return nil case user.FieldPassword: m.ClearPassword() return nil case user.FieldLastAuthenticationAt: m.ClearLastAuthenticationAt() return nil } return fmt.Errorf("unknown User nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *UserMutation) ResetField(name string) error { switch name { case user.FieldEmail: m.ResetEmail() return nil case user.FieldCellPhone: m.ResetCellPhone() return nil case user.FieldFirstName: m.ResetFirstName() return nil case user.FieldLastName: m.ResetLastName() return nil case user.FieldPassword: m.ResetPassword() return nil case user.FieldIsActive: m.ResetIsActive() return nil case user.FieldIsAdmin: m.ResetIsAdmin() return nil case user.FieldCreatedAt: m.ResetCreatedAt() return nil case user.FieldUpdatedAt: m.ResetUpdatedAt() return nil case user.FieldLastAuthenticationAt: m.ResetLastAuthenticationAt() return nil } return fmt.Errorf("unknown User field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserMutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.products != nil { edges = append(edges, user.EdgeProducts) } if m.domains != nil { edges = append(edges, user.EdgeDomains) } if m.businesses != nil { edges = append(edges, user.EdgeBusinesses) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserMutation) AddedIDs(name string) []ent.Value { switch name { case user.EdgeProducts: ids := make([]ent.Value, 0, len(m.products)) for id := range m.products { ids = append(ids, id) } return ids case user.EdgeDomains: ids := make([]ent.Value, 0, len(m.domains)) for id := range m.domains { ids = append(ids, id) } return ids case user.EdgeBusinesses: ids := make([]ent.Value, 0, len(m.businesses)) for id := range m.businesses { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { edges := make([]string, 0, 3) if m.removedproducts != nil { edges = append(edges, user.EdgeProducts) } if m.removeddomains != nil { edges = append(edges, user.EdgeDomains) } if m.removedbusinesses != nil { edges = append(edges, user.EdgeBusinesses) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *UserMutation) RemovedIDs(name string) []ent.Value { switch name { case user.EdgeProducts: ids := make([]ent.Value, 0, len(m.removedproducts)) for id := range m.removedproducts { ids = append(ids, id) } return ids case user.EdgeDomains: ids := make([]ent.Value, 0, len(m.removeddomains)) for id := range m.removeddomains { ids = append(ids, id) } return ids case user.EdgeBusinesses: ids := make([]ent.Value, 0, len(m.removedbusinesses)) for id := range m.removedbusinesses { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedproducts { edges = append(edges, user.EdgeProducts) } if m.cleareddomains { edges = append(edges, user.EdgeDomains) } if m.clearedbusinesses { edges = append(edges, user.EdgeBusinesses) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserMutation) EdgeCleared(name string) bool { switch name { case user.EdgeProducts: return m.clearedproducts case user.EdgeDomains: return m.cleareddomains case user.EdgeBusinesses: return m.clearedbusinesses } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *UserMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown User unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *UserMutation) ResetEdge(name string) error { switch name { case user.EdgeProducts: m.ResetProducts() return nil case user.EdgeDomains: m.ResetDomains() return nil case user.EdgeBusinesses: m.ResetBusinesses() return nil } return fmt.Errorf("unknown User edge %s", name) }