【问题标题】:Pagination in dynamo dbdynamo db中的分页
【发布时间】:2014-09-08 20:19:20
【问题描述】:

我要在我的 Angular Js 应用程序上设置分页。我目前正在使用此查询。 query documention

 TableName: 'articles_staging',
                IndexName: 'feeds_feedname-index',
                KeyConditions: {
                    "feeds_feedname": {
                        "AttributeValueList": [{
                                "S": arrayfeeds[j]


                            }

                        ],

                        "ComparisonOperator": "EQ"
                    }
                }

我如何使用它来应用分页。

【问题讨论】:

  • 你检查了 angular bootstrap ui 的分页吗?
  • 实际上我需要 dynamodb 中的 amazon-web-services 帮助来编写查询。

标签: angularjs amazon-web-services pagination amazon-dynamodb


【解决方案1】:

嗯,坏消息是 DynamoDB 中没有分页(尤其是没有 OFFSET 参数)。我有这个函数供scan() 处理分页(PHP 代码):

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 指的是 DynamoDB 连接

如您所见,我检查LastEvaluatedKey 作为响应,如果它在那里,则意味着数据库中仍然没有返回条目。然后我循环直到这个参数消失。

【讨论】:

    猜你喜欢
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多