awspilot / dynamodb-oop

Speak fluent DynamoDB, write code with fashion, I Promise() 😃
https://awspilot.dev
MIT License
119 stars 28 forks source link

DynamoDB.add() String Set #15

Closed teebu closed 8 years ago

teebu commented 8 years ago

I think right now, this module only supports arrays, but I'd like to add unique values only, I think using a String Set is the way that is done.

Can you consider adding that feature.

For now, I modified the add prototype for my testing.

    DynamoDB.prototype.addSS = function(data) {
        if (Array.isArray(data)) {
            var to_ret = {'SS': [] }
            for (var i in data) {
                to_ret.SS[i] = data[i]
            }
            return new DynamoDB.Raw({
                Action: 'ADD',
                Value: to_ret
            })
        }
    }
adrianpraja commented 8 years ago

Hi,

I've updated library to support inserting string sets and number sets like

{
     number: 1,
     object: {a: 1, b: 'string'},
     string_set: DynamoDB.stringSet(['xxx','yyy','zzz']),
     number_set: DynamoDB.numberSet([5,4,3,2,1])
}

documentation not updated yet

I'll be back with a solution for "add() to stringSet/numberSet" also (addSS maybe)

-adrian

teebu commented 8 years ago

Another feature request, remove/delete item from string set.

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html#Expressions.Modifying.ConditionalWrites

adrianpraja commented 8 years ago

Teebu,

I've published 0.1.48 with support for add/remove from stringSet and numberSet

{
     a_number: 1,
     b_number: DynamoDB.add(5), // increment by 5

     a_string_set: DynamoDB.stringSet(['xxx','yyy','zzz']),
     b_string_set: DynamoDB.add(['aaa','bbb'],'SS'), // add to stringSet
     c_string_set: DynamoDB.del(['xxx','yyy'],'SS'), // remove from stringSet

     a_number_set: DynamoDB.numberSet([5,4,3,2,1]),
     b_number_set: DynamoDB.add([11,22],'NS'), // add to numberSet
     c_number_set: DynamoDB.del([3,2],'NS'), // remove from numberSet
}
teebu commented 8 years ago

Observation:

stringset_test: DynamoDB.add('a', 'SS'), // add to stringSet

doing this, doesn't add 'a' to a stringset, it removes that field entirely.

adrianpraja commented 8 years ago

The add() metod will support all data types Including L but now it only supports:

.add( 5 ) for N .add( [ ... ], type ) for SS and NS

If we support .add( 'a', 'SS') then we also need to Support .add('a', 'b', 'SS' )

I'm thinking that another way of solving this without using a second parameter wiuld be:

.add( DynamoDB.stringSet([...]))

Right now, since nothing related to adding to stringset is published into the documentation, add(param) assumes its adding to a number and will remain The same for backword compatibility

adrianpraja commented 8 years ago

numberSet / stringSet support is now available and documented.

Please let me know if anything missing

thanks,