mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-14 13:24:34 +02:00
88 lines
2.2 KiB
Go
88 lines
2.2 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/alert"
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/predicate"
|
|
)
|
|
|
|
// AlertDelete is the builder for deleting a Alert entity.
|
|
type AlertDelete struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AlertMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AlertDelete builder.
|
|
func (ad *AlertDelete) Where(ps ...predicate.Alert) *AlertDelete {
|
|
ad.mutation.Where(ps...)
|
|
return ad
|
|
}
|
|
|
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
|
func (ad *AlertDelete) Exec(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, ad.sqlExec, ad.mutation, ad.hooks)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (ad *AlertDelete) ExecX(ctx context.Context) int {
|
|
n, err := ad.Exec(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (ad *AlertDelete) sqlExec(ctx context.Context) (int, error) {
|
|
_spec := sqlgraph.NewDeleteSpec(alert.Table, sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt))
|
|
if ps := ad.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
affected, err := sqlgraph.DeleteNodes(ctx, ad.driver, _spec)
|
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
ad.mutation.done = true
|
|
return affected, err
|
|
}
|
|
|
|
// AlertDeleteOne is the builder for deleting a single Alert entity.
|
|
type AlertDeleteOne struct {
|
|
ad *AlertDelete
|
|
}
|
|
|
|
// Where appends a list predicates to the AlertDelete builder.
|
|
func (ado *AlertDeleteOne) Where(ps ...predicate.Alert) *AlertDeleteOne {
|
|
ado.ad.mutation.Where(ps...)
|
|
return ado
|
|
}
|
|
|
|
// Exec executes the deletion query.
|
|
func (ado *AlertDeleteOne) Exec(ctx context.Context) error {
|
|
n, err := ado.ad.Exec(ctx)
|
|
switch {
|
|
case err != nil:
|
|
return err
|
|
case n == 0:
|
|
return &NotFoundError{alert.Label}
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (ado *AlertDeleteOne) ExecX(ctx context.Context) {
|
|
if err := ado.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|