forked from dugancathal/dynago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest_scan.go
119 lines (100 loc) · 3.03 KB
/
request_scan.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package dynago
type scanRequest struct {
queryRequest
Segment *int `json:",omitempty"`
TotalSegments *int `json:",omitempty"`
}
type Scan struct {
client *Client
req scanRequest
}
func newScan(c *Client, table string) *Scan {
req := scanRequest{queryRequest: queryRequest{TableName: table}}
return &Scan{c, req}
}
// ConsistentRead does a strongly consistent scan if strong is true. (defaults to false)
func (s Scan) ConsistentRead(strong bool) *Scan {
s.req.ConsistentRead = &strong
return &s
}
/*
ExclusiveStartKey sets the start key (effectively the offset cursor).
*/
func (s Scan) ExclusiveStartKey(key Document) *Scan {
s.req.ExclusiveStartKey = key
return &s
}
/*
FilterExpression post-filters results on this scan.
Scans with a FilterExpression may return 0 results due to scanning past
records which don't match the filter, but still have more results to get.
*/
func (s Scan) FilterExpression(expression string, params ...Params) *Scan {
s.req.FilterExpression = expression
s.req.paramsHelper(params)
return &s
}
// IndexName specifies a secondary index to scan instead of a table.
func (s Scan) IndexName(name string) *Scan {
s.req.IndexName = name
return &s
}
// Limit the maximum number of results to return per call.
func (s Scan) Limit(limit uint) *Scan {
s.req.Limit = limit
return &s
}
// ProjectionExpression allows the client to specify which attributes are returned.
func (s Scan) ProjectionExpression(expression string, params ...Params) *Scan {
s.req.ProjectionExpression = expression
s.req.paramsHelper(params)
return &s
}
// ReturnConsumedCapacity enables capacity reporting on this Query.
func (s Scan) ReturnConsumedCapacity(consumedCapacity CapacityDetail) *Scan {
s.req.ReturnConsumedCapacity = consumedCapacity
return &s
}
// Segment chooses the parallel segment of the table to scan.
func (s Scan) Segment(segment, total int) *Scan {
s.req.Segment = &segment
s.req.TotalSegments = &total
return &s
}
/*
Select specifies how attributes are chosen, or enables count mode.
Most of the time, specifying Select is not required, because the DynamoDB
API does the "right thing" inferring values based on other attributes like
the projection expression, index, etc.
*/
func (s Scan) Select(value Select) *Scan {
s.req.Select = value
return &s
}
// Execute this Scan query.
func (s *Scan) Execute() (*ScanResult, error) {
return s.client.executor.Scan(s)
}
// Scan operation
func (e *AwsExecutor) Scan(s *Scan) (result *ScanResult, err error) {
result = &ScanResult{req: s}
err = e.MakeRequestUnmarshal("Scan", s.req, &result)
return
}
// ScanResult is the result of Scan queries.
type ScanResult struct {
req *Scan
Items []Document
LastEvaluatedKey Document
ConsumedCapacity *ConsumedCapacity
}
/*
Next returns a scan which get the next page of results when executed.
If the scan has a LastEvaluatedKey, returns another Scan. Otherwise, returns nil.
*/
func (r *ScanResult) Next() *Scan {
if r.LastEvaluatedKey != nil {
return r.req.ExclusiveStartKey(r.LastEvaluatedKey)
}
return nil
}