-
Notifications
You must be signed in to change notification settings - Fork 152
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Is your feature request related to a problem? Please describe.
I think it is better that both of AggregateI and QueryI returns CursorI by same method.
Describe the solution you'd like
change AggregateI's interface to have Cursor() method.
// AggregateI define the interface of aggregate
type AggregateI interface {
All(results interface{}) error
One(result interface{}) error
Cursor() CursorI // not Iter()
}
Describe alternatives you've considered
QueryI has Iter() method.
Additional context
We have the interface in our application code
type Cursor = qmgo.CursorI
type Iterable interface { // the name Iterable is for historical reason (from mgo)
Cursor() Cursor
}
and, Iterate function is defined such as flowlings.
func Iterate(query Iterable, body func(Cursor) (next bool, _ error)) error {
cursor := query.Cursor()
defer cursor.Close() // nolint
if err := cursor.Err(); err != nil {
return err
}
for {
next, err := body(cursor)
if err != nil {
return err
}
if err := cursor.Err(); err != nil {
return err
}
if !next {
return nil
}
}
}
using Iterate(collection.Find(ctx, ...), func(...){...})
is OK but Iterate(collection.Aggregat(ctx, ...), func(...){...})
is NG.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request