telegram-commerce/ent/mutation.go

3032 lines
91 KiB
Go
Raw Permalink Normal View History

2023-10-25 21:54:32 +00:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"tel-commerce/ent/business"
"tel-commerce/ent/businesscategory"
"tel-commerce/ent/predicate"
"tel-commerce/ent/product"
"tel-commerce/ent/productcategory"
"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"
TypeProduct = "Product"
TypeProductCategory = "ProductCategory"
)
// 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
company *string
about_us *string
created_at *time.Time
updated_at *time.Time
clearedFields map[string]struct{}
businessCategory map[int]struct{}
removedbusinessCategory map[int]struct{}
clearedbusinessCategory 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)
}
// SetCompany sets the "company" field.
func (m *BusinessMutation) SetCompany(s string) {
m.company = &s
}
// Company returns the value of the "company" field in the mutation.
func (m *BusinessMutation) 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 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) 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 *BusinessMutation) ResetCompany() {
m.company = nil
}
// 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)
}
// 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
}
// AddBusinessCategoryIDs adds the "businessCategory" edge to the BusinessCategory entity by ids.
func (m *BusinessMutation) AddBusinessCategoryIDs(ids ...int) {
if m.businessCategory == nil {
m.businessCategory = make(map[int]struct{})
}
for i := range ids {
m.businessCategory[ids[i]] = struct{}{}
}
}
// ClearBusinessCategory clears the "businessCategory" edge to the BusinessCategory entity.
func (m *BusinessMutation) ClearBusinessCategory() {
m.clearedbusinessCategory = true
}
// BusinessCategoryCleared reports if the "businessCategory" edge to the BusinessCategory entity was cleared.
func (m *BusinessMutation) BusinessCategoryCleared() bool {
return m.clearedbusinessCategory
}
// RemoveBusinessCategoryIDs removes the "businessCategory" edge to the BusinessCategory entity by IDs.
func (m *BusinessMutation) RemoveBusinessCategoryIDs(ids ...int) {
if m.removedbusinessCategory == nil {
m.removedbusinessCategory = make(map[int]struct{})
}
for i := range ids {
delete(m.businessCategory, ids[i])
m.removedbusinessCategory[ids[i]] = struct{}{}
}
}
// RemovedBusinessCategory returns the removed IDs of the "businessCategory" edge to the BusinessCategory entity.
func (m *BusinessMutation) RemovedBusinessCategoryIDs() (ids []int) {
for id := range m.removedbusinessCategory {
ids = append(ids, id)
}
return
}
// BusinessCategoryIDs returns the "businessCategory" edge IDs in the mutation.
func (m *BusinessMutation) BusinessCategoryIDs() (ids []int) {
for id := range m.businessCategory {
ids = append(ids, id)
}
return
}
// ResetBusinessCategory resets all changes to the "businessCategory" edge.
func (m *BusinessMutation) ResetBusinessCategory() {
m.businessCategory = nil
m.clearedbusinessCategory = false
m.removedbusinessCategory = 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, 8)
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.company != nil {
fields = append(fields, business.FieldCompany)
}
if m.about_us != nil {
fields = append(fields, business.FieldAboutUs)
}
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.FieldCompany:
return m.Company()
case business.FieldAboutUs:
return m.AboutUs()
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.FieldCompany:
return m.OldCompany(ctx)
case business.FieldAboutUs:
return m.OldAboutUs(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.FieldCompany:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCompany(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.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 {
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 *BusinessMutation) 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 *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)
}
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
}
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.FieldCompany:
m.ResetCompany()
return nil
case business.FieldAboutUs:
m.ResetAboutUs()
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, 1)
if m.businessCategory != nil {
edges = append(edges, business.EdgeBusinessCategory)
}
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.EdgeBusinessCategory:
ids := make([]ent.Value, 0, len(m.businessCategory))
for id := range m.businessCategory {
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, 1)
if m.removedbusinessCategory != nil {
edges = append(edges, business.EdgeBusinessCategory)
}
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.EdgeBusinessCategory:
ids := make([]ent.Value, 0, len(m.removedbusinessCategory))
for id := range m.removedbusinessCategory {
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, 1)
if m.clearedbusinessCategory {
edges = append(edges, business.EdgeBusinessCategory)
}
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.EdgeBusinessCategory:
return m.clearedbusinessCategory
}
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 {
}
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.EdgeBusinessCategory:
m.ResetBusinessCategory()
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)
}
// ProductMutation represents an operation that mutates the Product nodes in the graph.
type ProductMutation struct {
config
op Op
typ string
id *int
name *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{}
productCategory map[int]struct{}
removedproductCategory map[int]struct{}
clearedproductCategory 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
}
// 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
}
// 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
}
// AddProductCategoryIDs adds the "productCategory" edge to the ProductCategory entity by ids.
func (m *ProductMutation) AddProductCategoryIDs(ids ...int) {
if m.productCategory == nil {
m.productCategory = make(map[int]struct{})
}
for i := range ids {
m.productCategory[ids[i]] = struct{}{}
}
}
// ClearProductCategory clears the "productCategory" edge to the ProductCategory entity.
func (m *ProductMutation) ClearProductCategory() {
m.clearedproductCategory = true
}
// ProductCategoryCleared reports if the "productCategory" edge to the ProductCategory entity was cleared.
func (m *ProductMutation) ProductCategoryCleared() bool {
return m.clearedproductCategory
}
// RemoveProductCategoryIDs removes the "productCategory" edge to the ProductCategory entity by IDs.
func (m *ProductMutation) RemoveProductCategoryIDs(ids ...int) {
if m.removedproductCategory == nil {
m.removedproductCategory = make(map[int]struct{})
}
for i := range ids {
delete(m.productCategory, ids[i])
m.removedproductCategory[ids[i]] = struct{}{}
}
}
// RemovedProductCategory returns the removed IDs of the "productCategory" edge to the ProductCategory entity.
func (m *ProductMutation) RemovedProductCategoryIDs() (ids []int) {
for id := range m.removedproductCategory {
ids = append(ids, id)
}
return
}
// ProductCategoryIDs returns the "productCategory" edge IDs in the mutation.
func (m *ProductMutation) ProductCategoryIDs() (ids []int) {
for id := range m.productCategory {
ids = append(ids, id)
}
return
}
// ResetProductCategory resets all changes to the "productCategory" edge.
func (m *ProductMutation) ResetProductCategory() {
m.productCategory = nil
m.clearedproductCategory = false
m.removedproductCategory = nil
}
// 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, 8)
if m.name != nil {
fields = append(fields, product.FieldName)
}
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.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.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.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.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.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.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.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.FieldDescription) {
fields = append(fields, product.FieldDescription)
}
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.FieldDescription:
m.ClearDescription()
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.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.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, 1)
if m.productCategory != nil {
edges = append(edges, product.EdgeProductCategory)
}
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.EdgeProductCategory:
ids := make([]ent.Value, 0, len(m.productCategory))
for id := range m.productCategory {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ProductMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
if m.removedproductCategory != nil {
edges = append(edges, product.EdgeProductCategory)
}
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 {
switch name {
case product.EdgeProductCategory:
ids := make([]ent.Value, 0, len(m.removedproductCategory))
for id := range m.removedproductCategory {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ProductMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.clearedproductCategory {
edges = append(edges, product.EdgeProductCategory)
}
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.EdgeProductCategory:
return m.clearedproductCategory
}
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 {
}
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.EdgeProductCategory:
m.ResetProductCategory()
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
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
}
// 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
}
// 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, 6)
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.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.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.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.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 {
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 *ProductCategoryMutation) 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 *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)
}
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
}
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.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, 1)
if m.products != nil {
edges = append(edges, productcategory.EdgeProducts)
}
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
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ProductCategoryMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
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, 1)
if m.clearedproducts {
edges = append(edges, productcategory.EdgeProducts)
}
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
}
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 {
}
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
}
return fmt.Errorf("unknown ProductCategory edge %s", name)
}