Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add database option support to DB.set

  • Loading branch information...
commit c344f6ed34c80a819e0658efb2e10e398da3db82 1 parent 424781f
Wesley Moore authored
Showing with 21 additions and 11 deletions.
  1. +5 −3 src/db.coffee
  2. +16 −8 test/db_test.coffee
8 src/db.coffee
View
@@ -109,14 +109,16 @@ class DB
# Note: value can be a string or Buffer for utf-8 strings it should be a Buffer
set: (key, value, 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 set");
- @restClient.put key, value, database, (error) ->
+ @restClient.put key, value, options.database or @database, (error) ->
callback error
# Add a record if it doesn't already exist
24 test/db_test.coffee
View
@@ -63,15 +63,13 @@ module.exports =
test.equal output.path, 'test2.kct'
test.done()
- # TODO: set should accept numeric values and store them as such in Kyoto.
- # This would allow them to be incremented/decremented with the appropriate
- # functions.
+ # TODO: set should accept Numbers
set: testCase
setUp: dbClear
'completes without error': (test) ->
test.expect 1
- db.set 'test', "Test", testDb, (error, output) ->
+ db.set 'test', "Test", (error, output) ->
test.ifError error
test.done()
@@ -82,19 +80,29 @@ module.exports =
barrier++
if barrier == 4
test.done()
- db.set 'test', '\u00bd + \u00bc = \u00be', testDb, (error, output) ->
+ db.set 'test', '\u00bd + \u00bc = \u00be', (error, output) ->
test.ifError error
done()
- db.set 'test2', '\u00bd + \u00bc = \u00be', testDb, (error, output) ->
+ db.set 'test2', '\u00bd + \u00bc = \u00be', (error, output) ->
test.ifError error
done()
- db.set 'test3', '\u00bd + \u00bc = \u00be', testDb, (error, output) ->
+ db.set 'test3', '\u00bd + \u00bc = \u00be', (error, output) ->
test.ifError error
done()
- db.set 'test4', '\u00bd + \u00bc = \u00be', testDb, (error, output) ->
+ db.set 'test4', '\u00bd + \u00bc = \u00be', (error, output) ->
test.ifError error
done()
+ 'allows the database to be specified': (test) ->
+ test.expect 2
+ db.set 'test', 'other db', {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()
+
add: testCase
setUp: dbClear
Please sign in to comment.
Something went wrong with that request. Please try again.