-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiterator.go
35 lines (30 loc) · 904 Bytes
/
iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package djoemo
import (
"context"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/guregu/dynamo"
)
// IteratorInterface ...
type IteratorInterface interface {
NextItem(out interface{}) bool
}
// Iterator ...
type Iterator struct {
scan *dynamo.Scan
tableName string
searchLimit int64
lastEvaluatedKey map[string]*dynamodb.AttributeValue
iterator dynamo.PagingIter
dynamoClient *dynamo.DB
ctx context.Context
}
// NextItem unmarshals the next item into out and returns if there are more items following
func (itr *Iterator) NextItem(out interface{}) bool {
more := itr.iterator.NextWithContext(itr.ctx, out)
if !more && itr.iterator.LastEvaluatedKey() != nil {
itr.scan = itr.scan.StartFrom(itr.iterator.LastEvaluatedKey())
itr.iterator = itr.scan.Iter()
return itr.iterator.NextWithContext(itr.ctx, out)
}
return more
}