telegram-commerce/ent/productcategory_delete.go

89 lines
2.4 KiB
Go
Raw Normal View History

2023-10-25 21:54:32 +00:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"tel-commerce/ent/predicate"
"tel-commerce/ent/productcategory"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ProductCategoryDelete is the builder for deleting a ProductCategory entity.
type ProductCategoryDelete struct {
config
hooks []Hook
mutation *ProductCategoryMutation
}
// Where appends a list predicates to the ProductCategoryDelete builder.
func (pcd *ProductCategoryDelete) Where(ps ...predicate.ProductCategory) *ProductCategoryDelete {
pcd.mutation.Where(ps...)
return pcd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (pcd *ProductCategoryDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, pcd.sqlExec, pcd.mutation, pcd.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (pcd *ProductCategoryDelete) ExecX(ctx context.Context) int {
n, err := pcd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (pcd *ProductCategoryDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(productcategory.Table, sqlgraph.NewFieldSpec(productcategory.FieldID, field.TypeInt))
if ps := pcd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, pcd.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
pcd.mutation.done = true
return affected, err
}
// ProductCategoryDeleteOne is the builder for deleting a single ProductCategory entity.
type ProductCategoryDeleteOne struct {
pcd *ProductCategoryDelete
}
// Where appends a list predicates to the ProductCategoryDelete builder.
func (pcdo *ProductCategoryDeleteOne) Where(ps ...predicate.ProductCategory) *ProductCategoryDeleteOne {
pcdo.pcd.mutation.Where(ps...)
return pcdo
}
// Exec executes the deletion query.
func (pcdo *ProductCategoryDeleteOne) Exec(ctx context.Context) error {
n, err := pcdo.pcd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{productcategory.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (pcdo *ProductCategoryDeleteOne) ExecX(ctx context.Context) {
if err := pcdo.Exec(ctx); err != nil {
panic(err)
}
}