entc/gen: less sophisticated naming logic (#774)

Closed #772
This commit is contained in:
Ariel Mashraki
2020-09-17 09:19:55 +03:00
committed by GitHub
parent 235973cc2d
commit 17abe2d60f
225 changed files with 5542 additions and 1679 deletions

View File

@@ -121,7 +121,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
@@ -129,13 +129,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{
@@ -150,7 +150,7 @@ func (nc *NodeCreate) createSpec() (*Node, *sqlgraph.CreateSpec) {
Value: value,
Column: node.FieldValue,
})
n.Value = value
_node.Value = value
}
if nodes := nc.mutation.ParentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
@@ -190,7 +190,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.

View File

@@ -107,23 +107,23 @@ func (nq *NodeQuery) QueryChildren() *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.

View File

@@ -410,11 +410,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.
@@ -430,7 +430,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,
@@ -549,9 +549,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}
@@ -560,5 +560,5 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
}
return nil, err
}
return n, nil
return _node, nil
}