0
我無法找到在swift中編寫dynamodb查詢以獲取具有特定分區鍵的結果的方法。如何在swift中編寫dynamodb查詢以獲取具有特定分區鍵的所有值
例如說我的分區鍵是「bigCompany」,排序鍵是「email」。現在我想要將所有電子郵件的「bigCompany」名稱作爲「xyz」。
僅供參考,我的代碼結構與下面的加載函數非常相似。但是這個使用.load
來獲取一個值而不是查詢。基本上我需要找到一種方法,在給定我上面提到的約束條件下調用dynamoDBOBjectMapper .query()
。任何幫助將非常感謝!
func getTableRow() {
let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()
//tableRow?.UserId --> (tableRow?.UserId)!
dynamoDBObjectMapper .load(DDBTableRow.self, hashKey: (tableRow?.UserId)!, rangeKey: tableRow?.GameTitle) .continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task:AWSTask!) -> AnyObject! in
if (task.error == nil) {
if (task.result != nil) {
let tableRow = task.result as! DDBTableRow
self.hashKeyTextField.text = tableRow.UserId
self.rangeKeyTextField.text = tableRow.GameTitle
self.attribute1TextField.text = tableRow.TopScore?.stringValue
self.attribute2TextField.text = tableRow.Wins?.stringValue
self.attribute3TextField.text = tableRow.Losses?.stringValue
}
} else {
print("Error: \(task.error)")
let alertController = UIAlertController(title: "Failed to get item from table.", message: task.error!.description, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: { (action:UIAlertAction) -> Void in
})
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
return nil
})
}