代码拉取完成,页面将自动刷新
// 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"
"time"
"gitee.com/damengde/ent/dialect/gremlin"
"gitee.com/damengde/ent/dialect/gremlin/graph/dsl"
"gitee.com/damengde/ent/dialect/gremlin/graph/dsl/__"
"gitee.com/damengde/ent/dialect/gremlin/graph/dsl/g"
"gitee.com/damengde/ent/dialect/gremlin/graph/dsl/p"
"gitee.com/damengde/ent/entc/integration/gremlin/ent/node"
)
// NodeCreate is the builder for creating a Node entity.
type NodeCreate struct {
config
mutation *NodeMutation
hooks []Hook
}
// SetValue sets the "value" field.
func (nc *NodeCreate) SetValue(i int) *NodeCreate {
nc.mutation.SetValue(i)
return nc
}
// SetNillableValue sets the "value" field if the given value is not nil.
func (nc *NodeCreate) SetNillableValue(i *int) *NodeCreate {
if i != nil {
nc.SetValue(*i)
}
return nc
}
// SetUpdatedAt sets the "updated_at" field.
func (nc *NodeCreate) SetUpdatedAt(t time.Time) *NodeCreate {
nc.mutation.SetUpdatedAt(t)
return nc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (nc *NodeCreate) SetNillableUpdatedAt(t *time.Time) *NodeCreate {
if t != nil {
nc.SetUpdatedAt(*t)
}
return nc
}
// SetPrevID sets the "prev" edge to the Node entity by ID.
func (nc *NodeCreate) SetPrevID(id string) *NodeCreate {
nc.mutation.SetPrevID(id)
return nc
}
// SetNillablePrevID sets the "prev" edge to the Node entity by ID if the given value is not nil.
func (nc *NodeCreate) SetNillablePrevID(id *string) *NodeCreate {
if id != nil {
nc = nc.SetPrevID(*id)
}
return nc
}
// SetPrev sets the "prev" edge to the Node entity.
func (nc *NodeCreate) SetPrev(n *Node) *NodeCreate {
return nc.SetPrevID(n.ID)
}
// SetNextID sets the "next" edge to the Node entity by ID.
func (nc *NodeCreate) SetNextID(id string) *NodeCreate {
nc.mutation.SetNextID(id)
return nc
}
// SetNillableNextID sets the "next" edge to the Node entity by ID if the given value is not nil.
func (nc *NodeCreate) SetNillableNextID(id *string) *NodeCreate {
if id != nil {
nc = nc.SetNextID(*id)
}
return nc
}
// SetNext sets the "next" edge to the Node entity.
func (nc *NodeCreate) SetNext(n *Node) *NodeCreate {
return nc.SetNextID(n.ID)
}
// Mutation returns the NodeMutation object of the builder.
func (nc *NodeCreate) Mutation() *NodeMutation {
return nc.mutation
}
// Save creates the Node in the database.
func (nc *NodeCreate) Save(ctx context.Context) (*Node, error) {
return withHooks(ctx, nc.gremlinSave, nc.mutation, nc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (nc *NodeCreate) SaveX(ctx context.Context) *Node {
v, err := nc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (nc *NodeCreate) Exec(ctx context.Context) error {
_, err := nc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (nc *NodeCreate) ExecX(ctx context.Context) {
if err := nc.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (nc *NodeCreate) check() error {
return nil
}
func (nc *NodeCreate) gremlinSave(ctx context.Context) (*Node, error) {
if err := nc.check(); err != nil {
return nil, err
}
res := &gremlin.Response{}
query, bindings := nc.gremlin().Query()
if err := nc.driver.Exec(ctx, query, bindings, res); err != nil {
return nil, err
}
if err, ok := isConstantError(res); ok {
return nil, err
}
rnode := &Node{config: nc.config}
if err := rnode.FromResponse(res); err != nil {
return nil, err
}
nc.mutation.id = &rnode.ID
nc.mutation.done = true
return rnode, nil
}
func (nc *NodeCreate) gremlin() *dsl.Traversal {
type constraint struct {
pred *dsl.Traversal // constraint predicate.
test *dsl.Traversal // test matches and its constant.
}
constraints := make([]*constraint, 0, 2)
v := g.AddV(node.Label)
if value, ok := nc.mutation.Value(); ok {
v.Property(dsl.Single, node.FieldValue, value)
}
if value, ok := nc.mutation.UpdatedAt(); ok {
v.Property(dsl.Single, node.FieldUpdatedAt, value)
}
for _, id := range nc.mutation.PrevIDs() {
v.AddE(node.NextLabel).From(g.V(id)).InV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(node.NextLabel).OutV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(node.Label, node.NextLabel, id)),
})
}
for _, id := range nc.mutation.NextIDs() {
v.AddE(node.NextLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(node.NextLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(node.Label, node.NextLabel, id)),
})
}
if len(constraints) == 0 {
return v.ValueMap(true)
}
tr := constraints[0].pred.Coalesce(constraints[0].test, v.ValueMap(true))
for _, cr := range constraints[1:] {
tr = cr.pred.Coalesce(cr.test, tr)
}
return tr
}
// NodeCreateBulk is the builder for creating many Node entities in bulk.
type NodeCreateBulk struct {
config
err error
builders []*NodeCreate
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。