github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/appcoin_delete.go (about) 1 // Code generated by ent, 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/NpoolPlatform/chain-middleware/pkg/db/ent/appcoin" 13 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/predicate" 14 ) 15 16 // AppCoinDelete is the builder for deleting a AppCoin entity. 17 type AppCoinDelete struct { 18 config 19 hooks []Hook 20 mutation *AppCoinMutation 21 } 22 23 // Where appends a list predicates to the AppCoinDelete builder. 24 func (acd *AppCoinDelete) Where(ps ...predicate.AppCoin) *AppCoinDelete { 25 acd.mutation.Where(ps...) 26 return acd 27 } 28 29 // Exec executes the deletion query and returns how many vertices were deleted. 30 func (acd *AppCoinDelete) Exec(ctx context.Context) (int, error) { 31 var ( 32 err error 33 affected int 34 ) 35 if len(acd.hooks) == 0 { 36 affected, err = acd.sqlExec(ctx) 37 } else { 38 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 39 mutation, ok := m.(*AppCoinMutation) 40 if !ok { 41 return nil, fmt.Errorf("unexpected mutation type %T", m) 42 } 43 acd.mutation = mutation 44 affected, err = acd.sqlExec(ctx) 45 mutation.done = true 46 return affected, err 47 }) 48 for i := len(acd.hooks) - 1; i >= 0; i-- { 49 if acd.hooks[i] == nil { 50 return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 51 } 52 mut = acd.hooks[i](mut) 53 } 54 if _, err := mut.Mutate(ctx, acd.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 (acd *AppCoinDelete) ExecX(ctx context.Context) int { 63 n, err := acd.Exec(ctx) 64 if err != nil { 65 panic(err) 66 } 67 return n 68 } 69 70 func (acd *AppCoinDelete) sqlExec(ctx context.Context) (int, error) { 71 _spec := &sqlgraph.DeleteSpec{ 72 Node: &sqlgraph.NodeSpec{ 73 Table: appcoin.Table, 74 ID: &sqlgraph.FieldSpec{ 75 Type: field.TypeUint32, 76 Column: appcoin.FieldID, 77 }, 78 }, 79 } 80 if ps := acd.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 affected, err := sqlgraph.DeleteNodes(ctx, acd.driver, _spec) 88 if err != nil && sqlgraph.IsConstraintError(err) { 89 err = &ConstraintError{msg: err.Error(), wrap: err} 90 } 91 return affected, err 92 } 93 94 // AppCoinDeleteOne is the builder for deleting a single AppCoin entity. 95 type AppCoinDeleteOne struct { 96 acd *AppCoinDelete 97 } 98 99 // Exec executes the deletion query. 100 func (acdo *AppCoinDeleteOne) Exec(ctx context.Context) error { 101 n, err := acdo.acd.Exec(ctx) 102 switch { 103 case err != nil: 104 return err 105 case n == 0: 106 return &NotFoundError{appcoin.Label} 107 default: 108 return nil 109 } 110 } 111 112 // ExecX is like Exec, but panics if an error occurs. 113 func (acdo *AppCoinDeleteOne) ExecX(ctx context.Context) { 114 acdo.acd.ExecX(ctx) 115 }