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