Skip to content
Browse files

Merge pull request #28 from Pita/master

Master
  • Loading branch information...
2 parents ebe93bc + 0d1b141 commit 34bb375b6630230e3910f93a8d4373efe2f1a752 @JohnMcLear JohnMcLear committed Jan 15, 2013
Showing with 41 additions and 25 deletions.
  1. +31 −18 findKeysTest.js
  2. +4 −3 mysql_db.js
  3. +2 −1 package.json
  4. +4 −3 postgres_db.js
View
49 findKeysTest.js
@@ -61,28 +61,41 @@ function test ()
//try findKeys
function(callback)
{
- db.db.wrappedDB.findKeys("test:test1", null, function(err, value){
- if(err)
- {
- callback(err);
- return;
- }
-
- try{
- assert.equal(value.length, 1, "different result amount than expected returned: "+value.length);
- assert.equal(value[0], "test:test1", "wrong value returned " + value);
- }
- catch(e)
- {
- console.error(e.message);
- }
-
- callback();
- });
+ doTest("test:test1", null,1,["test:test1"],callback);
+ },
+ //try findKeys
+ function(callback)
+ {
+ doTest("test:*","*:*:*",1,["test:test1"],callback);
+ },
+ //try findKeys
+ function(callback)
+ {
+ doTest("test:*",null,2,["test:test1","test:test1:check:check1"],callback);
},
], function(err){
if(err) throw err;
process.exit();
});
+}
+var doTest=function(key,notKey,expectedLength,expectedValue,callback){
+ db.db.wrappedDB.findKeys(key, notKey, function(err, value){
+ if(err)
+ {
+ callback(err);
+ return;
+ }
+
+ try{
+ assert.deepEqual(value.length, expectedLength, "different result amount than expected returned. Expected: "+expectedLength+", Actual: "+value.length);
+ assert.deepEqual(value, expectedValue, "wrong values returned. Expected: "+expectedValue+", Actual: "+ value);
+ }
+ catch(e)
+ {
+ console.error(e.message);
+ }
+
+ callback();
+ });
}
View
7 mysql_db.js
@@ -102,14 +102,15 @@ exports.database.prototype.get = function (key, callback)
exports.database.prototype.findKeys = function (key, notKey, callback)
{
var query="SELECT `key` FROM `store` WHERE `key` LIKE ?"
- , params=[key]
+ , params=[]
;
//desired keys are %key:%, e.g. pad:%
- key=key.replace(/\*/,'%')+":%";
+ key=key.replace(/\*/g,'%');
+ params.push(key);
if(notKey!=null && notKey != undefined){
//not desired keys are notKey:%, e.g. %:%:%
- notKey=notKey.replace(/\*/,'%')+":%";
+ notKey=notKey.replace(/\*/g,'%');
query+=" AND `key` NOT LIKE ?"
params.push(notKey);
}
View
3 package.json
@@ -5,7 +5,8 @@
"keywords" : ["database", "keyvalue"],
"author" : "Peter 'Pita' Martischka <petermartischka@googlemail.com> - Primary Technology Ltd",
"contributors" : [
- { "name": "John McLear"}
+ { "name": "John McLear"},
+ { "name": "spcsser"}
],
"dependencies" : {
"mysql" : "0.9.5",
View
7 postgres_db.js
@@ -82,14 +82,15 @@ exports.database.prototype.get = function (key, callback)
exports.database.prototype.findKeys = function (key, notKey, callback)
{
var query="SELECT key FROM store WHERE key LIKE $1"
- , params=[key]
+ , params=[]
;
//desired keys are %key:%, e.g. pad:%
- key=key.replace(/\*/,'%')+":%";
+ key=key.replace(/\*/g,'%');
+ params.push(key);
if(notKey!=null && notKey != undefined){
//not desired keys are notKey:%, e.g. %:%:%
- notKey=notKey.replace(/\*/,'%')+":%";
+ notKey=notKey.replace(/\*/g,'%');
query+=" AND key NOT LIKE $2"
params.push(notKey);
}

0 comments on commit 34bb375

Please sign in to comment.
Something went wrong with that request. Please try again.