usagestatistichour_delete.go 2.5 KB

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