entc/gen: use NotFoundError when updating non-exist node (#348)

Fixes #341
This commit is contained in:
Ariel Mashraki
2020-02-16 13:26:13 +02:00
committed by GitHub
parent 14ccf7b7fc
commit d9c8d9545d
52 changed files with 309 additions and 100 deletions

View File

@@ -169,7 +169,9 @@ func (cu *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{city.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -320,7 +322,9 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (c *City, err error) {
_spec.Assign = c.assignValues
_spec.ScanValues = c.scanValues()
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{city.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -158,7 +158,9 @@ func (su *StreetUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{street.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -297,7 +299,9 @@ func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (s *Street, err error)
_spec.Assign = s.assignValues
_spec.ScanValues = s.scanValues()
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{street.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -74,7 +74,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
}
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -131,7 +133,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -169,7 +169,9 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, gu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{group.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -320,7 +322,9 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) {
_spec.Assign = gr.assignValues
_spec.ScanValues = gr.scanValues()
if err = sqlgraph.UpdateNode(ctx, guo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{group.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -202,7 +202,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -386,7 +388,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -201,7 +201,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -385,7 +387,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -281,7 +281,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -545,7 +547,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -158,7 +158,9 @@ func (pu *PetUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{pet.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -297,7 +299,9 @@ func (puo *PetUpdateOne) sqlSave(ctx context.Context) (pe *Pet, err error) {
_spec.Assign = pe.assignValues
_spec.ScanValues = pe.scanValues()
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{pet.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -202,7 +202,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -386,7 +388,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -256,7 +256,9 @@ func (nu *NodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, nu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{node.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -494,7 +496,9 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
_spec.Assign = n.assignValues
_spec.ScanValues = n.scanValues()
if err = sqlgraph.UpdateNode(ctx, nuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{node.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -168,7 +168,9 @@ func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{card.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -316,7 +318,9 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (c *Card, err error) {
_spec.Assign = c.assignValues
_spec.ScanValues = c.scanValues()
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{card.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -191,7 +191,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -363,7 +365,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -190,7 +190,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -362,7 +364,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -244,7 +244,9 @@ func (nu *NodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, nu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{node.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -470,7 +472,9 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
_spec.Assign = n.assignValues
_spec.ScanValues = n.scanValues()
if err = sqlgraph.UpdateNode(ctx, nuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{node.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -173,7 +173,9 @@ func (cu *CarUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{car.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -326,7 +328,9 @@ func (cuo *CarUpdateOne) sqlSave(ctx context.Context) (c *Car, err error) {
_spec.Assign = c.assignValues
_spec.ScanValues = c.scanValues()
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{car.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -175,7 +175,9 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, gu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{group.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -331,7 +333,9 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) {
_spec.Assign = gr.assignValues
_spec.ScanValues = gr.scanValues()
if err = sqlgraph.UpdateNode(ctx, guo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{group.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -297,7 +297,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -574,7 +576,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -238,7 +238,9 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, gu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{group.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -457,7 +459,9 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) {
_spec.Assign = gr.assignValues
_spec.ScanValues = gr.scanValues()
if err = sqlgraph.UpdateNode(ctx, guo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{group.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -238,7 +238,9 @@ func (pu *PetUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{pet.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -457,7 +459,9 @@ func (puo *PetUpdateOne) sqlSave(ctx context.Context) (pe *Pet, err error) {
_spec.Assign = pe.assignValues
_spec.ScanValues = pe.scanValues()
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{pet.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -443,7 +443,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -867,7 +869,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
_spec.Assign = u.assignValues
_spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err