fmog
fmog

Reputation: 186

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

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?

Upvotes: 4

Views: 636

Answers (2)

Niklas
Niklas

Reputation: 1331

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
    }

Upvotes: 0

Yosuke
Yosuke

Reputation: 3759

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.

Upvotes: 2

Related Questions