group_delete.go 2.5 KB

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