mirror of
https://github.com/Fishwaldo/mouthpiece.git
synced 2025-03-16 03:51:22 +00:00
139 lines
3.8 KiB
Go
139 lines
3.8 KiB
Go
/*
|
|
MIT License
|
|
|
|
Copyright (c) 2021 Justin Hammond
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
*/
|
|
|
|
// Code generated by entc, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbmessage"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/ent/predicate"
|
|
)
|
|
|
|
// DbMessageDelete is the builder for deleting a DbMessage entity.
|
|
type DbMessageDelete struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *DbMessageMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the DbMessageDelete builder.
|
|
func (dmd *DbMessageDelete) Where(ps ...predicate.DbMessage) *DbMessageDelete {
|
|
dmd.mutation.Where(ps...)
|
|
return dmd
|
|
}
|
|
|
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
|
func (dmd *DbMessageDelete) Exec(ctx context.Context) (int, error) {
|
|
var (
|
|
err error
|
|
affected int
|
|
)
|
|
if len(dmd.hooks) == 0 {
|
|
affected, err = dmd.sqlExec(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*DbMessageMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
dmd.mutation = mutation
|
|
affected, err = dmd.sqlExec(ctx)
|
|
mutation.done = true
|
|
return affected, err
|
|
})
|
|
for i := len(dmd.hooks) - 1; i >= 0; i-- {
|
|
if dmd.hooks[i] == nil {
|
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = dmd.hooks[i](mut)
|
|
}
|
|
if _, err := mut.Mutate(ctx, dmd.mutation); err != nil {
|
|
return 0, err
|
|
}
|
|
}
|
|
return affected, err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (dmd *DbMessageDelete) ExecX(ctx context.Context) int {
|
|
n, err := dmd.Exec(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (dmd *DbMessageDelete) sqlExec(ctx context.Context) (int, error) {
|
|
_spec := &sqlgraph.DeleteSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: dbmessage.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeUUID,
|
|
Column: dbmessage.FieldID,
|
|
},
|
|
},
|
|
}
|
|
if ps := dmd.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
affected, err := sqlgraph.DeleteNodes(ctx, dmd.driver, _spec)
|
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return affected, err
|
|
}
|
|
|
|
// DbMessageDeleteOne is the builder for deleting a single DbMessage entity.
|
|
type DbMessageDeleteOne struct {
|
|
dmd *DbMessageDelete
|
|
}
|
|
|
|
// Exec executes the deletion query.
|
|
func (dmdo *DbMessageDeleteOne) Exec(ctx context.Context) error {
|
|
n, err := dmdo.dmd.Exec(ctx)
|
|
switch {
|
|
case err != nil:
|
|
return err
|
|
case n == 0:
|
|
return &NotFoundError{dbmessage.Label}
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (dmdo *DbMessageDeleteOne) ExecX(ctx context.Context) {
|
|
dmdo.dmd.ExecX(ctx)
|
|
}
|