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

@@ -117,7 +117,7 @@ func (cc *CarCreate) check() error {
}
func (cc *CarCreate) sqlSave(ctx context.Context) (*Car, 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
@@ -125,13 +125,13 @@ func (cc *CarCreate) sqlSave(ctx context.Context) (*Car, 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 *CarCreate) createSpec() (*Car, *sqlgraph.CreateSpec) {
var (
c = &Car{config: cc.config}
_node = &Car{config: cc.config}
_spec = &sqlgraph.CreateSpec{
Table: car.Table,
ID: &sqlgraph.FieldSpec{
@@ -146,7 +146,7 @@ func (cc *CarCreate) createSpec() (*Car, *sqlgraph.CreateSpec) {
Value: value,
Column: car.FieldModel,
})
c.Model = value
_node.Model = value
}
if value, ok := cc.mutation.RegisteredAt(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
@@ -154,7 +154,7 @@ func (cc *CarCreate) createSpec() (*Car, *sqlgraph.CreateSpec) {
Value: value,
Column: car.FieldRegisteredAt,
})
c.RegisteredAt = value
_node.RegisteredAt = value
}
if nodes := cc.mutation.OwnerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
@@ -175,7 +175,7 @@ func (cc *CarCreate) createSpec() (*Car, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
return c, _spec
return _node, _spec
}
// CarCreateBulk is the builder for creating a bulk of Car entities.

View File

@@ -84,23 +84,23 @@ func (cq *CarQuery) QueryOwner() *UserQuery {
// First returns the first Car entity in the query. Returns *NotFoundError when no car was found.
func (cq *CarQuery) First(ctx context.Context) (*Car, 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{car.Label}
}
return cs[0], nil
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (cq *CarQuery) FirstX(ctx context.Context) *Car {
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 Car id in the query. Returns *NotFoundError when no id was found.
@@ -127,13 +127,13 @@ func (cq *CarQuery) FirstXID(ctx context.Context) int {
// Only returns the only Car entity in the query, returns an error if not exactly one entity was returned.
func (cq *CarQuery) Only(ctx context.Context) (*Car, 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{car.Label}
default:
@@ -143,11 +143,11 @@ func (cq *CarQuery) Only(ctx context.Context) (*Car, error) {
// OnlyX is like Only, but panics if an error occurs.
func (cq *CarQuery) OnlyX(ctx context.Context) *Car {
c, err := cq.Only(ctx)
node, err := cq.Only(ctx)
if err != nil {
panic(err)
}
return c
return node
}
// OnlyID returns the only Car id in the query, returns an error if not exactly one id was returned.
@@ -186,11 +186,11 @@ func (cq *CarQuery) All(ctx context.Context) ([]*Car, error) {
// AllX is like All, but panics if an error occurs.
func (cq *CarQuery) AllX(ctx context.Context) []*Car {
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 Car ids.

View File

@@ -284,11 +284,11 @@ func (cuo *CarUpdateOne) Save(ctx context.Context) (*Car, error) {
// SaveX is like Save, but panics if an error occurs.
func (cuo *CarUpdateOne) SaveX(ctx context.Context) *Car {
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.
@@ -304,7 +304,7 @@ func (cuo *CarUpdateOne) ExecX(ctx context.Context) {
}
}
func (cuo *CarUpdateOne) sqlSave(ctx context.Context) (c *Car, err error) {
func (cuo *CarUpdateOne) sqlSave(ctx context.Context) (_node *Car, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: car.Table,
@@ -369,9 +369,9 @@ func (cuo *CarUpdateOne) sqlSave(ctx context.Context) (c *Car, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
c = &Car{config: cuo.config}
_spec.Assign = c.assignValues
_spec.ScanValues = c.scanValues()
_node = &Car{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{car.Label}
@@ -380,5 +380,5 @@ func (cuo *CarUpdateOne) sqlSave(ctx context.Context) (c *Car, err error) {
}
return nil, err
}
return c, nil
return _node, nil
}

View File

@@ -108,7 +108,7 @@ func (gc *GroupCreate) check() error {
}
func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) {
gr, _spec := gc.createSpec()
_node, _spec := gc.createSpec()
if err := sqlgraph.CreateNode(ctx, gc.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
@@ -116,13 +116,13 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) {
return nil, err
}
id := _spec.ID.Value.(int64)
gr.ID = int(id)
return gr, nil
_node.ID = int(id)
return _node, nil
}
func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
var (
gr = &Group{config: gc.config}
_node = &Group{config: gc.config}
_spec = &sqlgraph.CreateSpec{
Table: group.Table,
ID: &sqlgraph.FieldSpec{
@@ -137,7 +137,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
Value: value,
Column: group.FieldName,
})
gr.Name = value
_node.Name = value
}
if nodes := gc.mutation.UsersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
@@ -158,7 +158,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
return gr, _spec
return _node, _spec
}
// GroupCreateBulk is the builder for creating a bulk of Group entities.

View File

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

View File

@@ -327,11 +327,11 @@ func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
// SaveX is like Save, but panics if an error occurs.
func (guo *GroupUpdateOne) SaveX(ctx context.Context) *Group {
gr, err := guo.Save(ctx)
node, err := guo.Save(ctx)
if err != nil {
panic(err)
}
return gr
return node
}
// Exec executes the query on the entity.
@@ -357,7 +357,7 @@ func (guo *GroupUpdateOne) check() error {
return nil
}
func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) {
func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: group.Table,
@@ -434,9 +434,9 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
gr = &Group{config: guo.config}
_spec.Assign = gr.assignValues
_spec.ScanValues = gr.scanValues()
_node = &Group{config: guo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues()
if err = sqlgraph.UpdateNode(ctx, guo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{group.Label}
@@ -445,5 +445,5 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) {
}
return nil, err
}
return gr, nil
return _node, nil
}

View File

@@ -150,7 +150,7 @@ func (uc *UserCreate) check() error {
}
func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
u, _spec := uc.createSpec()
_node, _spec := uc.createSpec()
if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
@@ -158,13 +158,13 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
return nil, err
}
id := _spec.ID.Value.(int64)
u.ID = int(id)
return u, nil
_node.ID = int(id)
return _node, nil
}
func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
var (
u = &User{config: uc.config}
_node = &User{config: uc.config}
_spec = &sqlgraph.CreateSpec{
Table: user.Table,
ID: &sqlgraph.FieldSpec{
@@ -179,7 +179,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
Value: value,
Column: user.FieldAge,
})
u.Age = value
_node.Age = value
}
if value, ok := uc.mutation.Name(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
@@ -187,7 +187,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
Value: value,
Column: user.FieldName,
})
u.Name = value
_node.Name = value
}
if nodes := uc.mutation.CarsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
@@ -227,7 +227,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
return u, _spec
return _node, _spec
}
// UserCreateBulk is the builder for creating a bulk of User entities.

View File

@@ -108,23 +108,23 @@ func (uq *UserQuery) QueryGroups() *GroupQuery {
// First returns the first User entity in the query. Returns *NotFoundError when no user was found.
func (uq *UserQuery) First(ctx context.Context) (*User, error) {
us, err := uq.Limit(1).All(ctx)
nodes, err := uq.Limit(1).All(ctx)
if err != nil {
return nil, err
}
if len(us) == 0 {
if len(nodes) == 0 {
return nil, &NotFoundError{user.Label}
}
return us[0], nil
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (uq *UserQuery) FirstX(ctx context.Context) *User {
u, err := uq.First(ctx)
node, err := uq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return u
return node
}
// FirstID returns the first User id in the query. Returns *NotFoundError when no id was found.
@@ -151,13 +151,13 @@ func (uq *UserQuery) FirstXID(ctx context.Context) int {
// Only returns the only User entity in the query, returns an error if not exactly one entity was returned.
func (uq *UserQuery) Only(ctx context.Context) (*User, error) {
us, err := uq.Limit(2).All(ctx)
nodes, err := uq.Limit(2).All(ctx)
if err != nil {
return nil, err
}
switch len(us) {
switch len(nodes) {
case 1:
return us[0], nil
return nodes[0], nil
case 0:
return nil, &NotFoundError{user.Label}
default:
@@ -167,11 +167,11 @@ func (uq *UserQuery) Only(ctx context.Context) (*User, error) {
// OnlyX is like Only, but panics if an error occurs.
func (uq *UserQuery) OnlyX(ctx context.Context) *User {
u, err := uq.Only(ctx)
node, err := uq.Only(ctx)
if err != nil {
panic(err)
}
return u
return node
}
// OnlyID returns the only User id in the query, returns an error if not exactly one id was returned.
@@ -210,11 +210,11 @@ func (uq *UserQuery) All(ctx context.Context) ([]*User, error) {
// AllX is like All, but panics if an error occurs.
func (uq *UserQuery) AllX(ctx context.Context) []*User {
us, err := uq.All(ctx)
nodes, err := uq.All(ctx)
if err != nil {
panic(err)
}
return us
return nodes
}
// IDs executes the query and returns a list of User ids.

View File

@@ -510,11 +510,11 @@ func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
// SaveX is like Save, but panics if an error occurs.
func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
u, err := uuo.Save(ctx)
node, err := uuo.Save(ctx)
if err != nil {
panic(err)
}
return u
return node
}
// Exec executes the query on the entity.
@@ -540,7 +540,7 @@ func (uuo *UserUpdateOne) check() error {
return nil
}
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: user.Table,
@@ -685,9 +685,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
u = &User{config: uuo.config}
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
_node = &User{config: uuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
@@ -696,5 +696,5 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
}
return nil, err
}
return u, nil
return _node, nil
}