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

@@ -295,7 +295,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
@@ -567,7 +569,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

@@ -195,7 +195,9 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) {
})
}
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{comment.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -373,7 +375,9 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (c *Comment, 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{comment.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -1166,7 +1166,9 @@ func (ftu *FieldTypeUpdate) sqlSave(ctx context.Context) (n int, err error) {
})
}
if n, err = sqlgraph.UpdateNodes(ctx, ftu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{fieldtype.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -2314,7 +2316,9 @@ func (ftuo *FieldTypeUpdateOne) sqlSave(ctx context.Context) (ft *FieldType, err
_spec.Assign = ft.assignValues
_spec.ScanValues = ft.scanValues()
if err = sqlgraph.UpdateNode(ctx, ftuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{fieldtype.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -355,7 +355,9 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, fu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{file.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -688,7 +690,9 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (f *File, err error) {
_spec.Assign = f.assignValues
_spec.ScanValues = f.scanValues()
if err = sqlgraph.UpdateNode(ctx, fuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{file.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -178,7 +178,9 @@ func (ftu *FileTypeUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, ftu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{filetype.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -337,7 +339,9 @@ func (ftuo *FileTypeUpdateOne) sqlSave(ctx context.Context) (ft *FileType, err e
_spec.Assign = ft.assignValues
_spec.ScanValues = ft.scanValues()
if err = sqlgraph.UpdateNode(ctx, ftuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{filetype.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -568,7 +568,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
@@ -1112,7 +1114,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

@@ -219,7 +219,9 @@ func (giu *GroupInfoUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, giu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{groupinfo.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -419,7 +421,9 @@ func (giuo *GroupInfoUpdateOne) sqlSave(ctx context.Context) (gi *GroupInfo, err
_spec.Assign = gi.assignValues
_spec.ScanValues = gi.scanValues()
if err = sqlgraph.UpdateNode(ctx, giuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{groupinfo.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -74,7 +74,9 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) {
}
}
if n, err = sqlgraph.UpdateNodes(ctx, iu.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{item.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -131,7 +133,9 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (i *Item, err error) {
_spec.Assign = i.assignValues
_spec.ScanValues = i.scanValues()
if err = sqlgraph.UpdateNode(ctx, iuo.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{item.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -275,7 +275,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
@@ -531,7 +533,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

@@ -235,7 +235,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
@@ -450,7 +452,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

@@ -164,7 +164,9 @@ func (su *SpecUpdate) 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{spec.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
@@ -309,7 +311,9 @@ func (suo *SpecUpdateOne) sqlSave(ctx context.Context) (s *Spec, 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{spec.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err

View File

@@ -1249,7 +1249,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
@@ -2474,7 +2476,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