Improve error reporting from db package

This commit is contained in:
Ben Visness 2022-07-16 13:23:06 -05:00
parent 9edfb21a98
commit 3067b3fc3e
1 changed files with 14 additions and 2 deletions

View File

@ -158,7 +158,11 @@ func QueryOne[T any](
result, hasRow := rows.Next()
if !hasRow {
return nil, NotFound
if readErr := rows.Err(); readErr != nil {
return nil, readErr
} else {
return nil, NotFound
}
}
return result, nil
@ -244,7 +248,11 @@ func QueryOneScalar[T any](
result, hasRow := rows.Next()
if !hasRow {
var zero T
return zero, NotFound
if readErr := rows.Err(); readErr != nil {
return zero, readErr
} else {
return zero, NotFound
}
}
return *result, nil
@ -585,6 +593,10 @@ func (it *Iterator[T]) Next() (*T, bool) {
}
}
func (it *Iterator[T]) Err() error {
return it.rows.Err()
}
// Takes a value from a database query (reflected) and assigns it to the
// destination. If the destination is a pointer, and the value is non-nil, it
// will initialize the destination before assigning.