Permalink
Browse files

Merge branch 'master' of github.com:rjrodger/simpledb

  • Loading branch information...
rjrodger committed Nov 1, 2011
2 parents 2460202 + 6431bd5 commit a1c0709fb500ebcb941e6b25146cf14ea0154123
Showing with 79 additions and 4 deletions.
  1. +22 −2 README.md
  2. +21 −0 lib/simpledb.js
  3. +3 −2 package.json
  4. +33 −0 test/simpledb.test.js
View
@@ -2,7 +2,7 @@
If you're using this library, feel free to contact me on twitter if you have any questions! :) [@rjrodger](http://twitter.com/rjrodger)
-Current Version: 0.0.6
+Current Version: 0.0.7
Tested on: node 0.4.4
@@ -45,6 +45,7 @@ Core Functions:
* deleteDomain (_"DeleteDomain"_)
* putItem (_"PutAttributes"_)
* batchPutItem (_"BatchPutAttributes"_)
+ * batchDeleteItem (_"BatchDeleteAttributes"_)
* getItem (_"GetAttributes"_)
* deleteItem (_"DeleteAttributes"_)
* select (_"Select"_)
@@ -288,6 +289,25 @@ _$ItemName_ meta-attribute that specifies the name of the item.
],function(err,res,meta){
console.log("And what was your ownership share diluted down to?"+JSON.stringify(res))
})
+
+### batchDeleteItem: `sdb.batchDeleteItem( domain, items, override, callback )`
+
+ * _domain_: (required) the name of the domain
+ * _items_: (required) the list of items to delete
+ * _override_: (optional) SimpleDB attributes to override function defaults
+ * _callback_: (required) callback function accepting parameters _callback(error, result, metadata)_
+
+Delete multiple items in one request. This is more efficient. The _items_
+argument is an array of item objects. Each item object must have a
+_$ItemName_ meta-attribute that specifies the name of the item.
+
+ sdb.batchDeleteItem('<domain>',
+ [
+ { $ItemName:'<itemname1>', <attr>:'<value>', ...},
+ { $ItemName:'<itemname2>', <attr>:'<value>', ...}
+ ],function(err,res,meta){
+ console.log("Done"+JSON.stringify(res))
+ })
@@ -374,7 +394,7 @@ If you need to handle _NextToken_ you'll need to do this manually with
the override argument. You can get the _NextToken_ from the _meta_ parameter to your callback.
sdb.select("select * from <domain> where <attribute> = '<value>'",function( error, result, meta ){
- console.log("I'll get you, my pretty, and your little dog too! "+JSON.stringify(res))
+ console.log("I'll get you, my pretty, and your little dog too! "+JSON.stringify(result)+" "+JSON.stringify(meta))
})
View
@@ -407,6 +407,27 @@ exports.SimpleDB = function(opts,logger) {
callback(err,out,meta)
})
}
+
+ self.batchDeleteItem = function(domain, items, override, callback) {
+ callback = getcallback(override,callback)
+ if( badargs(callback,domain ))return
+
+ var act = 'BatchDeleteAttributes'
+ var q = {DomainName:domain}
+
+ for( var itemI = 1; itemI <= items.length; itemI++ ) {
+ var attrs = items[itemI-1]
+ q['Item.'+itemI+'.ItemName'] = attrs.$ItemName
+ putattrs(q,attrs,'Item.'+itemI+'.')
+ }
+
+ applyoverride(q,override)
+ makereq(act,q,function(err,res,meta){
+ var out = err ? null : {}
+ callback(err,out,meta)
+ })
+
+ }
// override: {$AsArrays:'true|false(def)'}
View
@@ -2,11 +2,12 @@
"name": "simpledb",
"description": "An Amazon AWS SimpleDB library for Node.js that is user-friendly and fault-tolerant",
"keywords": ["amazon","aws","simpledb","database","wrapper","api"],
- "version": "0.0.6",
+ "version": "0.0.7",
"homepage": "https://github.com/rjrodger/simpledb",
"author": "Richard Rodger <richard@ricebridge.com> (http://richardrodger.com/)",
"contributors": [
- "Richard Rodger <richard@ricebridge.com> (http://richardrodger.com/)"
+ "Richard Rodger <richard@ricebridge.com> (http://richardrodger.com/)",
+ "John Roberts <jroberts@logitech.com>"
],
"dependencies": {
"aws-lib": ">0.0.1"
View
@@ -102,6 +102,39 @@ module.exports = {
tests[testI]()
},
+
+ batchDelete: function() {
+ sdb = new simpledb.SimpleDB({keyid:keys.id, secret:keys.secret}, simpledb.debuglogger);
+
+ sdb.createDomain('batchDeleteTest', function(err,res,meta) {
+ assert.isNull(err);
+ sdb.batchPutItem('batchDeleteTest', [
+ { $ItemName:'i1', batch:'yes', field:'one'},
+ { $ItemName:'i2', batch:'yes', field:'two'},
+ { $ItemName:'i3', batch:'yes', attr:'three'},
+ { $ItemName:'i4', batch:'yes', xjk:'ui'}
+ ], function(err, res, meta) {
+ assert.isNull(err);
+ sdb.batchDeleteItem('batchDeleteTest',
+ [{$ItemName:'i2'}, {$ItemName:'i3'}, {$ItemName:'i4', batch:'yes'}],
+ function(err, res, meta) {
+ assert.isNull(err);
+ sdb.select('select * from batchDeleteTest', function(err, res, meta) {
+ assert.isNull(err);
+ assert.ok(res.length==2, 'should only be 2 items');
+ assert.equal(JSON.stringify(res), JSON.stringify(
+ [{"$ItemName":"i1","batch":"yes","field":"one"},{"$ItemName":"i4","xjk":"ui"}]));
+
+ sdb.deleteDomain('batchDeleteTest', function(err, res, meta) {
+ assert.isNull(err);
+ });
+ });
+ });
+ });
+ });
+
+
+ },
simpledb: function() {
var sdb = null

0 comments on commit a1c0709

Please sign in to comment.