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