Browse files

Add database option support to DB.removeBulk

  • Loading branch information...
1 parent 27d4c95 commit 85942b16c4491b9b0dff5775f7427106f121b467 @wezm committed Apr 5, 2011
Showing with 30 additions and 12 deletions.
  1. +7 −6 src/db.coffee
  2. +23 −6 test/db_test.coffee
View
13 src/db.coffee
@@ -330,18 +330,19 @@ class DB
else
callback new Error("Unexpected response from server: #{status}"), output
- removeBulk: (records, args...) ->
+ removeBulk: (keys, args...) ->
switch args.length
- when 1 then callback = args[0]
+ when 1
+ options = {}
+ callback = args[0]
when 2
- database = args[0]
+ options = args[0]
callback = args[1]
else
throw new Error("Invalid number of arguments (#{args.length}) to removeBulk");
- rpc_args = {}
- rpc_args.DB = database if database?
- rpc_args["_#{key}"] = '' for key, value of records
+ rpc_args = this._initRpcArgs options
+ rpc_args["_#{key}"] = '' for key in keys
@rpcClient.call 'remove_bulk', rpc_args, (error, status, output) ->
if error?
View
29 test/db_test.coffee
@@ -417,20 +417,37 @@ module.exports =
test.done()
removeBulk: testCase
- setUp: dbClear
+ setUp: (callback) ->
+ @records =
+ bulk1: "Bulk\tValue"
+ bulk2: "Bulk Value 2"
+ dbClear callback
'allows multiple values to be removed at once': (test) ->
test.expect 3
- records =
- bulk1: "Bulk\tValue"
- bulk2: "Bulk Value 2"
- db.setBulk records, testDb, (error, output) ->
+ db.setBulk @records, (error, output) =>
test.equal output.num, '2'
- db.removeBulk records, testDb, (error, output) ->
+ db.removeBulk Object.keys(@records), (error, output) ->
test.ifError error
test.equal output.num, '2'
test.done()
+ 'allows the database to be specified': (test) ->
+ test.expect 3
+ options = {database: 'test2.kct'}
+ db.setBulk @records, (error, output) =>
+ db.setBulk @records, options, (error, output) =>
+ db.removeBulk Object.keys(@records), options, (error, output) ->
+ test.ifError error
+
+ # Check the it removed from the specified db and not the other
+ db.get 'bulk1', options, (error, value) ->
+ test.ok value == null
+
+ db.get 'bulk2', (error, value) ->
+ test.equal value, "Bulk Value 2"
+ test.done()
+
getBulk: testCase
setUp: dbClear

0 comments on commit 85942b1

Please sign in to comment.