使用批处理方法在DynamoDB中分页
我在DynamoDB中有2张桌子,即产品和卖家。
Seller: sellerId (partitionKey) (No sort key available)
Products: productId (partitionKey) and sellerId (sortKey)
我想在Spring Boot中开发一个API,我将其作为输入传递,并期望出售相应产品的卖家列表。 我将不得不首先使用Productid获取产品列表,然后在其中使用SellerId来获取卖方数据。我目前正在考虑使用映射。 我该如何分页我的结果?
I have 2 tables in DynamoDB, namely products and sellers.
Seller: sellerId (partitionKey) (No sort key available)
Products: productId (partitionKey) and sellerId (sortKey)
I want to develop an API in spring boot where I pass in productId as the input and expect a paginated list of sellers who sell the corresponding products.
I will have to first fetch a list of products using the productId and then use the sellerId in them to fetch seller data. I am currently thinking of using mapper.query for the first call and mapper.batchLoad for the second call.
How can I paginate my results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用DynamoDB使用单桌设计,而不是维护2个表。
以下是您可以在DynamoDB中对表进行建模的方式。
方式1
方法2(推荐)
您也可以使用
字符串集
来存储卖家。字符串集
确保列表中的独特字符串。这将为您节省创建额外的行以存储产品&卖方映射。以这种方式,您可以获取卖方-ID和产品查询,然后您可以提出批次阅读的请求以获取卖家的详细信息。
对于分页
do/while
循环,然后继续查询直到lastEvaledkeykey
变为null。lastEvalecekekey
返回客户端以获取下一组数据。Instead of maintaining 2 tables, you can use single-table design with DynamoDB.
Below is how you can model your table in DynamoDB.
Way 1
Way 2 (Recommended)
You can also use
string set
to store sellers.String Set
ensures unique strings in the list. This will save you to create extra rows to store product & seller mapping.With this way, you can get seller-ids along with product query, and then you can make a batch-read request to get details of sellers.
For Pagination
do/while
loop, and continue query untilLastEvaluatedKey
becomes null.LastEvaluatedKey
to client to get next set of data.