Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在swift中编写dynamodb查询以获取具有特定分区键的所有值_Ios_Swift_Amazon Dynamodb - Fatal编程技术网

Ios 如何在swift中编写dynamodb查询以获取具有特定分区键的所有值

Ios 如何在swift中编写dynamodb查询以获取具有特定分区键的所有值,ios,swift,amazon-dynamodb,Ios,Swift,Amazon Dynamodb,我无法找到用swift编写dynamodb查询以获取具有特定分区键的结果的方法 例如,假设我的分区键是“bigCompany”,排序键是“email”。现在,我想获取所有电子邮件,其“大公司”名称为“xyz” 作为参考,我的代码结构与下面的加载函数非常相似。但是这个函数使用.load来获取一个值,而不是查询。基本上,我需要找到一种方法来调用dynamodbobbjectmapper.query(),以满足我上面提到的约束条件。任何帮助都将不胜感激 func getTableRow() {

我无法找到用swift编写dynamodb查询以获取具有特定分区键的结果的方法

例如,假设我的分区键是“bigCompany”,排序键是“email”。现在,我想获取所有电子邮件,其“大公司”名称为“xyz”

作为参考,我的代码结构与下面的加载函数非常相似。但是这个函数使用
.load
来获取一个值,而不是查询。基本上,我需要找到一种方法来调用
dynamodbobbjectmapper.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
    })
}

我明白了。它们的关键是正确使用keyConditionExpression。下面是我的答案

            let queryExpression = AWSDynamoDBQueryExpression()

            queryExpression.keyConditionExpression = "#bigCompany = :bigCompany"
            queryExpression.expressionAttributeNames = ["#bigCompany": "bigCompany",]
            queryExpression.expressionAttributeValues = [":bigCompany" : self.bigCompany,]

            dynamoDBObjectMapper.query(Requests.self, expression: queryExpression) .continue(with: AWSExecutor.immediate(), with: { (task:AWSTask!) -> AnyObject! in
                //If added successfully
                if((task.result) != nil) {
                    let results = task.result! as AWSDynamoDBPaginatedOutput
                    print(results.items)
                } 
                else {
                    //do error checking here
                }
            })

我明白了。它们的关键是正确使用keyConditionExpression。下面是我的答案

            let queryExpression = AWSDynamoDBQueryExpression()

            queryExpression.keyConditionExpression = "#bigCompany = :bigCompany"
            queryExpression.expressionAttributeNames = ["#bigCompany": "bigCompany",]
            queryExpression.expressionAttributeValues = [":bigCompany" : self.bigCompany,]

            dynamoDBObjectMapper.query(Requests.self, expression: queryExpression) .continue(with: AWSExecutor.immediate(), with: { (task:AWSTask!) -> AnyObject! in
                //If added successfully
                if((task.result) != nil) {
                    let results = task.result! as AWSDynamoDBPaginatedOutput
                    print(results.items)
                } 
                else {
                    //do error checking here
                }
            })