Database Reference
In-Depth Information
Querying data
For the product table use case, sometimes there might be a need to get all details for the
given product ID; in that case you use query API to fetch the details. All other limitations
of query APIs, which we discussed in Chapter 2 , Data Models , applies here as well; for ex-
ample, in a single client call, we can fetch data only up to 1 MB. If the query result size is
more than 1 MB, then pagination is provided. We can use lastEvaluatedKey to fetch
the next set of results.
The following code snippets show how to fetch all the data for a given product ID using
queries with the Android and iOS SDKs.
Android
Here is the syntax to fetch the data from a given DynamoDB table using query API:
// specify the query condition, here product id = 123
Condition hashKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.EQ.toString())
.withAttributeValueList(new
AttributeValue().withN("123"));
Map<String, Condition> keyConditions = new HashMap<String,
Condition>();
keyConditions.put("productId", hashKeyCondition);
Map<String, AttributeValue> lastEvaluatedKey = null;
do {
QueryRequest queryRequest = new QueryRequest()
.withTableName("ProductTable")
.withKeyConditions(keyConditions)
.withExclusiveStartKey(lastEvaluatedKey);
QueryResult queryResult =
dynamoDBClient.query(queryRequest);
// Get all items from query result
queryResult.getItems();
Search WWH ::




Custom Search