Closed luizstacio closed 9 years ago
Hi
I know about this limitation, I'll get back with a solution, however may not be a third parameter.
Thanks
Ok no problem, I make this for resolve my problem but I understand, not be better solution for this project.
Maybe something:
DynamoDB
.table(TABLE)
.actions({
phones: 'ADD'
})
.insert_or_update({
hash: 'USER:123',
phones: ['99114999'],
status: null
}, function (err, data) {
if (err) throw (err);
console.log(data);
})
I'm doing some tests now, will be publishing new npm version soon
what I'm testing now and hopefully makes sense, looks like this
DynamoDB
.table(TABLE)
.insert_or_update({
hash: 'USER:123',
unneded_attribute: DynamoDB.delete(),
phones: DynamoDB.push('99114999'),
profile_views: DynamoDB.increment(1),
status: null
}, function( err,data ) {
})
This solution is pretty good, only one topic, I think "DynamoDB.add" make more sense. because the action in "DynamoDB.push or DynamoDB. increment" is the same.
It's a bit tricky as having only add() will need to know if it operates on an array or number because they translate into different code
Also an array should support adding multiple values like .add( 5, 'aaa', {}, [] )
Same with delete() where we need to know if we need to delete the entire arrtibute or just some values from the array
Ok, I understand your suggestion now. =D Thanks for your attention in my necessity and congrats for this project.
Updated, you can now use DynamoDB.add(number) to increment an attribute, DynamoDB.add([array]) to add elements to an attribute of list type DynamoDB.del() to remove attribute from an item
documentation updated aswell
In my case I have a list and i needed append this list in "insert_or_update" and if changing for the other method the method not attended my necessity, because I had atributes null.