1

I am trying to print my query results after I have made a query to my DynamoDB table. I am going to have it display in a table later, but for now I just want to make sure it is working correctly. The query works and doesn't have any errors. I think It has something todo with the Pagination function that I don't understand. I tried reading the documentation, but it hasn't helped me.

 func queryWithPartitionKeyAndSortKeyAndFilterWithCompletionHandler(completionHandler: (response: AWSDynamoDBPaginatedOutput?, error: NSError?) -> Void) {
    let objectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()
    let queryExpression = AWSDynamoDBQueryExpression()

    queryExpression.keyConditionExpression = "#userId = :userId AND #genre < :genre"
    queryExpression.filterExpression = "#author > :author"
    queryExpression.expressionAttributeNames = [
        "#userId": "userId",
        "#genre": "genre",
        "#author": "author",
    ]
    queryExpression.expressionAttributeValues = [
        ":userId": AWSIdentityManager.defaultIdentityManager().identityId!,
        ":genre": "fiction",
        ":author": "Taylor",
    ]

    objectMapper.query(Books.self, expression: queryExpression, completionHandler: {(response: AWSDynamoDBPaginatedOutput?, error: NSError?) -> Void in
        dispatch_async(dispatch_get_main_queue(), {
            completionHandler(response: response, error: error)
        })
    })
}


let completionHandler = {(response: AWSDynamoDBPaginatedOutput?, error: NSError?) -> Void in
    if let error = error {
        var errorMessage = "Failed to retrieve items. \(error.localizedDescription)"
        if (error.domain == AWSServiceErrorDomain && error.code == AWSServiceErrorType.AccessDeniedException.rawValue) {
            errorMessage = "Access denied. You are not allowed to perform this operation."
        }
    }else {


        print("I did it" )
        print(response)


    }
}

1 Answer 1

1

AWSDynamoDBPaginatedOutput has a property called items. You should print out the content of the array.

Sign up to request clarification or add additional context in comments.

1 Comment

That worked! I used print(response!.items) and it printed out the output so I am happy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.