update to latest bstore

This commit is contained in:
Mechiel Lukkien
2025-03-28 17:34:57 +01:00
parent 6bf80d91bc
commit 789e4875ca
4 changed files with 30 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"iter"
"reflect"
"slices"
@ -1233,3 +1234,27 @@ func (q *Query[T]) ForEach(fn func(value T) error) (rerr error) {
return fn(v)
})
}
// All returns an iterator over all selected records.
//
// All automatically respositions the cursor when data is changed while iterating.
// Changes to data aren't necessarily reflected in the yielded values. This can
// happen when a sort order isn't executed using an index: All gathers and sorts (a
// subset of) values before yielding them and does not reapply filtering and does
// not necessarily yield the updated values.
func (q *Query[T]) All() iter.Seq2[T, error] {
return func(yield func(T, error) bool) {
var stopped bool
err := q.ForEach(func(v T) error {
if !yield(v, nil) {
stopped = true
return StopForEach
}
return nil
})
if !stopped && err != nil {
var zero T
yield(zero, err)
}
}
}