I am to set pagination on my angular Js application. I am currently using this query. query documention
TableName: 'articles_staging',
IndexName: 'feeds_feedname-index',
KeyConditions: {
"feeds_feedname": {
"AttributeValueList": [{
"S": arrayfeeds[j]
}
],
"ComparisonOperator": "EQ"
}
}
how I applied pagination useing this.
Well, bad new is that there is no pagination in DynamoDB (especially there is no OFFSET parameter). I have this function for scan()
to process pagination (PHP code):
private function scan($table, $filter = [], $select = null, $limit = 10)
{
$page = isset($_GET['page']) ? $_GET['page'] : 0;
$options = [
'TableName' => $table,
'Count' => true,
];
if (!empty($limit)) {
$options['Limit'] = $limit;
}
if (!is_null($select)) {
$options['Select'] = $select;
}
if (!empty($filter)) {
$options['ScanFilter'] = $filter;
}
// For pagination:
$results = $this->_client->scan($options);
while ($page > 0 && isset($results['LastEvaluatedKey'])) {
$results = $this->_client->scan($options);
$options['ExclusiveStartKey'] = $results['LastEvaluatedKey'];
$page--;
}
return $results;
}
$this->_client
refers to DynamoDB connection
As you can see, I check for LastEvaluatedKey
in response, if it's there, than it mean in database is still left entries not returned. Than I loop till this parameter is gone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.