Skip to content

Commit

Permalink
[DynamoDB] Add ScanIndexForward option for Query operation (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
evalphobia authored Feb 7, 2018
1 parent fefad5c commit 18ebc43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dynamodb/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ConditionList struct {
limit int64
startKey map[string]*SDK.AttributeValue
isConsistent bool
isDesc bool // descending order
}

// NewConditionList returns initialized *ConditionList.
Expand Down Expand Up @@ -77,6 +78,11 @@ func (c *ConditionList) SetConsistent(b bool) {
c.isConsistent = b
}

// SetDesc sets descending order flag.
func (c *ConditionList) SetDesc(b bool) {
c.isDesc = b
}

// SetStartKey sets ExclusiveStartKey.
func (c *ConditionList) SetStartKey(startKey map[string]*SDK.AttributeValue) {
c.startKey = startKey
Expand Down
4 changes: 4 additions & 0 deletions dynamodb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ func (t *Table) query(cond *ConditionList, in *SDK.QueryInput) (*QueryResult, er
if cond.isConsistent {
in.ConsistentRead = pointers.Bool(cond.isConsistent)
}
if cond.isDesc {
in.ScanIndexForward = pointers.Bool(false)
}

in.ExclusiveStartKey = cond.startKey
in.TableName = pointers.String(t.nameWithPrefix)
req, err := t.service.client.Query(in)
if err != nil {
Expand Down

0 comments on commit 18ebc43

Please sign in to comment.