Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #16 from aomega/master

Added batchDeleteItem mirroring existing API
  • Loading branch information...
commit 6431bd5e1a7f6cbb6e55e5eeda9624a806473163 2 parents b6b6048 + c3879a6
@rjrodger authored
View
22 README.md
@@ -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))
+ })
View
21 lib/simpledb.js
@@ -403,6 +403,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
5 package.json
@@ -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
33 test/simpledb.test.js
@@ -100,6 +100,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
Please sign in to comment.
Something went wrong with that request. Please try again.