I am trying to print my query results after I have made a query to my DynamoDB table. I am going to have it display in a table later, but for now I just want to make sure it is working correctly. The query works and doesn't have any errors. I think It has something todo with the Pagination function that I don't understand. I tried reading the documentation, but it hasn't helped me.
我在查询DynamoDB表后尝试打印查询结果。我将在稍后的表格中显示它,但是现在我只想确保它正常工作。查询有效并且没有任何错误。我认为这与我不理解的分页功能有关。我试过阅读文档,但它没有帮助我。
func queryWithPartitionKeyAndSortKeyAndFilterWithCompletionHandler(completionHandler: (response: AWSDynamoDBPaginatedOutput?, error: NSError?) -> Void) {
let objectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()
let queryExpression = AWSDynamoDBQueryExpression()
queryExpression.keyConditionExpression = "#userId = :userId AND #genre < :genre"
queryExpression.filterExpression = "#author > :author"
queryExpression.expressionAttributeNames = [
"#userId": "userId",
"#genre": "genre",
"#author": "author",
]
queryExpression.expressionAttributeValues = [
":userId": AWSIdentityManager.defaultIdentityManager().identityId!,
":genre": "fiction",
":author": "Taylor",
]
objectMapper.query(Books.self, expression: queryExpression, completionHandler: {(response: AWSDynamoDBPaginatedOutput?, error: NSError?) -> Void in
dispatch_async(dispatch_get_main_queue(), {
completionHandler(response: response, error: error)
})
})
}
let completionHandler = {(response: AWSDynamoDBPaginatedOutput?, error: NSError?) -> Void in
if let error = error {
var errorMessage = "Failed to retrieve items. \(error.localizedDescription)"
if (error.domain == AWSServiceErrorDomain && error.code == AWSServiceErrorType.AccessDeniedException.rawValue) {
errorMessage = "Access denied. You are not allowed to perform this operation."
}
}else {
print("I did it" )
print(response)
}
}
1 个解决方案
#1
1
AWSDynamoDBPaginatedOutput
has a property called items
. You should print out the content of the array.
AWSDynamoDBPaginatedOutput有一个名为items的属性。您应该打印出数组的内容。
#1
1
AWSDynamoDBPaginatedOutput
has a property called items
. You should print out the content of the array.
AWSDynamoDBPaginatedOutput有一个名为items的属性。您应该打印出数组的内容。