問題描述
我正在努力增加已保存在我的 DynamoDB 表中的項目的數字屬性值,我的代碼當前是:
I am struggling with incrementing a number property value of an item already saved in my table on DynamoDB my code currently is:
AWSDynamoDBUpdateItemInput *updateItemInput = [AWSDynamoDBUpdateItemInput new];
updateItemInput.tableName = @"Table";
updateItemInput.key= @{
@"KeyPropertyName":@"KeyValue"
};
updateItemInput.updateExpression = @"SET(counter = counter + :val)";
updateItemInput.expressionAttributeValues =@{
@":val":@1
};
AWSDynamoDB *dynamoDB = [AWSDynamoDB defaultDynamoDB];
[[dynamoDB updateItem:updateItemInput]
continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(@"The request failed. Error: [%@]", task.error);
}
if (task.exception) {
NSLog(@"The request failed. Exception: [%@]", task.exception);
}
if (task.result) {
//Do something with result.
}
return nil;
}];
當我不注釋掉 updateExpression 和 expressionAttributeValues 時,我的應用程序總是崩潰.當我創建我的項目類型的空實例時,我可以到達塊,當我創建 AWSDynamoDBAttributeValue 的實例以傳遞密鑰時,我會得到奇怪的結果.有什么建議?我是否也錯誤地編寫了我的 updateExpression?
My app always crashes when I do not comment out the updateExpression and expressionAttributeValues. I can reach the block when I create an empty instance of my item type and get strange results when I create an instance of AWSDynamoDBAttributeValue to pass in the key. Any suggestions? Am I also improperly writing my updateExpression?
我還將在另一個對象的數組/列表和字典/映射屬性中添加更新和刪除項目.這會有什么不同?
I am also going to be adding updating and deleting items in array/list and dictionary/map properties on another object. How would this differ?
推薦答案
有幾件事.key
定義如下:
@property (nonatomic, strong) NSDictionary<NSString *, AWSDynamoDBAttributeValue *> * _Nullable key;
您需要將 @"KeyValue"
替換為 AWSDynamoDBAttributeValue
的實例.
You need to replace @"KeyValue"
with an instance of AWSDynamoDBAttributeValue
.
expressionAttributeValues
定義如下:
@property (nonatomic, strong) NSDictionary<NSString *, AWSDynamoDBAttributeValue *> * _Nullable expressionAttributeValues;
您需要將 @1
替換為 AWSDynamoDBAttributeValue
的實例.
You need to replace @1
with an instance of AWSDynamoDBAttributeValue
.
確保使用最新版本的適用于 iOS 的 AWS 開發工具包,以便您可以在頭文件中看到泛型注釋.它可以幫助您構建正確的請求對象.
Make sure to use the latest version of the AWS SDK for iOS so that you can see the generics annotations in the header file. It helps you construct the proper request object.
這篇關于AWS DynamoDB Objective C 中的遞增數字屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!