123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // Code generated by entc, DO NOT EDIT.
- package ent
- import (
- "context"
- "fmt"
- "code.osinet.fr/fgm/go__ent_demo/ent/car"
- "code.osinet.fr/fgm/go__ent_demo/ent/predicate"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // CarDelete is the builder for deleting a Car entity.
- type CarDelete struct {
- config
- hooks []Hook
- mutation *CarMutation
- }
- // Where appends a list predicates to the CarDelete builder.
- func (cd *CarDelete) Where(ps ...predicate.Car) *CarDelete {
- cd.mutation.Where(ps...)
- return cd
- }
- // Exec executes the deletion query and returns how many vertices were deleted.
- func (cd *CarDelete) Exec(ctx context.Context) (int, error) {
- var (
- err error
- affected int
- )
- if len(cd.hooks) == 0 {
- affected, err = cd.sqlExec(ctx)
- } else {
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*CarMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- cd.mutation = mutation
- affected, err = cd.sqlExec(ctx)
- mutation.done = true
- return affected, err
- })
- for i := len(cd.hooks) - 1; i >= 0; i-- {
- if cd.hooks[i] == nil {
- return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
- }
- mut = cd.hooks[i](mut)
- }
- if _, err := mut.Mutate(ctx, cd.mutation); err != nil {
- return 0, err
- }
- }
- return affected, err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cd *CarDelete) ExecX(ctx context.Context) int {
- n, err := cd.Exec(ctx)
- if err != nil {
- panic(err)
- }
- return n
- }
- func (cd *CarDelete) sqlExec(ctx context.Context) (int, error) {
- _spec := &sqlgraph.DeleteSpec{
- Node: &sqlgraph.NodeSpec{
- Table: car.Table,
- ID: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: car.FieldID,
- },
- },
- }
- if ps := cd.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- return sqlgraph.DeleteNodes(ctx, cd.driver, _spec)
- }
- // CarDeleteOne is the builder for deleting a single Car entity.
- type CarDeleteOne struct {
- cd *CarDelete
- }
- // Exec executes the deletion query.
- func (cdo *CarDeleteOne) Exec(ctx context.Context) error {
- n, err := cdo.cd.Exec(ctx)
- switch {
- case err != nil:
- return err
- case n == 0:
- return &NotFoundError{car.Label}
- default:
- return nil
- }
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cdo *CarDeleteOne) ExecX(ctx context.Context) {
- cdo.cd.ExecX(ctx)
- }
|