diff --git a/rows.go b/rows.go index f6f26f479..0d1d3e9c6 100644 --- a/rows.go +++ b/rows.go @@ -451,6 +451,15 @@ func CollectRows[T any](rows Rows, fn RowToFunc[T]) ([]T, error) { return AppendRows([]T{}, rows, fn) } +// CollectRowsInto is the same as [CollectRows] but allows +// defining a custom slice type. Useful when you have custom +// types to denote slices. +// +// This function closes the rows automatically on return. +func CollectRowsInto[S ~[]T, T any](rows Rows, fn RowToFunc[T]) (S, error) { + return CollectRows(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. // CollectOneRow is to CollectRows as QueryRow is to Query. //