Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement pagination when using amazon Dynamo DB in rails

Tags:

I want to use amazon Dynamo DB with rails.But I have not found a way to implement pagination.

I will use AWS::Record::HashModel as ORM.

This ORM supports limits like this:

People.limit(10).each {|person| ... }  

But I could not figured out how to implement following MySql query in Dynamo DB.

SELECT *    FROM  `People`   LIMIT 1 , 30 
like image 912
sunil Avatar asked Feb 01 '12 14:02

sunil


People also ask

Does DynamoDB support pagination?

DynamoDB paginates the results from Query operations. With pagination, the Query results are divided into "pages" of data that are 1 MB in size (or less). An application can process the first page of results, then the second page, and so on.

How do you count in DynamoDB?

To get the item count of a dynamodb table, you have to: Open the AWS Dynamodb console and click on your table's name. In the Overview tab scroll down to the Items summary section. Click on the Get live item count button.

What is pagination AWS?

When using a command, by default the AWS CLI automatically makes multiple calls to return all possible results to create pagination. One call for each page. Disabling pagination has the AWS CLI only call once for the first page of command results.

How many requests per second can DynamoDB handle?

DynamoDB can handle more than 10 trillion requests per day and can support peaks of more than 20 million requests per second.


2 Answers

You issue queries using LIMIT. If the subset returned does not contain the full table, a LastEvaluatedKey value is returned. You use this value as the ExclusiveStartKey in the next query. And so on...

From the DynamoDB Developer Guide.

like image 99
codeprimate Avatar answered Sep 18 '22 13:09

codeprimate


You can provide 'page-size' in you query to set the result set size. The response of DynamoDB contains 'LastEvaluatedKey' which will indicate the last key as per the page size. If response does't contain 'LastEvaluatedKey' it means there are no results left to fetch. Use the 'LastEvaluatedKey' as 'ExclusiveStartKey' while fetching next time.

I hope this helps.

DynamoDB Pagination

like image 43
Pranav Patil Avatar answered Sep 17 '22 13:09

Pranav Patil