bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/ent/event_delete.go (about) 1 // Code generated by entc, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "fmt" 8 9 "entgo.io/ent/dialect/sql" 10 "entgo.io/ent/dialect/sql/sqlgraph" 11 "entgo.io/ent/schema/field" 12 "bitbucket.org/Aishee/synsec/pkg/database/ent/event" 13 "bitbucket.org/Aishee/synsec/pkg/database/ent/predicate" 14 ) 15 16 // EventDelete is the builder for deleting a Event entity. 17 type EventDelete struct { 18 config 19 hooks []Hook 20 mutation *EventMutation 21 } 22 23 // Where adds a new predicate to the EventDelete builder. 24 func (ed *EventDelete) Where(ps ...predicate.Event) *EventDelete { 25 ed.mutation.predicates = append(ed.mutation.predicates, ps...) 26 return ed 27 } 28 29 // Exec executes the deletion query and returns how many vertices were deleted. 30 func (ed *EventDelete) Exec(ctx context.Context) (int, error) { 31 var ( 32 err error 33 affected int 34 ) 35 if len(ed.hooks) == 0 { 36 affected, err = ed.sqlExec(ctx) 37 } else { 38 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 39 mutation, ok := m.(*EventMutation) 40 if !ok { 41 return nil, fmt.Errorf("unexpected mutation type %T", m) 42 } 43 ed.mutation = mutation 44 affected, err = ed.sqlExec(ctx) 45 mutation.done = true 46 return affected, err 47 }) 48 for i := len(ed.hooks) - 1; i >= 0; i-- { 49 mut = ed.hooks[i](mut) 50 } 51 if _, err := mut.Mutate(ctx, ed.mutation); err != nil { 52 return 0, err 53 } 54 } 55 return affected, err 56 } 57 58 // ExecX is like Exec, but panics if an error occurs. 59 func (ed *EventDelete) ExecX(ctx context.Context) int { 60 n, err := ed.Exec(ctx) 61 if err != nil { 62 panic(err) 63 } 64 return n 65 } 66 67 func (ed *EventDelete) sqlExec(ctx context.Context) (int, error) { 68 _spec := &sqlgraph.DeleteSpec{ 69 Node: &sqlgraph.NodeSpec{ 70 Table: event.Table, 71 ID: &sqlgraph.FieldSpec{ 72 Type: field.TypeInt, 73 Column: event.FieldID, 74 }, 75 }, 76 } 77 if ps := ed.mutation.predicates; len(ps) > 0 { 78 _spec.Predicate = func(selector *sql.Selector) { 79 for i := range ps { 80 ps[i](selector) 81 } 82 } 83 } 84 return sqlgraph.DeleteNodes(ctx, ed.driver, _spec) 85 } 86 87 // EventDeleteOne is the builder for deleting a single Event entity. 88 type EventDeleteOne struct { 89 ed *EventDelete 90 } 91 92 // Exec executes the deletion query. 93 func (edo *EventDeleteOne) Exec(ctx context.Context) error { 94 n, err := edo.ed.Exec(ctx) 95 switch { 96 case err != nil: 97 return err 98 case n == 0: 99 return &NotFoundError{event.Label} 100 default: 101 return nil 102 } 103 } 104 105 // ExecX is like Exec, but panics if an error occurs. 106 func (edo *EventDeleteOne) ExecX(ctx context.Context) { 107 edo.ed.ExecX(ctx) 108 }