Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down