rag/ent/library_delete.go

89 lines
2.2 KiB
Go
Raw Normal View History

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