Ich versuche, meine Abfrageergebnisse zu drucken, nachdem ich eine Abfrage in meine DynamoDB-Tabelle erstellt habe. Ich werde es später in einer Tabelle anzeigen lassen, aber jetzt möchte ich nur sicherstellen, dass es korrekt funktioniert. Die Abfrage funktioniert und hat keine Fehler. Ich denke, es hat etwas mit der Paginierung Funktion, die ich nicht verstehe. Ich habe versucht, die Dokumentation zu lesen, aber es hat mir nicht geholfen.Wie Drucken DynamoDB Query Ergebnisse mit Swift
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)
}
}
Das hat funktioniert! Ich benutzte Druck (Antwort! .Artikel) und es druckte die Ausgabe aus, also bin ich glücklich. –