Reverse before limit
This commit is contained in:
parent
9b0bce93dc
commit
33f31652ea
@ -320,14 +320,14 @@ class DynamoHandler(BaseResponse):
|
|||||||
er = 'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException'
|
er = 'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException'
|
||||||
return self.error(er)
|
return self.error(er)
|
||||||
|
|
||||||
limit = self.body.get("Limit")
|
|
||||||
if limit:
|
|
||||||
items = items[:limit]
|
|
||||||
|
|
||||||
reversed = self.body.get("ScanIndexForward")
|
reversed = self.body.get("ScanIndexForward")
|
||||||
if reversed is False:
|
if reversed is False:
|
||||||
items.reverse()
|
items.reverse()
|
||||||
|
|
||||||
|
limit = self.body.get("Limit")
|
||||||
|
if limit:
|
||||||
|
items = items[:limit]
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"Count": len(items),
|
"Count": len(items),
|
||||||
"Items": [item.attrs for item in items],
|
"Items": [item.attrs for item in items],
|
||||||
|
@ -570,6 +570,30 @@ def test_query_with_global_indexes():
|
|||||||
list(results).should.have.length_of(0)
|
list(results).should.have.length_of(0)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_reverse_query():
|
||||||
|
conn = boto.dynamodb2.layer1.DynamoDBConnection()
|
||||||
|
|
||||||
|
table = Table.create('messages', schema=[
|
||||||
|
HashKey('subject'),
|
||||||
|
RangeKey('created_at', data_type='N')
|
||||||
|
])
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
table.put_item({
|
||||||
|
'subject': "Hi",
|
||||||
|
'created_at': i
|
||||||
|
})
|
||||||
|
|
||||||
|
results = table.query_2(subject__eq="Hi",
|
||||||
|
created_at__lt=6,
|
||||||
|
limit=4,
|
||||||
|
reverse=True)
|
||||||
|
|
||||||
|
expected = map(Decimal, [5, 4, 3, 2])
|
||||||
|
[r['created_at'] for r in results].should.equal(expected)
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_lookup():
|
def test_lookup():
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user