用于查询AWS dynamoDB数据库的

时间:2017-01-20 23:18:46

标签: ios swift xcode amazon-web-services amazon-dynamodb

我正在使用Swift 2.3和Xcode 8构建一个应用程序,我需要我的应用程序来查询数据库中的用户信息(回答他们之前已经回答并保存在数据库中的问题)。 我找到了一些代码(见下文),但我只收到错误。我认为问题是代码正在寻找一个特定的项目,我需要在哈希键中搜索用户的唯一ID,这样每个查询答案的用户都会得到他们的具体信息......任何建议?

func updateAnswer() {  
    //first create expression
    let queryExpression = AWSDynamoDBQueryExpression()

    //second define the index name
    queryExpression.indexName = "userID-index"

    //3rd hashes
    queryExpression.hashKeyAttribute = "userID"
    queryExpression.hashKeyValues = ("us-east-1:97335bac-26d1-4b85-bc86-47091900df44")

    let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()

    //tableRow?.UserId --> (tableRow?.UserId)!
    dynamoDBObjectMapper .query(Notes.self, expression: queryExpression) .continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task:AWSTask!) -> AnyObject! in
        if (task.error == nil) {
            if (task.result != nil) {
                let note = task.result as! Notes
                self.driverAccomplishment1.text = note._content
            }
        } 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
    })
}

0 个答案:

没有答案