From e3dc7ee01c86f56d5ddc63a900fed0d9c2020560 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 18 Dec 2024 01:16:24 +0200 Subject: [PATCH] dbutil: add QueryManyIter to QueryHelper --- dbutil/queryhelper.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dbutil/queryhelper.go b/dbutil/queryhelper.go index 89692e7..5e33722 100644 --- a/dbutil/queryhelper.go +++ b/dbutil/queryhelper.go @@ -126,9 +126,12 @@ func (qh *QueryHelper[T]) QueryOne(ctx context.Context, query string, args ...an // to scan each row, and returns the values. If the query returns no rows, it // returns a non-nil zero-length slice and no error. func (qh *QueryHelper[T]) QueryMany(ctx context.Context, query string, args ...any) ([]T, error) { + return qh.QueryManyIter(ctx, query, args...).AsList() +} + +// QueryManyIter executes a query with QueryContext and returns a RowIter +// that will use the associated DataStruct to scan each row. +func (qh *QueryHelper[T]) QueryManyIter(ctx context.Context, query string, args ...any) RowIter[T] { rows, err := qh.db.Query(ctx, query, args...) - if err != nil { - return nil, err - } - return NewRowIter(rows, qh.scanNew).AsList() + return NewRowIterWithError(rows, qh.scanNew, err) }