I am creating a personal Alexa skill that can log in the savings that i have on a daily basis. So lets say I saved 10$ today, i want my alexa skill to remember that along with a running sum of the total money that i have saved so far, so if yesterday i had saved 5$, if i ask the skill about my savings, it should come back with 15$. I also want it to have the capability, to subtract from the total sum when i withdraw money. So if i take out 5$ tomorrow, the new total should be 10$.
I have done the Alexa part of the skill, where i am able to get the amount in the var, varUserAmount in my lambda function. But i am stuck beyond that. I was also able to make the following query work, where everytime i say an amount the value gets written in the dynamodb.
var params = {
TableName: 'AccountManagement',
Item: {
'date' : {S: 'test'},
'amount' : {N: varUserAmount},
}
};
// Call DynamoDB to add the item to the table
ddb.putItem(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
My confusion is on the query side of the things, how would the total column in the table work? I would assume i would want to query the last value of the total, add the new amount from the user, and write the updated total amount back to the table? But i am not sure how to write that query to get the latest value of total?
Any guidance would be appreciated.
date
as the sort key, then you could query by AccountID, withScanIndexForward = false
andLimit = 1
to get the last record inserted for that account. – Mark B