mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
@@ -125,7 +125,7 @@ func (nc *NodeCreate) check() error {
|
||||
}
|
||||
|
||||
func (nc *NodeCreate) sqlSave(ctx context.Context) (*Node, error) {
|
||||
n, _spec := nc.createSpec()
|
||||
_node, _spec := nc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, nc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
@@ -133,13 +133,13 @@ func (nc *NodeCreate) sqlSave(ctx context.Context) (*Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
n.ID = int(id)
|
||||
return n, nil
|
||||
_node.ID = int(id)
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (nc *NodeCreate) createSpec() (*Node, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
n = &Node{config: nc.config}
|
||||
_node = &Node{config: nc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: node.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
@@ -154,7 +154,7 @@ func (nc *NodeCreate) createSpec() (*Node, *sqlgraph.CreateSpec) {
|
||||
Value: value,
|
||||
Column: node.FieldValue,
|
||||
})
|
||||
n.Value = value
|
||||
_node.Value = value
|
||||
}
|
||||
if nodes := nc.mutation.PrevIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -194,7 +194,7 @@ func (nc *NodeCreate) createSpec() (*Node, *sqlgraph.CreateSpec) {
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return n, _spec
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// NodeCreateBulk is the builder for creating a bulk of Node entities.
|
||||
|
||||
@@ -107,23 +107,23 @@ func (nq *NodeQuery) QueryNext() *NodeQuery {
|
||||
|
||||
// First returns the first Node entity in the query. Returns *NotFoundError when no node was found.
|
||||
func (nq *NodeQuery) First(ctx context.Context) (*Node, error) {
|
||||
ns, err := nq.Limit(1).All(ctx)
|
||||
nodes, err := nq.Limit(1).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(ns) == 0 {
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{node.Label}
|
||||
}
|
||||
return ns[0], nil
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (nq *NodeQuery) FirstX(ctx context.Context) *Node {
|
||||
n, err := nq.First(ctx)
|
||||
node, err := nq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Node id in the query. Returns *NotFoundError when no id was found.
|
||||
@@ -150,13 +150,13 @@ func (nq *NodeQuery) FirstXID(ctx context.Context) int {
|
||||
|
||||
// Only returns the only Node entity in the query, returns an error if not exactly one entity was returned.
|
||||
func (nq *NodeQuery) Only(ctx context.Context) (*Node, error) {
|
||||
ns, err := nq.Limit(2).All(ctx)
|
||||
nodes, err := nq.Limit(2).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(ns) {
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return ns[0], nil
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{node.Label}
|
||||
default:
|
||||
@@ -166,11 +166,11 @@ func (nq *NodeQuery) Only(ctx context.Context) (*Node, error) {
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (nq *NodeQuery) OnlyX(ctx context.Context) *Node {
|
||||
n, err := nq.Only(ctx)
|
||||
node, err := nq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID returns the only Node id in the query, returns an error if not exactly one id was returned.
|
||||
@@ -209,11 +209,11 @@ func (nq *NodeQuery) All(ctx context.Context) ([]*Node, error) {
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (nq *NodeQuery) AllX(ctx context.Context) []*Node {
|
||||
ns, err := nq.All(ctx)
|
||||
nodes, err := nq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ns
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Node ids.
|
||||
|
||||
@@ -369,11 +369,11 @@ func (nuo *NodeUpdateOne) Save(ctx context.Context) (*Node, error) {
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (nuo *NodeUpdateOne) SaveX(ctx context.Context) *Node {
|
||||
n, err := nuo.Save(ctx)
|
||||
node, err := nuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
@@ -389,7 +389,7 @@ func (nuo *NodeUpdateOne) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
|
||||
func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (_node *Node, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: node.Table,
|
||||
@@ -489,9 +489,9 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
n = &Node{config: nuo.config}
|
||||
_spec.Assign = n.assignValues
|
||||
_spec.ScanValues = n.scanValues()
|
||||
_node = &Node{config: nuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues()
|
||||
if err = sqlgraph.UpdateNode(ctx, nuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{node.Label}
|
||||
@@ -500,5 +500,5 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return n, nil
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user