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

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

View File

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

View File

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

View File

@@ -112,7 +112,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
@@ -120,13 +120,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{
@@ -141,7 +141,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{
@@ -149,7 +149,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
Value: value,
Column: user.FieldName,
})
u.Name = value
_node.Name = value
}
if nodes := uc.mutation.PetsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
@@ -170,7 +170,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

@@ -84,23 +84,23 @@ func (uq *UserQuery) QueryPets() *PetQuery {
// 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.
@@ -127,13 +127,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:
@@ -143,11 +143,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.
@@ -186,11 +186,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

@@ -345,11 +345,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.
@@ -365,7 +365,7 @@ func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
}
}
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,
@@ -456,9 +456,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}
@@ -467,5 +467,5 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
}
return nil, err
}
return u, nil
return _node, nil
}