Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add database option support to DB.matchPrefix and matchRegex

  • Loading branch information...
commit 226485ce4cf6928d9d493e636f33173d007978c4 1 parent 95c449b
@wezm authored
Showing with 30 additions and 13 deletions.
  1. +5 −4 src/db.coffee
  2. +25 −9 test/db_test.coffee
View
9 src/db.coffee
@@ -381,24 +381,25 @@ class DB
callback undefined, results
_matchUsing: (procedure, pattern, args) ->
+ options = {}
switch args.length
- when 1 then callback = args[0]
+ when 1
+ callback = args[0]
when 2
max = args[0]
callback = args[1]
when 3
max = args[0]
- database = args[1]
+ options = args[1]
callback = args[2]
else
throw new Error("Invalid number of arguments (#{args.length}) to #{procedure}");
- rpc_args = {}
+ rpc_args = this._initRpcArgs options
if procedure == 'match_prefix'
rpc_args.prefix = pattern
else
rpc_args.regex = pattern
- rpc_args.DB = database if database?
rpc_args.max = max if max?
@rpcClient.call procedure, rpc_args, (error, status, output) ->
View
34 test/db_test.coffee
@@ -497,10 +497,7 @@ module.exports =
test.equal output.num, '3'
db.matchPrefix 'bulk', null, (error, output) ->
test.ifError error
- test.deepEqual output, [
- 'bulk1',
- 'bulk2'
- ]
+ test.deepEqual output, [ 'bulk1', 'bulk2' ]
test.done()
'allows the number of results to be limited': (test) ->
@@ -513,13 +510,18 @@ module.exports =
test.done()
'allows the database to be specified': (test) ->
- test.expect 3
- db.setBulk @records, (error, output) ->
+ test.expect 5
+ options = {database: 'test2.kct'}
+ db.setBulk @records, options, (error, output) ->
test.equal output.num, '3'
- db.matchPrefix 'bulk', 1, (error, output) ->
+ db.matchPrefix 'bulk', null, options, (error, output) ->
test.ifError error
- test.deepEqual output, [ 'bulk1' ]
- test.done()
+ test.deepEqual output, [ 'bulk1', 'bulk2' ]
+
+ db.matchPrefix 'bulk', (error, output) ->
+ test.ifError error
+ test.deepEqual output, []
+ test.done()
matchRegex: testCase
setUp: (callback) ->
@@ -550,3 +552,17 @@ module.exports =
test.ifError error
test.deepEqual output, [ 'bulk1' ]
test.done()
+
+ 'allows the database to be specified': (test) ->
+ test.expect 5
+ options = {database: 'test2.kct'}
+ db.setBulk @records, options, (error, output) ->
+ test.equal output.num, '4'
+ db.matchRegex 'bulk.*', null, options, (error, output) ->
+ test.ifError error
+ test.deepEqual output, [ 'bulk1', 'bulk2' ]
+
+ db.matchRegex 'bulk.*', (error, output) ->
+ test.ifError error
+ test.deepEqual output, []
+ test.done()
Please sign in to comment.
Something went wrong with that request. Please try again.