Open haruharuharuby opened 4 years ago
Hi @haruharuharuby,
There's an executeUpdateExpression
method to support this type of update.
@jeskew okay. thanks. I could not find this document.
Can anyone help with an example of how to use the executeUpdateExpression method to achieve the functionality mentioned in the description please?
Here's what I've cobbled together so far from the docs...
My table, called my-table
, contains the following entry to be updated:
{
"MyHashKey": { // This is my hash/primary key
"S": "my-hash-key-value"
},
"MyRangeKey": { // This is my sort/range key
"S": "my-range-key-value"
},
"SomeValue": { // this is the value to be updated
"N": "0"
}
}
My code that attempts to execute an update expression
@table("my-table")
export class MyModel {
@hashKey()
MyHashKey!: string;
@rangeKey()
MyRangeKey!: string;
@attribute()
SomeValue!: number;
}
const updateExpr = new UpdateExpression();
updateExpr.set("SomeValue", new MathematicalExpression("SomeValue", '+', 1));
const key = {
"MyHashKey": { S: "my-hash-key-value" } ,
"MyRangeKey": { S: "my-range-key-value" }
};
await mapper.executeUpdateExpression(updateExpr, key, MyModel);
However this seems to be throwing the following exception:
ValidationException: The provided expression refers to an attribute that does not exist in the item
Any help getting a working example would be appreciated.
Did you find the solution to this issue?
There is an example of how to use executeUpdateExpression
in the tests.
Does set
allows us increase count of an existing attribute only, in my code someValue
attribute is not exists before so i am getting error like this
No item with the key found in table
Description: Currently update operation only accept annotated model. I'd like to request that Custom expression can be specified on update operation.
Abstract example: This example, some attribute increments by atomic counter.