Database Reference
In-Depth Information
Writing data to DynamoDB
We have already seen how to create, delete, and update using various APIs in
Chapter 2
,
Data Models
. In this section, we will go through the APIs available for the iOS and
Android SDKs. To understand this in a better way, let's assume that you want to develop an
app where a user can post adds to sell, rent, or purchase anything. For that, we would need
a table called product table, which would look like this:
productId
recordId
Data
123
productName
BMW Z
123
cost
$20000
456
productName
Hill range bicycle
456
cost
$120
789
productName
Baseball bat
789
Cost
$50
Here, we would like to have the hash key as
productId
and the range key as
re-
cordId
.
Android
Now, let's see how to write code in
Android
to add items in the
Product
table:
// Hash Map for storing attributes
Map<String,AttributeValue> product = new HashMap<String,
AttributeValue>();
// Adding hash key and value
item.put("productId", new AttributeValue().withS("123"));