mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
* entc/gen: use more go-ish names for generated error types * entc/gen: add NotLodedError type for eager-load api
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
// Code generated by entc, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/facebookincubator/ent/dialect/sql"
|
|
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
|
"github.com/facebookincubator/ent/entc/integration/ent/comment"
|
|
"github.com/facebookincubator/ent/entc/integration/ent/predicate"
|
|
"github.com/facebookincubator/ent/schema/field"
|
|
)
|
|
|
|
// CommentDelete is the builder for deleting a Comment entity.
|
|
type CommentDelete struct {
|
|
config
|
|
predicates []predicate.Comment
|
|
}
|
|
|
|
// Where adds a new predicate to the delete builder.
|
|
func (cd *CommentDelete) Where(ps ...predicate.Comment) *CommentDelete {
|
|
cd.predicates = append(cd.predicates, ps...)
|
|
return cd
|
|
}
|
|
|
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
|
func (cd *CommentDelete) Exec(ctx context.Context) (int, error) {
|
|
return cd.sqlExec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (cd *CommentDelete) ExecX(ctx context.Context) int {
|
|
n, err := cd.Exec(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (cd *CommentDelete) sqlExec(ctx context.Context) (int, error) {
|
|
_spec := &sqlgraph.DeleteSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: comment.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Column: comment.FieldID,
|
|
},
|
|
},
|
|
}
|
|
if ps := cd.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
return sqlgraph.DeleteNodes(ctx, cd.driver, _spec)
|
|
}
|
|
|
|
// CommentDeleteOne is the builder for deleting a single Comment entity.
|
|
type CommentDeleteOne struct {
|
|
cd *CommentDelete
|
|
}
|
|
|
|
// Exec executes the deletion query.
|
|
func (cdo *CommentDeleteOne) Exec(ctx context.Context) error {
|
|
n, err := cdo.cd.Exec(ctx)
|
|
switch {
|
|
case err != nil:
|
|
return err
|
|
case n == 0:
|
|
return &NotFoundError{comment.Label}
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (cdo *CommentDeleteOne) ExecX(ctx context.Context) {
|
|
cdo.cd.ExecX(ctx)
|
|
}
|