group_delete.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "fmt"
  6. "code.osinet.fr/fgm/go__ent_demo/ent/group"
  7. "code.osinet.fr/fgm/go__ent_demo/ent/predicate"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. )
  12. // GroupDelete is the builder for deleting a Group entity.
  13. type GroupDelete struct {
  14. config
  15. hooks []Hook
  16. mutation *GroupMutation
  17. }
  18. // Where appends a list predicates to the GroupDelete builder.
  19. func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete {
  20. gd.mutation.Where(ps...)
  21. return gd
  22. }
  23. // Exec executes the deletion query and returns how many vertices were deleted.
  24. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) {
  25. var (
  26. err error
  27. affected int
  28. )
  29. if len(gd.hooks) == 0 {
  30. affected, err = gd.sqlExec(ctx)
  31. } else {
  32. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  33. mutation, ok := m.(*GroupMutation)
  34. if !ok {
  35. return nil, fmt.Errorf("unexpected mutation type %T", m)
  36. }
  37. gd.mutation = mutation
  38. affected, err = gd.sqlExec(ctx)
  39. mutation.done = true
  40. return affected, err
  41. })
  42. for i := len(gd.hooks) - 1; i >= 0; i-- {
  43. if gd.hooks[i] == nil {
  44. return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  45. }
  46. mut = gd.hooks[i](mut)
  47. }
  48. if _, err := mut.Mutate(ctx, gd.mutation); err != nil {
  49. return 0, err
  50. }
  51. }
  52. return affected, err
  53. }
  54. // ExecX is like Exec, but panics if an error occurs.
  55. func (gd *GroupDelete) ExecX(ctx context.Context) int {
  56. n, err := gd.Exec(ctx)
  57. if err != nil {
  58. panic(err)
  59. }
  60. return n
  61. }
  62. func (gd *GroupDelete) sqlExec(ctx context.Context) (int, error) {
  63. _spec := &sqlgraph.DeleteSpec{
  64. Node: &sqlgraph.NodeSpec{
  65. Table: group.Table,
  66. ID: &sqlgraph.FieldSpec{
  67. Type: field.TypeInt,
  68. Column: group.FieldID,
  69. },
  70. },
  71. }
  72. if ps := gd.mutation.predicates; len(ps) > 0 {
  73. _spec.Predicate = func(selector *sql.Selector) {
  74. for i := range ps {
  75. ps[i](selector)
  76. }
  77. }
  78. }
  79. return sqlgraph.DeleteNodes(ctx, gd.driver, _spec)
  80. }
  81. // GroupDeleteOne is the builder for deleting a single Group entity.
  82. type GroupDeleteOne struct {
  83. gd *GroupDelete
  84. }
  85. // Exec executes the deletion query.
  86. func (gdo *GroupDeleteOne) Exec(ctx context.Context) error {
  87. n, err := gdo.gd.Exec(ctx)
  88. switch {
  89. case err != nil:
  90. return err
  91. case n == 0:
  92. return &NotFoundError{group.Label}
  93. default:
  94. return nil
  95. }
  96. }
  97. // ExecX is like Exec, but panics if an error occurs.
  98. func (gdo *GroupDeleteOne) ExecX(ctx context.Context) {
  99. gdo.gd.ExecX(ctx)
  100. }