简体   繁体   English

如何从 aws appsync 中的 dynamodb 获取数据总数以进行分页?

[英]How to get total count of data from dynamodb in aws appsync for pagination?

I am working on web app using aws amplify.我正在使用 aws amplify 开发 web 应用程序。 And I am using Appsync GraphQL as web server.我正在使用 Appsync GraphQL 作为 web 服务器。 But I don't know a way to get a total count of data from Dynamodb through aws appsync.但我不知道通过 aws appsync 从 Dynamodb 获取数据总数的方法。 Please help me.请帮我。

How weird this can feel when coming from a SQL background, there is no easy way to do this in DynamoDB.当来自 SQL 背景时,这感觉多么奇怪,在 DynamoDB 中没有简单的方法可以做到这一点。 The suggested approach is to perform multiple Scan operations until reaching the end and record the scannedCount value as you go.建议的方法是执行多次 Scan 操作,直到结束,并按照 go 记录scannedCount值。

You won't be able to achieve this in AWS AppSync natively, if you absolutely need to do this through AppSync you can use a Lambda resolver that will perform the Scan operations.您将无法在 AWS AppSync 本机中实现此目的,如果您绝对需要通过 AppSync 执行此操作,您可以使用 Lambda 解析器来执行Scan操作。

You could also keep track of all the PutItem and DeleteItem operation on your table using DynamoDB streams and increment/decrement a counter somewhere.您还可以使用 DynamoDB 流跟踪表上的所有PutItemDeleteItem操作,并在某处增加/减少计数器。 Again this might be fragile if your Lambda ever loses track.同样,如果您的 Lambda 丢失轨道,这可能会很脆弱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM