github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/file_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 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/file" 13 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/predicate" 14 ) 15 16 // FileDelete is the builder for deleting a File entity. 17 type FileDelete struct { 18 config 19 hooks []Hook 20 mutation *FileMutation 21 } 22 23 // Where appends a list predicates to the FileDelete builder. 24 func (fd *FileDelete) Where(ps ...predicate.File) *FileDelete { 25 fd.mutation.Where(ps...) 26 return fd 27 } 28 29 // Exec executes the deletion query and returns how many vertices were deleted. 30 func (fd *FileDelete) Exec(ctx context.Context) (int, error) { 31 var ( 32 err error 33 affected int 34 ) 35 if len(fd.hooks) == 0 { 36 affected, err = fd.sqlExec(ctx) 37 } else { 38 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 39 mutation, ok := m.(*FileMutation) 40 if !ok { 41 return nil, fmt.Errorf("unexpected mutation type %T", m) 42 } 43 fd.mutation = mutation 44 affected, err = fd.sqlExec(ctx) 45 mutation.done = true 46 return affected, err 47 }) 48 for i := len(fd.hooks) - 1; i >= 0; i-- { 49 if fd.hooks[i] == nil { 50 return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 51 } 52 mut = fd.hooks[i](mut) 53 } 54 if _, err := mut.Mutate(ctx, fd.mutation); err != nil { 55 return 0, err 56 } 57 } 58 return affected, err 59 } 60 61 // ExecX is like Exec, but panics if an error occurs. 62 func (fd *FileDelete) ExecX(ctx context.Context) int { 63 n, err := fd.Exec(ctx) 64 if err != nil { 65 panic(err) 66 } 67 return n 68 } 69 70 func (fd *FileDelete) sqlExec(ctx context.Context) (int, error) { 71 _spec := &sqlgraph.DeleteSpec{ 72 Node: &sqlgraph.NodeSpec{ 73 Table: file.Table, 74 ID: &sqlgraph.FieldSpec{ 75 Type: field.TypeInt, 76 Column: file.FieldID, 77 }, 78 }, 79 } 80 if ps := fd.mutation.predicates; len(ps) > 0 { 81 _spec.Predicate = func(selector *sql.Selector) { 82 for i := range ps { 83 ps[i](selector) 84 } 85 } 86 } 87 return sqlgraph.DeleteNodes(ctx, fd.driver, _spec) 88 } 89 90 // FileDeleteOne is the builder for deleting a single File entity. 91 type FileDeleteOne struct { 92 fd *FileDelete 93 } 94 95 // Exec executes the deletion query. 96 func (fdo *FileDeleteOne) Exec(ctx context.Context) error { 97 n, err := fdo.fd.Exec(ctx) 98 switch { 99 case err != nil: 100 return err 101 case n == 0: 102 return &NotFoundError{file.Label} 103 default: 104 return nil 105 } 106 } 107 108 // ExecX is like Exec, but panics if an error occurs. 109 func (fdo *FileDeleteOne) ExecX(ctx context.Context) { 110 fdo.fd.ExecX(ctx) 111 }