<bdo id='T1pse'></bdo><ul id='T1pse'></ul>

      <small id='T1pse'></small><noframes id='T1pse'>

        <tfoot id='T1pse'></tfoot>

        <i id='T1pse'><tr id='T1pse'><dt id='T1pse'><q id='T1pse'><span id='T1pse'><b id='T1pse'><form id='T1pse'><ins id='T1pse'></ins><ul id='T1pse'></ul><sub id='T1pse'></sub></form><legend id='T1pse'></legend><bdo id='T1pse'><pre id='T1pse'><center id='T1pse'></center></pre></bdo></b><th id='T1pse'></th></span></q></dt></tr></i><div id='T1pse'><tfoot id='T1pse'></tfoot><dl id='T1pse'><fieldset id='T1pse'></fieldset></dl></div>
        <legend id='T1pse'><style id='T1pse'><dir id='T1pse'><q id='T1pse'></q></dir></style></legend>

        使用 PHP 使用 AWS DynamoDB 进行分页

        时间:2024-05-10
      1. <legend id='4T278'><style id='4T278'><dir id='4T278'><q id='4T278'></q></dir></style></legend>
            <tbody id='4T278'></tbody>

            <i id='4T278'><tr id='4T278'><dt id='4T278'><q id='4T278'><span id='4T278'><b id='4T278'><form id='4T278'><ins id='4T278'></ins><ul id='4T278'></ul><sub id='4T278'></sub></form><legend id='4T278'></legend><bdo id='4T278'><pre id='4T278'><center id='4T278'></center></pre></bdo></b><th id='4T278'></th></span></q></dt></tr></i><div id='4T278'><tfoot id='4T278'></tfoot><dl id='4T278'><fieldset id='4T278'></fieldset></dl></div>
              <tfoot id='4T278'></tfoot>

              • <bdo id='4T278'></bdo><ul id='4T278'></ul>

                  <small id='4T278'></small><noframes id='4T278'>

                • 本文介绍了使用 PHP 使用 AWS DynamoDB 进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有人知道对表中的记录进行分页.其实我想用 DynamoDb 在 php 中创建一个分页组件.

                  似乎不可能像

                  1,2,3,4,5... .

                  那样进行分页

                  因为 Dyanmodb 只是为我们提供了 LIMIT 子句,通过它我们可以读取某些数字.的记录,我们可以通过 LastEvaluatedKey 处理下 n 条记录.所以如果我想直接跳到第5页,怎么可能?

                  据我了解,我们无法在分页中显示页码.我们可以做的就是读取一定数量的记录,并提供 NEXT 链接来检索下 n 条记录.

                  分页是任何Web应用程序的基本功能,如果迁移到像DynamoDb这样的云数据库,我们如何实现?

                  请提供您的意见和建议.谢谢

                  解决方案

                  是的,你是对的,DynamoDB 中没有 OFFSET.但是只使用 LimitLastEvaluatedKey,我做了这个函数:

                  公共函数扫描($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 进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:DynamoDB:仅当它已经存在时才更新项目 下一篇:重复受限制的 DynamoDB 请求

                  相关文章

                • <legend id='N5R8B'><style id='N5R8B'><dir id='N5R8B'><q id='N5R8B'></q></dir></style></legend>
                    <tfoot id='N5R8B'></tfoot>
                      <bdo id='N5R8B'></bdo><ul id='N5R8B'></ul>

                    <i id='N5R8B'><tr id='N5R8B'><dt id='N5R8B'><q id='N5R8B'><span id='N5R8B'><b id='N5R8B'><form id='N5R8B'><ins id='N5R8B'></ins><ul id='N5R8B'></ul><sub id='N5R8B'></sub></form><legend id='N5R8B'></legend><bdo id='N5R8B'><pre id='N5R8B'><center id='N5R8B'></center></pre></bdo></b><th id='N5R8B'></th></span></q></dt></tr></i><div id='N5R8B'><tfoot id='N5R8B'></tfoot><dl id='N5R8B'><fieldset id='N5R8B'></fieldset></dl></div>

                      <small id='N5R8B'></small><noframes id='N5R8B'>