@awspilot/dynamodb

Issue Star Fork
insert.js
insert_sql.js
insert_sql_values.js
// Insert Item ( no update ) // will fail if item exists // checks the table schema to add a conditional requests and make sure item does not exist // WARN: use schema() to prevent describeTable call DynamoDB .table('demo_table_hash_range') .insert({ // carefull though as foo.bar domain actually exists :) partitionKey: 'foo.bar', sortKey: 1, email: 'baz@foo.bar', password: 'qwert', boolean: true, number: 1, created_at: new Date().getTime(), updated_at: null, // server side only // buffer: new Buffer("test"), array_empty: [], // inserted as datatype L array_strings: ['alfa','beta','gama'], // inserted as datatype SS string_set1: DynamoDB.SS(['sss','bbb','ccc']), string_set2: new Set(['sss','bbb','ccc']), // inserted as datatype NS number_set1: DynamoDB.NS([111,222,333]), number_set2: new Set([111,222,333]), // inserted as datatype L list1: [7,9,15], list2: new Set([]), list3: new Set([ 'a', 1 ]), array_mixed: [ null, "string", 5, true, false, { key: "value"}, ["nested","array"], //new Buffer("test") ], nested_object: { name: "Foo", email: "baz@foo.bar", nested_attribute: { boolean_value: true, null_key: null, some_string: "tadaa", lucky_number: 12 } } }, function(err,data) { console.log( err, data ) });
// SQL keywords must be enclosed in "`", // if no callback is supplied, promise is returned // new Date() is evaluated to String or Number when parsed // // WARNING: // INSERT statement does not replace or update if an item with the same key exists // to prevent replacing or updating, awspilot needs to know the key schema // and will make an extra call to describeTable // use schema() to prevent the extra describeTable call DynamoDB.query(` INSERT INTO demo_table_hash_range SET partitionKey = uuid('account-######-######'), sortKey = 33, email = 'test@test.com', password = 'qwert', welcome = "hello" + " " + "world", boolean = true, number = Math.round( 3.14 ) - 2, updated_at = null, binary = Buffer.from('4oya', 'base64'), 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') ]), }, ss = new StringSet( [ 'sss','bbb','ccc' ] ), ns = new NumberSet( [ 111 , 222 , 333 ] ), bs = new BinarySet( [ Buffer.from('aXRlbTE=','base64') ]), created_at = new Date().getTime(), expire_at = Math.round( (new Date().getTime() / 1000) + 60*60*24 ) `, function( err, data ) { console.log( err, data ) });
// If only one item is specified for VALUES, awspilot will make a putItem request // if more items in VALUES, batchWriteItem will be performed DynamoDB.query(` INSERT INTO demo_table_hash_range VALUES ({ partitionKey : 'domain.com', sortKey : 99, email : 'test@test.com', password : 'qwert', bool : true, one : 1, updated_at : null, bin : Buffer.from('4oya', 'base64'), array : [ 'text', 1, 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') ]), }, ss : new StringSet( [ 'sss','bbb','ccc' ] ), ns : new NumberSet( [ 111 , 222 , 333 ] ), bs : new BinarySet( [ Buffer.from('aXRlbTE=','base64') ]), }) `, function( err, data ) { console.log( err, data ) });