crowdsec/pkg/database/ent/allowlist_delete.go

88 lines
2.3 KiB
Go

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