@awspilot/dynamodb

Issue Star Fork
update.js
update_sql.js
// Update Existing Item // WARN: use schema() to prevent describeTable call DynamoDB .table('tbl_name') .where('partition_key').eq('test@test.com') .where('sort_key').eq( 1234 ) .return(DynamoDB.ALL_OLD) .update({ password: 'qwert', name: 'Smith', active: true, subscription: null, mybuff: Buffer.from('WWV5IQ==','base64'), // increment page_views: DynamoDB.add(5), list: [5,'a', {}, [] ], // ADD to array (L) - not documented by AWS arr: DynamoDB.add( ['x','y', false, null, {}] ), // updated as datatype SS string_set1: DynamoDB.SS(['sss','bbb','ccc']), string_set2: new Set(['sss','bbb','ccc']), // updated as datatype NS number_set1: DynamoDB.NS([111,222,333]), number_set2: new Set([[111,222,333]]), // updated as datatype L list1: [7,9,15], list2: new Set([]), list3: new Set([ 'a', 1 ]), // ADD to StringSet and NumberSet, will only keep unique values ss1: DynamoDB.add( DynamoDB.SS(['aaa','ddd']) ), ns1: DynamoDB.add( DynamoDB.NS([11,44]) ), // delete from StringSet and NumberSet ss2: DynamoDB.del( DynamoDB.SS(['bbb']) ), ns2: DynamoDB.del( DynamoDB.NS([22]) ), // delete from Array (L) not supported by Amazon // delete attribute unneeded_attribute: DynamoDB.del(), }, function( err, data ) { console.log( err, data ) });
// Update Existing Item // SQL version does not currently support adding / removing from StringSet or NumberSet. (Awspilot limitation). // set value to undefined to delete an attribute // new Date() and Math is evaluated to String or Number when parsed // WARN: use schema() to prevent describeTable call DynamoDB.query(` UPDATE tbl_name SET active = true, nulled = null, nine = 5 + 4, binary = Buffer.from('4oya', 'base64'), activation_code = undefined, login_count += 1, days_left += -1, array = [ 'hello' + " " + "world", 1+2.14, null, true, Buffer.from('aXRlbTE=', 'base64'), { nested_object: true }, ['nested_array'], new StringSet( [ 'sss','bbb','ccc' ] ), new NumberSet( [ 111 , 222 , 333 ] ), new BinarySet( [ Buffer.from('aXRlbTE=','base64') ]), ], object = { string: 's', number: 1, null: null, boolean: true, "me-too": "JSON key names can be enclosed in quotes", binary: Buffer.from('aXRlbTE=', 'base64'), ss : new StringSet( [ 'sss','bbb','ccc' ] ), ns : new NumberSet( [ 111 , 222 , 333 ] ), bs : new BinarySet( [ Buffer.from('aXRlbTE=','base64') ]), }, tags = new StringSet(['dev','nodejs']), lucky_numbers = new NumberSet([ 12, 3.14 ]), bs = new BinarySet([ Buffer.from('aXRlbTE=','base64') ]), updated_at = new Date().getTime(), expire_at = Math.round( (new Date().getTime() / 1000) + 60*60*24 ) WHERE partition_key = 'test.com' AND sort_key = Math.round( 5.5 + 7.2 ) `, function( err, data ) { console.log( err, data ) });