Improve error reporting from db package
This commit is contained in:
parent
9edfb21a98
commit
3067b3fc3e
16
src/db/db.go
16
src/db/db.go
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue