Permalink
Browse files

Add database option support to DB.setBulk

  • Loading branch information...
1 parent e6917f2 commit 27d4c9537a566ccfd37fda43afc3ac764ad938a8 @wezm committed Apr 4, 2011
Showing with 24 additions and 9 deletions.
  1. +5 −4 src/db.coffee
  2. +19 −5 test/db_test.coffee
View
@@ -310,15 +310,16 @@ class DB
setBulk: (records, 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 setBulk");
- rpc_args = {}
- rpc_args.DB = database if database?
+ rpc_args = this._initRpcArgs options
rpc_args["_#{key}"] = value for key, value of records
@rpcClient.call 'set_bulk', rpc_args, (error, status, output) ->
View
@@ -390,18 +390,32 @@ module.exports =
test.done()
setBulk: testCase
- setUp: dbClear
+ setUp: (callback) ->
+ @records =
+ bulk1: "Bulk\tValue"
+ bulk2: "Bulk Value 2"
+ dbClear callback
'allows multiple values to be set at once': (test) ->
test.expect 2
- records =
- bulk1: "Bulk\tValue"
- bulk2: "Bulk Value 2"
- db.setBulk records, testDb, (error, output) ->
+ db.setBulk @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, options, (error, output) ->
+ test.ifError error
+
+ db.get 'bulk1', (error, value) ->
+ test.ok value == null
+
+ db.get 'bulk2', options, (error, value) ->
+ test.equal value, "Bulk Value 2"
+ test.done()
+
removeBulk: testCase
setUp: dbClear

0 comments on commit 27d4c95

Please sign in to comment.