Skip to content

Commit

Permalink
Fix behavior of CollectRows to return empty slice if Rows are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
its-felix authored and jackc committed Mar 3, 2024
1 parent 88dfc22 commit c1b0a01
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func AppendRows[T any, S ~[]T](slice S, rows Rows, fn RowToFunc[T]) (S, error) {

// CollectRows iterates through rows, calling fn for each row, and collecting the results into a slice of T.
func CollectRows[T any](rows Rows, fn RowToFunc[T]) ([]T, error) {
return AppendRows([]T(nil), rows, fn)
return AppendRows([]T{}, rows, fn)
}

// CollectOneRow 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.
Expand Down

0 comments on commit c1b0a01

Please sign in to comment.