From: adam Date: Sun, 4 Nov 2012 15:21:54 +0000 (+0700) Subject: #1 X-Git-Tag: v1.2.12~643^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1cab906353cf415db6af64f91b99c17fbdac9848;p=platform%2Fupstream%2Fejdb.git #1 --- diff --git a/.gitignore b/.gitignore index 03d8419..992179d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.o *.vlog +/npm-debug.log /.idea/workspace.xml /tcejdb/Makefile diff --git a/binding.gyp b/binding.gyp index ca5a1c0..4801c14 100644 --- a/binding.gyp +++ b/binding.gyp @@ -19,6 +19,7 @@ '_LARGEFILE_SOURCE', '_FILE_OFFSET_BITS=64', '_GNU_SOURCE', + '_GLIBCXX_PERMIT_BACKWARD_HASH', ], }], [ 'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { diff --git a/node/ejdb.js b/node/ejdb.js index 451306f..72d61ab 100644 --- a/node/ejdb.js +++ b/node/ejdb.js @@ -91,8 +91,8 @@ EJDB.prototype.remove = function(cname, oid, cb) { */ EJDB.prototype.query = function(cname, qobj, orarr, hints, cb) { if (arguments.length == 4) { - hints = orarr; cb = hints; + hints = orarr; orarr = []; } else if (arguments.length == 3) { cb = orarr; diff --git a/node/ejdb_native.cc b/node/ejdb_native.cc index 3a66e77..7a1f7b2 100644 --- a/node/ejdb_native.cc +++ b/node/ejdb_native.cc @@ -11,12 +11,17 @@ #include #include +#include #include -#include + using namespace node; using namespace v8; +#ifdef __GNUC__ +using namespace __gnu_cxx; +#endif + static const int CMD_RET_ERROR = 1; #define DEFINE_INT64_CONSTANT(target, constant) \ @@ -106,9 +111,25 @@ namespace ejdb { return sobj->ToNumber()->NumberValue(); } - typedef struct { - Handle traversed; - } TBSONCTX; + struct V8ObjHash { + + size_t operator()(const Handle& obj) const { + return (size_t) obj->GetIdentityHash(); + } + }; + + struct V8ObjEq { + + bool operator()(const Handle& o1, const Handle& o2) const { + return (o1 == o2); + } + }; + + typedef hash_set, V8ObjHash, V8ObjEq> V8ObjSet; + + struct TBSONCTX { + V8ObjSet tset; //traversed objects set + }; static Handle toV8Object(bson_iterator *it, bson_type obt = BSON_OBJECT); static Handle toV8Value(bson_iterator *it); @@ -322,12 +343,13 @@ namespace ejdb { static void toBSON0(Handle obj, bson *bs, TBSONCTX *ctx) { HandleScope scope; assert(ctx && obj->IsObject()); - if (ctx->traversed->Get(obj)->IsObject()) { + V8ObjSet::iterator it = ctx->tset.find(obj); + if (it != ctx->tset.end()) { bs->err = BSON_ERROR_ANY; bs->errstr = strdup("Circular object reference"); return; } - ctx->traversed->Set(obj, obj); + ctx->tset.insert(obj); Local pnames = obj->GetOwnPropertyNames(); for (uint32_t i = 0; i < pnames->Length(); ++i) { Local pn = pnames->Get(i); @@ -389,7 +411,6 @@ namespace ejdb { static void toBSON(Handle obj, bson *bs) { HandleScope scope; TBSONCTX ctx; - ctx.traversed = Object::New(); toBSON0(obj, bs, &ctx); } @@ -596,7 +617,7 @@ namespace ejdb { )); } bson *bs = bson_create(); - bson_init(bs); + bson_init_as_query(bs); toBSON(Local::Cast(qv), bs); bson_finish(bs); if (bs->err) { diff --git a/node/tests/t2.js b/node/tests/t2.js index 5b9874a..959b1ed 100644 --- a/node/tests/t2.js +++ b/node/tests/t2.js @@ -49,6 +49,7 @@ module.exports.testSaveLoad = function(test) { }); }; +/* module.exports.testQuery1 = function(test) { test.ok(jb); @@ -79,8 +80,20 @@ module.exports.testQuery1 = function(test) { }); }; +*/ + module.exports.testQuery2 = function(test) { - test.done(); + test.ok(jb); + test.ok(jb.isOpen()); + jb.query("parrots", + {name : /(grenny|bounty)/ig}, + {$orderby : {name : 1}}, + function(err, cursor, count) { + test.ifError(err); + console.log("count=" + count); + test.done(); + }); + }; module.exports.testClose = function(test) {