mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/38 Only `IsNil` and `NotNil` predicates are supported this moment Reviewed By: alexsn Differential Revision: D17444976 fbshipit-source-id: 37336fa0bc7749af995933baee2e23bb7366dd78
82 lines
2.0 KiB
Go
82 lines
2.0 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 (@generated) by entc, DO NOT EDIT.
|
|
|
|
package entv2
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/facebookincubator/ent/dialect/sql"
|
|
"github.com/facebookincubator/ent/entc/integration/migrate/entv2/predicate"
|
|
"github.com/facebookincubator/ent/entc/integration/migrate/entv2/user"
|
|
)
|
|
|
|
// UserDelete is the builder for deleting a User entity.
|
|
type UserDelete struct {
|
|
config
|
|
predicates []predicate.User
|
|
}
|
|
|
|
// Where adds a new predicate to the delete builder.
|
|
func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete {
|
|
ud.predicates = append(ud.predicates, ps...)
|
|
return ud
|
|
}
|
|
|
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
|
func (ud *UserDelete) Exec(ctx context.Context) (int, error) {
|
|
return ud.sqlExec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (ud *UserDelete) ExecX(ctx context.Context) int {
|
|
n, err := ud.Exec(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
|
var res sql.Result
|
|
selector := sql.Select().From(sql.Table(user.Table))
|
|
for _, p := range ud.predicates {
|
|
p(selector)
|
|
}
|
|
query, args := sql.Delete(user.Table).FromSelect(selector).Query()
|
|
if err := ud.driver.Exec(ctx, query, args, &res); err != nil {
|
|
return 0, err
|
|
}
|
|
affected, err := res.RowsAffected()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return int(affected), nil
|
|
}
|
|
|
|
// UserDeleteOne is the builder for deleting a single User entity.
|
|
type UserDeleteOne struct {
|
|
ud *UserDelete
|
|
}
|
|
|
|
// Exec executes the deletion query.
|
|
func (udo *UserDeleteOne) Exec(ctx context.Context) error {
|
|
n, err := udo.ud.Exec(ctx)
|
|
switch {
|
|
case err != nil:
|
|
return err
|
|
case n == 0:
|
|
return &ErrNotFound{user.Label}
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (udo *UserDeleteOne) ExecX(ctx context.Context) {
|
|
udo.ud.ExecX(ctx)
|
|
}
|