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

@@ -103,7 +103,7 @@ func (cc *CityCreate) check() error {
}
func (cc *CityCreate) sqlSave(ctx context.Context) (*City, error) {
c, _spec := cc.createSpec()
_node, _spec := cc.createSpec()
if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
@@ -111,13 +111,13 @@ func (cc *CityCreate) sqlSave(ctx context.Context) (*City, error) {
return nil, err
}
id := _spec.ID.Value.(int64)
c.ID = int(id)
return c, nil
_node.ID = int(id)
return _node, nil
}
func (cc *CityCreate) createSpec() (*City, *sqlgraph.CreateSpec) {
var (
c = &City{config: cc.config}
_node = &City{config: cc.config}
_spec = &sqlgraph.CreateSpec{
Table: city.Table,
ID: &sqlgraph.FieldSpec{
@@ -132,7 +132,7 @@ func (cc *CityCreate) createSpec() (*City, *sqlgraph.CreateSpec) {
Value: value,
Column: city.FieldName,
})
c.Name = value
_node.Name = value
}
if nodes := cc.mutation.StreetsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
@@ -153,7 +153,7 @@ func (cc *CityCreate) createSpec() (*City, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
return c, _spec
return _node, _spec
}
// CityCreateBulk is the builder for creating a bulk of City entities.

View File

@@ -84,23 +84,23 @@ func (cq *CityQuery) QueryStreets() *StreetQuery {
// First returns the first City entity in the query. Returns *NotFoundError when no city was found.
func (cq *CityQuery) First(ctx context.Context) (*City, error) {
cs, err := cq.Limit(1).All(ctx)
nodes, err := cq.Limit(1).All(ctx)
if err != nil {
return nil, err
}
if len(cs) == 0 {
if len(nodes) == 0 {
return nil, &NotFoundError{city.Label}
}
return cs[0], nil
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (cq *CityQuery) FirstX(ctx context.Context) *City {
c, err := cq.First(ctx)
node, err := cq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return c
return node
}
// FirstID returns the first City id in the query. Returns *NotFoundError when no id was found.
@@ -127,13 +127,13 @@ func (cq *CityQuery) FirstXID(ctx context.Context) int {
// Only returns the only City entity in the query, returns an error if not exactly one entity was returned.
func (cq *CityQuery) Only(ctx context.Context) (*City, error) {
cs, err := cq.Limit(2).All(ctx)
nodes, err := cq.Limit(2).All(ctx)
if err != nil {
return nil, err
}
switch len(cs) {
switch len(nodes) {
case 1:
return cs[0], nil
return nodes[0], nil
case 0:
return nil, &NotFoundError{city.Label}
default:
@@ -143,11 +143,11 @@ func (cq *CityQuery) Only(ctx context.Context) (*City, error) {
// OnlyX is like Only, but panics if an error occurs.
func (cq *CityQuery) OnlyX(ctx context.Context) *City {
c, err := cq.Only(ctx)
node, err := cq.Only(ctx)
if err != nil {
panic(err)
}
return c
return node
}
// OnlyID returns the only City id in the query, returns an error if not exactly one id was returned.
@@ -186,11 +186,11 @@ func (cq *CityQuery) All(ctx context.Context) ([]*City, error) {
// AllX is like All, but panics if an error occurs.
func (cq *CityQuery) AllX(ctx context.Context) []*City {
cs, err := cq.All(ctx)
nodes, err := cq.All(ctx)
if err != nil {
panic(err)
}
return cs
return nodes
}
// IDs executes the query and returns a list of City ids.

View File

@@ -305,11 +305,11 @@ func (cuo *CityUpdateOne) Save(ctx context.Context) (*City, error) {
// SaveX is like Save, but panics if an error occurs.
func (cuo *CityUpdateOne) SaveX(ctx context.Context) *City {
c, err := cuo.Save(ctx)
node, err := cuo.Save(ctx)
if err != nil {
panic(err)
}
return c
return node
}
// Exec executes the query on the entity.
@@ -325,7 +325,7 @@ func (cuo *CityUpdateOne) ExecX(ctx context.Context) {
}
}
func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (c *City, err error) {
func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (_node *City, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: city.Table,
@@ -402,9 +402,9 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (c *City, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
c = &City{config: cuo.config}
_spec.Assign = c.assignValues
_spec.ScanValues = c.scanValues()
_node = &City{config: cuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues()
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{city.Label}
@@ -413,5 +413,5 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (c *City, err error) {
}
return nil, err
}
return c, nil
return _node, nil
}

View File

@@ -107,7 +107,7 @@ func (sc *StreetCreate) check() error {
}
func (sc *StreetCreate) sqlSave(ctx context.Context) (*Street, error) {
s, _spec := sc.createSpec()
_node, _spec := sc.createSpec()
if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
@@ -115,13 +115,13 @@ func (sc *StreetCreate) sqlSave(ctx context.Context) (*Street, error) {
return nil, err
}
id := _spec.ID.Value.(int64)
s.ID = int(id)
return s, nil
_node.ID = int(id)
return _node, nil
}
func (sc *StreetCreate) createSpec() (*Street, *sqlgraph.CreateSpec) {
var (
s = &Street{config: sc.config}
_node = &Street{config: sc.config}
_spec = &sqlgraph.CreateSpec{
Table: street.Table,
ID: &sqlgraph.FieldSpec{
@@ -136,7 +136,7 @@ func (sc *StreetCreate) createSpec() (*Street, *sqlgraph.CreateSpec) {
Value: value,
Column: street.FieldName,
})
s.Name = value
_node.Name = value
}
if nodes := sc.mutation.CityIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
@@ -157,7 +157,7 @@ func (sc *StreetCreate) createSpec() (*Street, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
return s, _spec
return _node, _spec
}
// StreetCreateBulk is the builder for creating a bulk of Street entities.

View File

@@ -84,23 +84,23 @@ func (sq *StreetQuery) QueryCity() *CityQuery {
// First returns the first Street entity in the query. Returns *NotFoundError when no street was found.
func (sq *StreetQuery) First(ctx context.Context) (*Street, error) {
sSlice, err := sq.Limit(1).All(ctx)
nodes, err := sq.Limit(1).All(ctx)
if err != nil {
return nil, err
}
if len(sSlice) == 0 {
if len(nodes) == 0 {
return nil, &NotFoundError{street.Label}
}
return sSlice[0], nil
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (sq *StreetQuery) FirstX(ctx context.Context) *Street {
s, err := sq.First(ctx)
node, err := sq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return s
return node
}
// FirstID returns the first Street id in the query. Returns *NotFoundError when no id was found.
@@ -127,13 +127,13 @@ func (sq *StreetQuery) FirstXID(ctx context.Context) int {
// Only returns the only Street entity in the query, returns an error if not exactly one entity was returned.
func (sq *StreetQuery) Only(ctx context.Context) (*Street, error) {
sSlice, err := sq.Limit(2).All(ctx)
nodes, err := sq.Limit(2).All(ctx)
if err != nil {
return nil, err
}
switch len(sSlice) {
switch len(nodes) {
case 1:
return sSlice[0], nil
return nodes[0], nil
case 0:
return nil, &NotFoundError{street.Label}
default:
@@ -143,11 +143,11 @@ func (sq *StreetQuery) Only(ctx context.Context) (*Street, error) {
// OnlyX is like Only, but panics if an error occurs.
func (sq *StreetQuery) OnlyX(ctx context.Context) *Street {
s, err := sq.Only(ctx)
node, err := sq.Only(ctx)
if err != nil {
panic(err)
}
return s
return node
}
// OnlyID returns the only Street id in the query, returns an error if not exactly one id was returned.
@@ -186,11 +186,11 @@ func (sq *StreetQuery) All(ctx context.Context) ([]*Street, error) {
// AllX is like All, but panics if an error occurs.
func (sq *StreetQuery) AllX(ctx context.Context) []*Street {
sSlice, err := sq.All(ctx)
nodes, err := sq.All(ctx)
if err != nil {
panic(err)
}
return sSlice
return nodes
}
// IDs executes the query and returns a list of Street ids.

View File

@@ -264,11 +264,11 @@ func (suo *StreetUpdateOne) Save(ctx context.Context) (*Street, error) {
// SaveX is like Save, but panics if an error occurs.
func (suo *StreetUpdateOne) SaveX(ctx context.Context) *Street {
s, err := suo.Save(ctx)
node, err := suo.Save(ctx)
if err != nil {
panic(err)
}
return s
return node
}
// Exec executes the query on the entity.
@@ -284,7 +284,7 @@ func (suo *StreetUpdateOne) ExecX(ctx context.Context) {
}
}
func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (s *Street, err error) {
func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (_node *Street, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: street.Table,
@@ -342,9 +342,9 @@ func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (s *Street, err error)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
s = &Street{config: suo.config}
_spec.Assign = s.assignValues
_spec.ScanValues = s.scanValues()
_node = &Street{config: suo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues()
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{street.Label}
@@ -353,5 +353,5 @@ func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (s *Street, err error)
}
return nil, err
}
return s, nil
return _node, nil
}