Permalink
Browse files

Added batchDeleteItem to simpledb library and updated unit tests. For…

… unit test, added a new test called 'batchDelete' to test this functionality
  • Loading branch information...
1 parent b6b6048 commit f8c8ef00f48e5bf1b4a04957ea85a218e284bc21 John Roberts committed Sep 15, 2011
Showing with 57 additions and 2 deletions.
  1. +21 −0 lib/simpledb.js
  2. +3 −2 package.json
  3. +33 −0 test/simpledb.test.js
View
@@ -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
@@ -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
@@ -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

0 comments on commit f8c8ef0

Please sign in to comment.