userallowedgroup_delete.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "entgo.io/ent/dialect/sql"
  6. "entgo.io/ent/dialect/sql/sqlgraph"
  7. "github.com/Wei-Shaw/sub2api/ent/predicate"
  8. "github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
  9. )
  10. // UserAllowedGroupDelete is the builder for deleting a UserAllowedGroup entity.
  11. type UserAllowedGroupDelete struct {
  12. config
  13. hooks []Hook
  14. mutation *UserAllowedGroupMutation
  15. }
  16. // Where appends a list predicates to the UserAllowedGroupDelete builder.
  17. func (_d *UserAllowedGroupDelete) Where(ps ...predicate.UserAllowedGroup) *UserAllowedGroupDelete {
  18. _d.mutation.Where(ps...)
  19. return _d
  20. }
  21. // Exec executes the deletion query and returns how many vertices were deleted.
  22. func (_d *UserAllowedGroupDelete) Exec(ctx context.Context) (int, error) {
  23. return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
  24. }
  25. // ExecX is like Exec, but panics if an error occurs.
  26. func (_d *UserAllowedGroupDelete) ExecX(ctx context.Context) int {
  27. n, err := _d.Exec(ctx)
  28. if err != nil {
  29. panic(err)
  30. }
  31. return n
  32. }
  33. func (_d *UserAllowedGroupDelete) sqlExec(ctx context.Context) (int, error) {
  34. _spec := sqlgraph.NewDeleteSpec(userallowedgroup.Table, nil)
  35. if ps := _d.mutation.predicates; len(ps) > 0 {
  36. _spec.Predicate = func(selector *sql.Selector) {
  37. for i := range ps {
  38. ps[i](selector)
  39. }
  40. }
  41. }
  42. affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
  43. if err != nil && sqlgraph.IsConstraintError(err) {
  44. err = &ConstraintError{msg: err.Error(), wrap: err}
  45. }
  46. _d.mutation.done = true
  47. return affected, err
  48. }
  49. // UserAllowedGroupDeleteOne is the builder for deleting a single UserAllowedGroup entity.
  50. type UserAllowedGroupDeleteOne struct {
  51. _d *UserAllowedGroupDelete
  52. }
  53. // Where appends a list predicates to the UserAllowedGroupDelete builder.
  54. func (_d *UserAllowedGroupDeleteOne) Where(ps ...predicate.UserAllowedGroup) *UserAllowedGroupDeleteOne {
  55. _d._d.mutation.Where(ps...)
  56. return _d
  57. }
  58. // Exec executes the deletion query.
  59. func (_d *UserAllowedGroupDeleteOne) Exec(ctx context.Context) error {
  60. n, err := _d._d.Exec(ctx)
  61. switch {
  62. case err != nil:
  63. return err
  64. case n == 0:
  65. return &NotFoundError{userallowedgroup.Label}
  66. default:
  67. return nil
  68. }
  69. }
  70. // ExecX is like Exec, but panics if an error occurs.
  71. func (_d *UserAllowedGroupDeleteOne) ExecX(ctx context.Context) {
  72. if err := _d.Exec(ctx); err != nil {
  73. panic(err)
  74. }
  75. }