Permalink
Browse files

Add database option support to DB.increment

  • Loading branch information...
1 parent 4422fb8 commit b50fbe494eb3cace6f45bc14cfa19f49f82439d7 @wezm committed Apr 4, 2011
Showing with 17 additions and 6 deletions.
  1. +7 −6 src/db.coffee
  2. +10 −0 test/db_test.coffee
View
13 src/db.coffee
@@ -196,17 +196,18 @@ class DB
increment: (key, num, 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 increment");
- rpc_args =
- key: key
- num: num
- rpc_args.DB = database if database?
+ rpc_args = this._initRpcArgs options
+ rpc_args.key = key
+ rpc_args.num = num
@rpcClient.call 'increment', rpc_args, (error, status, output) ->
if error?
callback error, output
View
10 test/db_test.coffee
@@ -219,6 +219,16 @@ module.exports =
test.ok error?
test.done()
+ 'allows the database to be specified': (test) ->
+ test.expect 2
+ db.increment 'test', 10, {database: 'test2.kct'}, (error, output) ->
+ test.ifError error
+
+ # Check that the value wasn't set on the default db
+ db.get 'test', (error, value) ->
+ test.ok value == null
+ test.done()
+
incrementDouble: testCase
setUp: dbClear

0 comments on commit b50fbe4

Please sign in to comment.