From 389931396eea77f4e4b369f659a33b2bff179ae5 Mon Sep 17 00:00:00 2001 From: Julien GOTTELAND Date: Sat, 19 Aug 2023 23:18:29 +0200 Subject: [PATCH] No data result on error --- rows.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rows.go b/rows.go index a58cc7ee..c4c7ee0f 100644 --- a/rows.go +++ b/rows.go @@ -467,7 +467,7 @@ func CollectOneRow[T any](rows Rows, fn RowToFunc[T]) (T, error) { // CollectExactlyOneRow calls fn for the first row in rows and returns the result. // - If no rows are found returns an error where errors.Is(ErrNoRows) is true. -// - If more than 1 row is found returns the first result and an error where errors.Is(ErrTooManyRows) is true. +// - If more than 1 row is found returns an error where errors.Is(ErrTooManyRows) is true. func CollectExactlyOneRow[T any](rows Rows, fn RowToFunc[T]) (T, error) { defer rows.Close() @@ -490,7 +490,9 @@ func CollectExactlyOneRow[T any](rows Rows, fn RowToFunc[T]) (T, error) { } if rows.Next() { - return value, ErrTooManyRows + var zero T + + return zero, ErrTooManyRows } return value, rows.Err()