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

@@ -96,7 +96,9 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) ({{ $ret }}
{{- else }}
if {{ $ret }}, err = sqlgraph.UpdateNodes(ctx, {{ $receiver }}.driver, _spec); err != nil {
{{- end }}
if cerr, ok := isSQLConstraintError(err); ok {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{ {{ $.Package }}.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return {{ $zero }}, err