2 回答
TA贡献1847条经验 获得超7个赞
在DynamoDB我试图使用是一个简单的包装器AmazonDynamoDB,提供了一个稍微不同的API。使用AmazonDynamoDB代替使这个函数的实现更容易,它应该看起来像这样(请原谅糟糕的Java代码,我实际上是用Scala编写的):
public Boolean isEmpty(AmazonDynamoDB database, String tableName) = {
ScanRequest scanRequest = new ScanRequest().withTableName(tableName).withLimit(1);
return database.scan(scanRequest).getCount == 0;
}
或者,在 Scala 中:
def isEmpty(database: AmazonDynamoDB, tableName: String): Boolean = {
val scanRequest = new ScanRequest().withTableName(tableName).withLimit(1)
database.scan(scanRequest).getCount == 0
}
TA贡献1796条经验 获得超4个赞
我不知道如何在 Java 中做到这一点,但它必须类似于 Javascript:
const params = {
TableName: tableName,
Limit: 1, // `Limit` is the most important parameter.
// The scan will not scan the whole table,
// it will only visit one item and then return.
// Very efficient!
};
// Execute the scan, whatever the syntax is...
const result = await (new AWS.DynamoDB.DocumentClient().scan(params).promise());
// Check the response
if (result.Count > 0) return false; // the table is **not** empty
return true; // the table is empty
在 Java 中,代码应该是类似的...随意询问细节不够清楚。
添加回答
举报
