// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "tel-commerce/ent/business" "tel-commerce/ent/businesscategory" "tel-commerce/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // BusinessCategoryUpdate is the builder for updating BusinessCategory entities. type BusinessCategoryUpdate struct { config hooks []Hook mutation *BusinessCategoryMutation } // Where appends a list predicates to the BusinessCategoryUpdate builder. func (bcu *BusinessCategoryUpdate) Where(ps ...predicate.BusinessCategory) *BusinessCategoryUpdate { bcu.mutation.Where(ps...) return bcu } // SetSlug sets the "slug" field. func (bcu *BusinessCategoryUpdate) SetSlug(s string) *BusinessCategoryUpdate { bcu.mutation.SetSlug(s) return bcu } // SetName sets the "name" field. func (bcu *BusinessCategoryUpdate) SetName(s string) *BusinessCategoryUpdate { bcu.mutation.SetName(s) return bcu } // SetNillableName sets the "name" field if the given value is not nil. func (bcu *BusinessCategoryUpdate) SetNillableName(s *string) *BusinessCategoryUpdate { if s != nil { bcu.SetName(*s) } return bcu } // SetDescription sets the "description" field. func (bcu *BusinessCategoryUpdate) SetDescription(s string) *BusinessCategoryUpdate { bcu.mutation.SetDescription(s) return bcu } // SetNillableDescription sets the "description" field if the given value is not nil. func (bcu *BusinessCategoryUpdate) SetNillableDescription(s *string) *BusinessCategoryUpdate { if s != nil { bcu.SetDescription(*s) } return bcu } // AddBusinessIDs adds the "businesses" edge to the Business entity by IDs. func (bcu *BusinessCategoryUpdate) AddBusinessIDs(ids ...int) *BusinessCategoryUpdate { bcu.mutation.AddBusinessIDs(ids...) return bcu } // AddBusinesses adds the "businesses" edges to the Business entity. func (bcu *BusinessCategoryUpdate) AddBusinesses(b ...*Business) *BusinessCategoryUpdate { ids := make([]int, len(b)) for i := range b { ids[i] = b[i].ID } return bcu.AddBusinessIDs(ids...) } // Mutation returns the BusinessCategoryMutation object of the builder. func (bcu *BusinessCategoryUpdate) Mutation() *BusinessCategoryMutation { return bcu.mutation } // ClearBusinesses clears all "businesses" edges to the Business entity. func (bcu *BusinessCategoryUpdate) ClearBusinesses() *BusinessCategoryUpdate { bcu.mutation.ClearBusinesses() return bcu } // RemoveBusinessIDs removes the "businesses" edge to Business entities by IDs. func (bcu *BusinessCategoryUpdate) RemoveBusinessIDs(ids ...int) *BusinessCategoryUpdate { bcu.mutation.RemoveBusinessIDs(ids...) return bcu } // RemoveBusinesses removes "businesses" edges to Business entities. func (bcu *BusinessCategoryUpdate) RemoveBusinesses(b ...*Business) *BusinessCategoryUpdate { ids := make([]int, len(b)) for i := range b { ids[i] = b[i].ID } return bcu.RemoveBusinessIDs(ids...) } // Save executes the query and returns the number of nodes affected by the update operation. func (bcu *BusinessCategoryUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, bcu.sqlSave, bcu.mutation, bcu.hooks) } // SaveX is like Save, but panics if an error occurs. func (bcu *BusinessCategoryUpdate) SaveX(ctx context.Context) int { affected, err := bcu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (bcu *BusinessCategoryUpdate) Exec(ctx context.Context) error { _, err := bcu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (bcu *BusinessCategoryUpdate) ExecX(ctx context.Context) { if err := bcu.Exec(ctx); err != nil { panic(err) } } func (bcu *BusinessCategoryUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := sqlgraph.NewUpdateSpec(businesscategory.Table, businesscategory.Columns, sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt)) if ps := bcu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := bcu.mutation.Slug(); ok { _spec.SetField(businesscategory.FieldSlug, field.TypeString, value) } if value, ok := bcu.mutation.Name(); ok { _spec.SetField(businesscategory.FieldName, field.TypeString, value) } if value, ok := bcu.mutation.Description(); ok { _spec.SetField(businesscategory.FieldDescription, field.TypeString, value) } if bcu.mutation.BusinessesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: businesscategory.BusinessesTable, Columns: businesscategory.BusinessesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := bcu.mutation.RemovedBusinessesIDs(); len(nodes) > 0 && !bcu.mutation.BusinessesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: businesscategory.BusinessesTable, Columns: businesscategory.BusinessesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := bcu.mutation.BusinessesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: businesscategory.BusinessesTable, Columns: businesscategory.BusinessesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if n, err = sqlgraph.UpdateNodes(ctx, bcu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{businesscategory.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } bcu.mutation.done = true return n, nil } // BusinessCategoryUpdateOne is the builder for updating a single BusinessCategory entity. type BusinessCategoryUpdateOne struct { config fields []string hooks []Hook mutation *BusinessCategoryMutation } // SetSlug sets the "slug" field. func (bcuo *BusinessCategoryUpdateOne) SetSlug(s string) *BusinessCategoryUpdateOne { bcuo.mutation.SetSlug(s) return bcuo } // SetName sets the "name" field. func (bcuo *BusinessCategoryUpdateOne) SetName(s string) *BusinessCategoryUpdateOne { bcuo.mutation.SetName(s) return bcuo } // SetNillableName sets the "name" field if the given value is not nil. func (bcuo *BusinessCategoryUpdateOne) SetNillableName(s *string) *BusinessCategoryUpdateOne { if s != nil { bcuo.SetName(*s) } return bcuo } // SetDescription sets the "description" field. func (bcuo *BusinessCategoryUpdateOne) SetDescription(s string) *BusinessCategoryUpdateOne { bcuo.mutation.SetDescription(s) return bcuo } // SetNillableDescription sets the "description" field if the given value is not nil. func (bcuo *BusinessCategoryUpdateOne) SetNillableDescription(s *string) *BusinessCategoryUpdateOne { if s != nil { bcuo.SetDescription(*s) } return bcuo } // AddBusinessIDs adds the "businesses" edge to the Business entity by IDs. func (bcuo *BusinessCategoryUpdateOne) AddBusinessIDs(ids ...int) *BusinessCategoryUpdateOne { bcuo.mutation.AddBusinessIDs(ids...) return bcuo } // AddBusinesses adds the "businesses" edges to the Business entity. func (bcuo *BusinessCategoryUpdateOne) AddBusinesses(b ...*Business) *BusinessCategoryUpdateOne { ids := make([]int, len(b)) for i := range b { ids[i] = b[i].ID } return bcuo.AddBusinessIDs(ids...) } // Mutation returns the BusinessCategoryMutation object of the builder. func (bcuo *BusinessCategoryUpdateOne) Mutation() *BusinessCategoryMutation { return bcuo.mutation } // ClearBusinesses clears all "businesses" edges to the Business entity. func (bcuo *BusinessCategoryUpdateOne) ClearBusinesses() *BusinessCategoryUpdateOne { bcuo.mutation.ClearBusinesses() return bcuo } // RemoveBusinessIDs removes the "businesses" edge to Business entities by IDs. func (bcuo *BusinessCategoryUpdateOne) RemoveBusinessIDs(ids ...int) *BusinessCategoryUpdateOne { bcuo.mutation.RemoveBusinessIDs(ids...) return bcuo } // RemoveBusinesses removes "businesses" edges to Business entities. func (bcuo *BusinessCategoryUpdateOne) RemoveBusinesses(b ...*Business) *BusinessCategoryUpdateOne { ids := make([]int, len(b)) for i := range b { ids[i] = b[i].ID } return bcuo.RemoveBusinessIDs(ids...) } // Where appends a list predicates to the BusinessCategoryUpdate builder. func (bcuo *BusinessCategoryUpdateOne) Where(ps ...predicate.BusinessCategory) *BusinessCategoryUpdateOne { bcuo.mutation.Where(ps...) return bcuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (bcuo *BusinessCategoryUpdateOne) Select(field string, fields ...string) *BusinessCategoryUpdateOne { bcuo.fields = append([]string{field}, fields...) return bcuo } // Save executes the query and returns the updated BusinessCategory entity. func (bcuo *BusinessCategoryUpdateOne) Save(ctx context.Context) (*BusinessCategory, error) { return withHooks(ctx, bcuo.sqlSave, bcuo.mutation, bcuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (bcuo *BusinessCategoryUpdateOne) SaveX(ctx context.Context) *BusinessCategory { node, err := bcuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (bcuo *BusinessCategoryUpdateOne) Exec(ctx context.Context) error { _, err := bcuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (bcuo *BusinessCategoryUpdateOne) ExecX(ctx context.Context) { if err := bcuo.Exec(ctx); err != nil { panic(err) } } func (bcuo *BusinessCategoryUpdateOne) sqlSave(ctx context.Context) (_node *BusinessCategory, err error) { _spec := sqlgraph.NewUpdateSpec(businesscategory.Table, businesscategory.Columns, sqlgraph.NewFieldSpec(businesscategory.FieldID, field.TypeInt)) id, ok := bcuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BusinessCategory.id" for update`)} } _spec.Node.ID.Value = id if fields := bcuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, businesscategory.FieldID) for _, f := range fields { if !businesscategory.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != businesscategory.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := bcuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := bcuo.mutation.Slug(); ok { _spec.SetField(businesscategory.FieldSlug, field.TypeString, value) } if value, ok := bcuo.mutation.Name(); ok { _spec.SetField(businesscategory.FieldName, field.TypeString, value) } if value, ok := bcuo.mutation.Description(); ok { _spec.SetField(businesscategory.FieldDescription, field.TypeString, value) } if bcuo.mutation.BusinessesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: businesscategory.BusinessesTable, Columns: businesscategory.BusinessesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := bcuo.mutation.RemovedBusinessesIDs(); len(nodes) > 0 && !bcuo.mutation.BusinessesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: businesscategory.BusinessesTable, Columns: businesscategory.BusinessesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := bcuo.mutation.BusinessesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: businesscategory.BusinessesTable, Columns: businesscategory.BusinessesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &BusinessCategory{config: bcuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, bcuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{businesscategory.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } bcuo.mutation.done = true return _node, nil }