mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
// Copyright 2019-present Facebook Inc. 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 ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
|
|
"entgo.io/ent/dialect/gremlin"
|
|
"entgo.io/ent/dialect/gremlin/graph/dsl"
|
|
"entgo.io/ent/dialect/gremlin/graph/dsl/__"
|
|
"entgo.io/ent/dialect/gremlin/graph/dsl/g"
|
|
"entgo.io/ent/entc/integration/gremlin/ent/builder"
|
|
"entgo.io/ent/entc/integration/gremlin/ent/predicate"
|
|
)
|
|
|
|
// BuilderDelete is the builder for deleting a Builder entity.
|
|
type BuilderDelete struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *BuilderMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the BuilderDelete builder.
|
|
func (bd *BuilderDelete) Where(ps ...predicate.Builder) *BuilderDelete {
|
|
bd.mutation.Where(ps...)
|
|
return bd
|
|
}
|
|
|
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
|
func (bd *BuilderDelete) Exec(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, bd.gremlinExec, bd.mutation, bd.hooks)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (bd *BuilderDelete) ExecX(ctx context.Context) int {
|
|
n, err := bd.Exec(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (bd *BuilderDelete) gremlinExec(ctx context.Context) (int, error) {
|
|
res := &gremlin.Response{}
|
|
query, bindings := bd.gremlin().Query()
|
|
if err := bd.driver.Exec(ctx, query, bindings, res); err != nil {
|
|
return 0, err
|
|
}
|
|
bd.mutation.done = true
|
|
return res.ReadInt()
|
|
}
|
|
|
|
func (bd *BuilderDelete) gremlin() *dsl.Traversal {
|
|
t := g.V().HasLabel(builder.Label)
|
|
for _, p := range bd.mutation.predicates {
|
|
p(t)
|
|
}
|
|
return t.SideEffect(__.Drop()).Count()
|
|
}
|
|
|
|
// BuilderDeleteOne is the builder for deleting a single Builder entity.
|
|
type BuilderDeleteOne struct {
|
|
bd *BuilderDelete
|
|
}
|
|
|
|
// Where appends a list predicates to the BuilderDelete builder.
|
|
func (bdo *BuilderDeleteOne) Where(ps ...predicate.Builder) *BuilderDeleteOne {
|
|
bdo.bd.mutation.Where(ps...)
|
|
return bdo
|
|
}
|
|
|
|
// Exec executes the deletion query.
|
|
func (bdo *BuilderDeleteOne) Exec(ctx context.Context) error {
|
|
n, err := bdo.bd.Exec(ctx)
|
|
switch {
|
|
case err != nil:
|
|
return err
|
|
case n == 0:
|
|
return &NotFoundError{builder.Label}
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (bdo *BuilderDeleteOne) ExecX(ctx context.Context) {
|
|
if err := bdo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|