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