Pagination with AWS DynamoDB with PHP(使用 PHP 使用 AWS DynamoDB 进行分页)
问题描述
有人知道对表中的记录进行分页.其实我想用 DynamoDb 在 php 中创建一个分页组件.
似乎不可能像
因为 Dyanmodb 只是为我们提供了 LIMIT 子句,通过它我们可以读取某些数字.的记录,我们可以通过 LastEvaluatedKey 处理下 n 条记录.所以如果我想直接跳到第5页,怎么可能?
据我了解,我们无法在分页中显示页码.我们可以做的就是读取一定数量的记录,并提供 NEXT 链接来检索下 n 条记录.
分页是任何Web应用程序的基本功能,如果迁移到像DynamoDb这样的云数据库,我们如何实现?
请提供您的意见和建议.谢谢
是的,你是对的,DynamoDB 中没有 OFFSET
.但是只使用 Limit
和 LastEvaluatedKey
,我做了这个函数:
公共函数扫描($table, $filter = [], $select = null, $limit = 2){$page = isset($_GET['page']) ?$_GET['page'] : 0;$选项= ['表名' =>$表,'计数' =>真的,];if (!empty($limit)) {$options['Limit'] = $limit;}if (!is_null($select)) {$options['Select'] = $select;}if (!empty($filter)) {$options['ScanFilter'] = $filter;}$results = $results = $this->_client->scan($options);while ($page > 0 && isset($results['LastEvaluatedKey'])) {$results = $results = $this->_client->scan($options);$options['ExclusiveStartKey'] = $results['LastEvaluatedKey'];$页--;}返回$结果;}
$this->_client
指的是 DynamoDb 客户端对象.
基本上,我使用 LastEvaluatedKey
遍历所有条目,直到到达所需的页面.
要获取表中的总条目,请调用 $this->scan($this->tableName(), [], null, null)['Count'];
(即 - 没有任何搜索条件并且没有分页,就像在正常的分页功能中一样).
Have someone any idea about Paginating the records from a table. Actually I want to create a paginate component in php with DynamoDb.
It seems like it is not possible to giving pagination like <first> <prev> 1,2,3,4,5... <next> <last>.
Because Dyanmodb just provide us LIMIT clause by which we can read certain no. of records and we can process next n records by LastEvaluatedKey. So if I want to jump directly to 5th page, How is it possible ?
As per my understanding we can't display page numbers into the pagination. The thing we can do is just read certain limit of records and provide the NEXT link to retrieve next n records.
Pagination is basic feature of any web application, How can we implement if migrating to cloud database like DynamoDb ?
Please provide your views and suggestions. Thanks
Yes, you are right, there is no OFFSET
in DynamoDB. But using only Limit
and LastEvaluatedKey
, i made this function:
public function scan($table, $filter = [], $select = null, $limit = 2)
{
$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;
}
$results = $results = $this->_client->scan($options);
while ($page > 0 && isset($results['LastEvaluatedKey'])) {
$results = $results = $this->_client->scan($options);
$options['ExclusiveStartKey'] = $results['LastEvaluatedKey'];
$page--;
}
return $results;
}
$this->_client
refers to DynamoDb client object.
Basically i loop through all entries with LastEvaluatedKey
till i reach needed page.
To get total entries in table, call $this->scan($this->tableName(), [], null, null)['Count'];
(that is - without any search criteria and without pagination, just as in normal pagination function).
这篇关于使用 PHP 使用 AWS DynamoDB 进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 PHP 使用 AWS DynamoDB 进行分页
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01