From 9e39c705a2d480d5fda082b6e0fbc6c0a2d66d6a Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 3 Nov 2012 23:38:45 +0700 Subject: [PATCH] #1 --- .idea/jsLibraryMappings.xml | 8 +++++++ node/ejdb.js | 46 +++++++++++++++++++++++++++++++++++++++ node/nbproject/configurations.xml | 8 ------- node/tests/t2.js | 17 ++++++++++++++- tcejdb/tcejdb.iml | 1 + 5 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 .idea/jsLibraryMappings.xml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..14019d8 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/node/ejdb.js b/node/ejdb.js index 50b9769..451306f 100644 --- a/node/ejdb.js +++ b/node/ejdb.js @@ -72,5 +72,51 @@ EJDB.prototype.load = function(cname, oid, cb) { }; +EJDB.prototype.remove = function(cname, oid, cb) { + return this._impl.remove(cname, oid, cb); +}; + +/** + * + * Calling variations: + * - query(cname, qobj, qobjarr, hints, cb) + * - query(cname, qobj, hints, cb) + * - query(cname, qobj, cb) + * + * @param cname + * @param qobj + * @param orarr + * @param hints + * @param cb + */ +EJDB.prototype.query = function(cname, qobj, orarr, hints, cb) { + if (arguments.length == 4) { + hints = orarr; + cb = hints; + orarr = []; + } else if (arguments.length == 3) { + cb = orarr; + orarr = []; + hints = {}; + } + if (typeof cb !== "function") { + throw new Error("Callback 'cb' argument must be specified"); + } + if (typeof cname !== "string") { + throw new Error("Collection name 'cname' argument must be specified"); + } + if (typeof hints !== "object") { + hints = {}; + } + if (typeof qobj !== "object") { + qobj = {}; + } + return this._impl.query(cname, + [qobj].concat(orarr, hints), + (hints["onlycount"] ? ejdblib.JBQRYCOUNT : 0), + cb); +}; + + module.exports = EJDB; diff --git a/node/nbproject/configurations.xml b/node/nbproject/configurations.xml index 8e4ba2b..bd5be3b 100644 --- a/node/nbproject/configurations.xml +++ b/node/nbproject/configurations.xml @@ -2,14 +2,6 @@ - - - - - - - - diff --git a/node/tests/t2.js b/node/tests/t2.js index fb40027..3f4b04d 100644 --- a/node/tests/t2.js +++ b/node/tests/t2.js @@ -10,6 +10,7 @@ module.exports.testSetup = function(test) { }; module.exports.testSaveLoad = function(test) { + test.ok(jb); test.ok(jb.isOpen()); var parrot1 = { "name" : "Grenny", @@ -45,7 +46,21 @@ module.exports.testSaveLoad = function(test) { module.exports.testQuery1 = function(test) { - test.done(); + test.ok(jb); + test.ok(jb.isOpen()); + jb.query("parrots", {}, function(err, cursor, count) { + test.ifError(err); + test.equal(count, 2); + test.ok(cursor); + var c = 0; + while (cursor.next()) { + ++c; + } + test.equal(c, 2); + + test.ifError(err); + test.done(); + }); }; module.exports.testClose = function(test) { diff --git a/tcejdb/tcejdb.iml b/tcejdb/tcejdb.iml index 9f9a6f2..5fa768d 100644 --- a/tcejdb/tcejdb.iml +++ b/tcejdb/tcejdb.iml @@ -8,6 +8,7 @@ + -- 2.7.4