Skip to content

Commit

Permalink
dbutil: add QueryManyIter to QueryHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 17, 2024
1 parent 4aa8973 commit e3dc7ee
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dbutil/queryhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit e3dc7ee

Please sign in to comment.