Ignore empty errors on postgres upsert fail
- Postgres's behavior when there is no update is that there is an ErrNoRows thrown back, which we can safely ignore since the only time this can happen in postgres's case is under this circumstance since there's no race unlike the mysql upsert code. - Fix #84
This commit is contained in:
parent
4ae9336538
commit
22f7a45847
1 changed files with 4 additions and 1 deletions
|
@ -181,11 +181,14 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, {{if ne .DriverName
|
|||
{{- else}}
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRow(cache.query, vals...).Scan(returns...)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil // Postgres doesn't return anything when there's no update
|
||||
}
|
||||
} else {
|
||||
_, err = exec.Exec(cache.query, vals...)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "{{.PkgName}}: unable to upsert for {{.Table.Name}}")
|
||||
return errors.Wrap(err, "{{.PkgName}}: unable to upsert {{.Table.Name}}")
|
||||
}
|
||||
{{- end}}
|
||||
|
||||
|
|
Loading…
Reference in a new issue