zkt24/z2/backend/ent/blocks_delete.go
2024-04-25 13:51:47 +02:00

89 lines
2.1 KiB
Go

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