aws dynamodb how to use object mapper with batch get in ios

╄→гoц情女王★ 提交于 2019-12-23 12:26:20

问题


I need to get ~50 items with their primary keys from dynamodb using ios sdk. i am able to get the items by AWSDynamoDB.defaultDynamoDB().batchGetItem but couldn't figure out if it is possible to use object mapper with the response. Unfortunately objectmapper class in ios doesn't have batchGet function. As far as i know i cant use query in this situation.

Is it possible to use object mapper? If not which one makes more sense: parsing the response to get the desired class instance or calling objectMapper.load on each item?


回答1:


Currently, AWSDynamoDBObjectMapper does not support the batch get item. You need to load one item at a time if you want to use the object mapper.




回答2:


I solved it by doing this,

    let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()
    let task1 = dynamoDBObjectMapper.load(User.self, hashKey: "rtP1oQ5DJG", rangeKey: nil)
    let task2 = dynamoDBObjectMapper.load(User.self, hashKey: "dbqb1zyUq1", rangeKey: nil)

    AWSTask.init(forCompletionOfAllTasksWithResults: [task1, task2]).continueWithBlock { (task) -> AnyObject? in
        if let users = task.result as? [User] {
            print(users.count)
            print(users[0].firstName)
            print(users[1].firstName)
        }
        else if let error = task.error {
            print(error.localizedDescription)
        }
        return nil
    }


来源:https://stackoverflow.com/questions/35246164/aws-dynamodb-how-to-use-object-mapper-with-batch-get-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!