Database Reference
In-Depth Information
iOS
The syntax for conditional writes in iOS is as follows:
Tip
The next piece of code checks whether any item with given details exists; if not, then only
the code commits the put request.
DynamoDBExpectedAttributeValue *checkExists =
[DynamoDBExpectedAttributeValue new];
checkExists.exists = NO;
[putItemRequest.expected setValue:checkExists
forKey:@"recordId"];
Tip
The next piece of code checks if the value of data is two, only then does it update it to a
new value three.
// Create a request which updates the no. of items in stock
DynamoDBPutItemRequest *putItemRequest =
[DynamoDBPutItemRequest new];
request.tableName = @"ProductTable";
DynamoDBAttributeValue *value = [[DynamoDBAttributeValue
alloc] initWithN:@"777"]; [putItemRequest.item
setValue:value forKey:@"productId"];
value = [[DynamoDBAttributeValue alloc]
initWithS:@"NoOfItemsInStock"];
[putItemRequest.item setValue:value forKey:@"recordId"];
value = [[DynamoDBAttributeValue alloc] initWithS:@"3"];
[putItemRequest.item setValue:value forKey:@"data"];
// Here we want DynamoDB to update the record only when its
value is 2
Search WWH ::




Custom Search