-var ejdblib = require("build/Release/ejdb_native");
\ No newline at end of file
+var ejdblib = require("./build/Release/ejdb_native");
+var EJDBImpl = ejdblib.NodeEJDB
+
+const DEFAULT_OPEN_MODE = (ejdblib.JBOWRITER | ejdblib.JBOCREAT);
+var EJDB = function(dbFile, openMode) {
+ this._impl = new EJDBImpl(dbFile, (openMode > 0) ? openMode : DEFAULT_OPEN_MODE);
+ return this;
+};
+
+for (var k in ejdblib) { //Export constants
+ if (k.indexOf("JB") === 0) {
+ EJDB[k] = ejdblib[k];
+ }
+}
+EJDB.DEFAULT_OPEN_MODE = DEFAULT_OPEN_MODE;
+
+EJDB.open = function(dbFile, openMode) {
+ return new EJDB(dbFile, openMode);
+};
+
+EJDB.prototype.close = function() {
+ return this._impl.close();
+}
+
+
+module.exports = EJDB;
+
#include <v8.h>
#include <node.h>
#include <ejdb.h>
-#include <locale.h>
-#include <stdio.h>
#include "ejdb_args.h"
#include "ejdb_cmd.h"
#include "ejdb_logging.h"
#include "ejdb_thread.h"
+#include <sstream>
+#include <locale.h>
+#include <stdio.h>
+
using namespace node;
using namespace v8;
static Persistent<FunctionTemplate> constructor_template;
+ EJDB *m_jb;
+
static Handle<Value> s_new_object(const Arguments& args) {
HandleScope scope;
REQ_STR_ARG(0, dbPath);
-
+ REQ_INT32_ARG(1, mode);
+ NodeEJDB *nejdb = new NodeEJDB();
+ if (!nejdb->open(*dbPath, mode)) {
+ std::ostringstream os;
+ os << "Unable to open database: " << (*dbPath) << " error: " << nejdb->jb_error_msg();
+ EJ_LOG_ERROR(os.str().c_str());
+ delete nejdb;
+ return scope.Close(ThrowException(Exception::Error(String::New(os.str().c_str()))));
+ }
+ nejdb->Wrap(args.This());
return scope.Close(args.This());
}
- NodeEJDB() {
+ NodeEJDB() : m_jb(NULL) {
}
virtual ~NodeEJDB() {
+ if (m_jb) {
+ ejdbdel(m_jb);
+ }
+ }
+
+ bool open(const char* dbpath, int mode) {
+ m_jb = ejdbnew();
+ if (!m_jb) {
+ return false;
+ }
+ return ejdbopen(m_jb, dbpath, mode);
+ }
+
+ bool close() {
+ if (m_jb) {
+ return ejdbclose(m_jb);
+ }
+ }
+
+ const char* jb_error_msg() {
+ return m_jb ? ejdberrmsg(ejdbecode(m_jb)) : "unknown";
}
+
public:
static void Init(Handle<Object> target) {
HandleScope scope;
-
Local<FunctionTemplate> t = FunctionTemplate::New(s_new_object);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("NodeEJDB"));
+
+ //Open mode
+ NODE_DEFINE_CONSTANT(target, JBOREADER);
+ NODE_DEFINE_CONSTANT(target, JBOWRITER);
+ NODE_DEFINE_CONSTANT(target, JBOCREAT);
+ NODE_DEFINE_CONSTANT(target, JBOTRUNC);
+ NODE_DEFINE_CONSTANT(target, JBONOLCK);
+ NODE_DEFINE_CONSTANT(target, JBOLCKNB);
+ NODE_DEFINE_CONSTANT(target, JBOTSYNC);
+
+ //Indexes
+ NODE_DEFINE_CONSTANT(target, JBIDXDROP);
+ NODE_DEFINE_CONSTANT(target, JBIDXDROPALL);
+ NODE_DEFINE_CONSTANT(target, JBIDXOP);
+ NODE_DEFINE_CONSTANT(target, JBIDXREBLD);
+ NODE_DEFINE_CONSTANT(target, JBIDXNUM);
+ NODE_DEFINE_CONSTANT(target, JBIDXSTR);
+ NODE_DEFINE_CONSTANT(target, JBIDXARR);
+
+ //Misc
+ NODE_DEFINE_CONSTANT(target, JBQRYCOUNT);
+
+ target->Set(v8::String::NewSymbol("NodeEJDB"), constructor_template->GetFunction());
}
void Ref() {
<df name="obj.target">
<df name="ejdb_native">
</df>
- <in>ejdb_native.node</in>
</df>
- <in>ejdb_native.node</in>
- <in>linker.lock</in>
</df>
<in>Makefile</in>
<in>binding.Makefile</in>
</df>
</df>
</df>
+ <df name="win32">
+ <in>pthread_mutex.h</in>
+ </df>
+ <in>ejdb_args.h</in>
+ <in>ejdb_cmd.h</in>
+ <in>ejdb_logging.cc</in>
+ <in>ejdb_logging.h</in>
<in>ejdb_native.cc</in>
+ <in>ejdb_thread.h</in>
</df>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
--- /dev/null
+var EJDB = require("../ejdb.js");
+
+module.exports.testOpenClose = function(test) {
+ var jb = EJDB.open("tdb1");
+ test.done();
+}
\ No newline at end of file
EJDB_EXPORT const char* ejdberrmsg(int ecode) {
switch (ecode) {
- case JDBEINVALIDCOLNAME: return "invalid collection name";
- case JDBEINVALIDBSON: return "invalid bson object";
- case JDBEQINVALIDQCONTROL: return "invalid query control field starting with '$'";
- case JDBEQINOPNOTARRAY: return "$strand, $stror, $in, $nin, $bt keys requires not empty array value";
- case JDBEMETANVALID: return "inconsistent database metadata";
- case JDBEFPATHINVALID: return "invalid JSON field path value";
- case JDBEQINVALIDQRX: return "invalid query regexp value";
- case JDBEQRSSORTING: return "result set sorting error";
- case JDBQINVALID: return "query generic error";
+ case JBEINVALIDCOLNAME: return "invalid collection name";
+ case JBEINVALIDBSON: return "invalid bson object";
+ case JBEQINVALIDQCONTROL: return "invalid query control field starting with '$'";
+ case JBEQINOPNOTARRAY: return "$strand, $stror, $in, $nin, $bt keys requires not empty array value";
+ case JBEMETANVALID: return "inconsistent database metadata";
+ case JBEFPATHINVALID: return "invalid JSON field path value";
+ case JBEQINVALIDQRX: return "invalid query regexp value";
+ case JBEQRSSORTING: return "result set sorting error";
+ case JBEQERROR: return "query generic error";
default: return tcerrmsg(ecode);
}
}
return coll;
}
if (!JBISVALCOLNAME(colname)) {
- _ejdbsetecode(jb, JDBEINVALIDCOLNAME, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jb, JBEINVALIDCOLNAME, __FILE__, __LINE__, __func__);
return NULL;
}
JBENSUREOPENLOCK(jb, true, NULL);
bson_iterator it;
int tcitype = 0; //TCDB index type
int oldiflags = 0; //Old index flags stored in meta
- bool ibld = (flags & JDIDXREBLD);
+ bool ibld = (flags & JBIDXREBLD);
if (ibld) {
- flags &= ~JDIDXREBLD;
+ flags &= ~JBIDXREBLD;
}
- bool idrop = (flags & JDIDXDROP);
+ bool idrop = (flags & JBIDXDROP);
if (idrop) {
- flags &= ~JDIDXDROP;
+ flags &= ~JBIDXDROP;
}
- bool idropall = (flags & JDIDXDROPALL);
+ bool idropall = (flags & JBIDXDROPALL);
if (idropall) {
idrop = true;
- flags &= ~JDIDXDROPALL;
+ flags &= ~JBIDXDROPALL;
}
- bool iop = (flags & JDIDXOP);
+ bool iop = (flags & JBIDXOP);
if (iop) {
- flags &= ~JDIDXOP;
+ flags &= ~JBIDXOP;
}
char ipath[BSON_MAX_FPATH_LEN + 2]; //add 2 bytes for one char prefix and '\0'term
char ikey[BSON_MAX_FPATH_LEN + 2]; //add 2 bytes for one char prefix and '\0'term
int fpathlen = strlen(fpath);
if (fpathlen > BSON_MAX_FPATH_LEN) {
- _ejdbsetecode(jcoll->jb, JDBEFPATHINVALID, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jcoll->jb, JBEFPATHINVALID, __FILE__, __LINE__, __func__);
rv = false;
goto finish;
}
goto finish;
}
if (tcitype) {
- if (flags & JDIDXSTR) {
+ if (flags & JBIDXSTR) {
ipath[0] = 's';
rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, NULL);
}
- if (rv && (flags & JDIDXNUM)) {
+ if (rv && (flags & JBIDXNUM)) {
ipath[0] = 'n';
rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, NULL);
}
- if (rv && (flags & JDIDXARR)) {
+ if (rv && (flags & JBIDXARR)) {
ipath[0] = 'a';
rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, NULL);
}
}
}
} else {
- if ((flags & JDIDXSTR) && (ibld || !(oldiflags & JDIDXSTR))) {
+ if ((flags & JBIDXSTR) && (ibld || !(oldiflags & JBIDXSTR))) {
ipath[0] = 's';
rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITLEXICAL, _bsonipathrowldr, NULL);
}
- if (rv && (flags & JDIDXNUM) && (ibld || !(oldiflags & JDIDXNUM))) {
+ if (rv && (flags & JBIDXNUM) && (ibld || !(oldiflags & JBIDXNUM))) {
ipath[0] = 'n';
rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITDECIMAL, _bsonipathrowldr, NULL);
}
- if (rv && (flags & JDIDXARR) && (ibld || !(oldiflags & JDIDXARR))) {
+ if (rv && (flags & JBIDXARR) && (ibld || !(oldiflags & JBIDXARR))) {
ipath[0] = 'a';
rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITTOKEN, _bsonipathrowldr, NULL);
}
_qrydup(q, ejq, EJQINTERNAL);
*outcount = 0;
- bool onlycount = (qflags & EJQRYCOUNT); //quering only for result set count
+ bool onlycount = (qflags & JBQRYCOUNT); //quering only for result set count
bool all = false; //need all records
EJQF *mqf = NULL; //main indexed query condition if exists
sctx.ofs = ofs;
sctx.ofsz = ofsz;
if (ejdbtimsortlist(res, _ejdbsoncmp, &sctx)) {
- _ejdbsetecode(jcoll->jb, JDBEQRSSORTING, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jcoll->jb, JBEQRSSORTING, __FILE__, __LINE__, __func__);
}
finish:
//revert max
return NULL;
}
int iflags = bson_iterator_int(&it);
- if (iflags & JDIDXARR) { //array token index exists so convert qf into TDBQCSTROR
+ if (iflags & JBIDXARR) { //array token index exists so convert qf into TDBQCSTROR
for (int i = 0; i < tdb->inum; ++i) {
TDBIDX *idx = tdb->idxs + i;
if (!strcmp(qf->fpath, idx->name + 1)) {
TCMAP *cmeta = tctdbget(jb->metadb, colname, colnamesz);
if (!cmeta) {
- _ejdbsetecode(jb, JDBEMETANVALID, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jb, JBEMETANVALID, __FILE__, __LINE__, __func__);
rv = false;
goto finish;
}
bson *rv = NULL;
TCMAP *cmeta = tctdbget(jb->metadb, colname, colnamesz);
if (!cmeta) {
- _ejdbsetecode(jb, JDBEMETANVALID, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jb, JBEMETANVALID, __FILE__, __LINE__, __func__);
return NULL;
}
int bsz;
char fpathkey[BSON_MAX_FPATH_LEN + 1];
TCMAP *cmeta = tctdbget(jcoll->jb->metadb, jcoll->cname, jcoll->cnamesz);
if (!cmeta) {
- _ejdbsetecode(jcoll->jb, JDBEMETANVALID, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jcoll->jb, JBEMETANVALID, __FILE__, __LINE__, __func__);
goto finish;
}
int klen = snprintf(fpathkey, BSON_MAX_FPATH_LEN + 1, "i%s", ipath); //'i' prefix for all columns with index meta
if (klen > BSON_MAX_FPATH_LEN) {
- _ejdbsetecode(jcoll->jb, JDBEFPATHINVALID, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jcoll->jb, JBEFPATHINVALID, __FILE__, __LINE__, __func__);
goto finish;
}
int bsz;
qf.ftype = ftype;
} else {
if (!pqf) { //Require parent query object
- ret = JDBQINVALID;
+ ret = JBEQERROR;
break;
}
qf = *pqf;
strcmp("$bt", fkey) &&
strcmp("$strand", fkey) &&
strcmp("$stror", fkey)) {
- ret = JDBEQINVALIDQCONTROL;
+ ret = JBEQINVALIDQCONTROL;
break;
}
bson_iterator sit;
bson_type atype = 0;
TCLIST *tokens = _fetch_bson_str_array(&sit, &atype);
if (atype == 0) {
- ret = JDBEQINOPNOTARRAY;
+ ret = JBEQINOPNOTARRAY;
tclistdel(tokens);
break;
}
} else if (!strcmp("$bt", fkey)) { //between
qf.tcop = TDBQCNUMBT;
if (TCLISTNUM(tokens) != 2) {
- ret = JDBEQINOPNOTARRAY;
+ ret = JBEQINOPNOTARRAY;
TCFREE(qf.expr);
tclistdel(qf.exprlist);
break;
TCMALLOC(qf.regex, sizeof (rxbuf));
memcpy(qf.regex, &rxbuf, sizeof (rxbuf));
} else {
- ret = JDBEQINVALIDQRX;
+ ret = JBEQINVALIDQRX;
TCFREE(qf.fpath);
TCFREE(qf.expr);
break;
bool rv = true;
TCMAP *cmeta = tctdbget(jcoll->jb->metadb, jcoll->cname, jcoll->cnamesz);
if (!cmeta) {
- _ejdbsetecode(jcoll->jb, JDBEMETANVALID, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jcoll->jb, JBEMETANVALID, __FILE__, __LINE__, __func__);
return false;
}
TCMAP *imap = NULL; //New index map
imap = tcmapnew2(16);
rimap = tcmapnew2(16);
}
- for (int i = 4; i <= 6; ++i) { /* JDIDXNUM, JDIDXSTR, JDIDXARR */
+ for (int i = 4; i <= 6; ++i) { /* JBIDXNUM, JBIDXSTR, JBIDXARR */
bool rm = false;
- if ((1 << i) == JDIDXNUM && (JDIDXNUM & iflags)) {
+ if ((1 << i) == JBIDXNUM && (JBIDXNUM & iflags)) {
ikey[0] = 'n';
- } else if ((1 << i) == JDIDXSTR && (JDIDXSTR & iflags)) {
+ } else if ((1 << i) == JBIDXSTR && (JBIDXSTR & iflags)) {
ikey[0] = 's';
- } else if ((1 << i) == JDIDXARR && (JDIDXARR & iflags)) {
+ } else if ((1 << i) == JBIDXARR && (JBIDXARR & iflags)) {
ikey[0] = 'a';
if (ofvalue && oft == BSON_ARRAY &&
(!fvalue || ft != oft || fvaluesz != ofvaluesz || memcmp(fvalue, ofvalue, fvaluesz))) {
static bool _createcoldb(const char* colname, EJDB *jb, EJCOLLOPTS *opts, TCTDB **res) {
assert(jb && jb->metadb);
if (!JBISVALCOLNAME(colname)) {
- _ejdbsetecode(jb, JDBEINVALIDCOLNAME, __FILE__, __LINE__, __func__);
+ _ejdbsetecode(jb, JBEINVALIDCOLNAME, __FILE__, __LINE__, __func__);
*res = NULL;
return false;
}
#define JBMAXCOLNAMELEN 128
enum { /** Error codes */
- JDBEINVALIDCOLNAME = 9000, /**< Invalid collection name. */
- JDBEINVALIDBSON = 9001, /**< Invalid bson object. */
- JDBEQINVALIDQCONTROL = 9002, /**< Invalid query control field starting with '$'. */
- JDBEQINOPNOTARRAY = 9003, /**< $strand, $stror, $in, $nin, $bt keys requires not empty array value. */
- JDBEMETANVALID = 9004, /**< Inconsistent database metadata. */
- JDBEFPATHINVALID = 9005, /**< Invalid field path value. */
- JDBEQINVALIDQRX = 9006, /**< Invalid query regexp value. */
- JDBEQRSSORTING = 9007, /**< Result set sorting error. */
- JDBQINVALID = 9008 /**< Query generic error. */
+ JBEINVALIDCOLNAME = 9000, /**< Invalid collection name. */
+ JBEINVALIDBSON = 9001, /**< Invalid bson object. */
+ JBEQINVALIDQCONTROL = 9002, /**< Invalid query control field starting with '$'. */
+ JBEQINOPNOTARRAY = 9003, /**< $strand, $stror, $in, $nin, $bt keys requires not empty array value. */
+ JBEMETANVALID = 9004, /**< Inconsistent database metadata. */
+ JBEFPATHINVALID = 9005, /**< Invalid field path value. */
+ JBEQINVALIDQRX = 9006, /**< Invalid query regexp value. */
+ JBEQRSSORTING = 9007, /**< Result set sorting error. */
+ JBEQERROR = 9008 /**< Query generic error. */
};
enum { /** Database open modes */
- JDBOREADER = 1 << 0, /**< Open as a reader. */
- JDBOWRITER = 1 << 1, /**< Open as a writer. */
- JDBOCREAT = 1 << 2, /**< Create if db file not exists. */
- JDBOTRUNC = 1 << 3, /**< Truncate db. */
- JDBONOLCK = 1 << 4, /**< Open without locking. */
- JDBOLCKNB = 1 << 5, /**< Lock without blocking. */
- JDBOTSYNC = 1 << 6 /**< Synchronize every transaction. */
+ JBOREADER = 1 << 0, /**< Open as a reader. */
+ JBOWRITER = 1 << 1, /**< Open as a writer. */
+ JBOCREAT = 1 << 2, /**< Create if db file not exists. */
+ JBOTRUNC = 1 << 3, /**< Truncate db. */
+ JBONOLCK = 1 << 4, /**< Open without locking. */
+ JBOLCKNB = 1 << 5, /**< Lock without blocking. */
+ JBOTSYNC = 1 << 6 /**< Synchronize every transaction. */
};
enum { /** Index modes, index types. */
- JDIDXDROP = 1 << 0, /**< Drop index. */
- JDIDXDROPALL = 1 << 1, /**< Drop index for all types. */
- JDIDXOP = 1 << 2, /**< Optimize index. */
- JDIDXREBLD = 1 << 3, /**< Rebuild index. */
- JDIDXNUM = 1 << 4, /**< Number index. */
- JDIDXSTR = 1 << 5, /**< String index.*/
- JDIDXARR = 1 << 6, /**< Array token index. */
+ JBIDXDROP = 1 << 0, /**< Drop index. */
+ JBIDXDROPALL = 1 << 1, /**< Drop index for all types. */
+ JBIDXOP = 1 << 2, /**< Optimize index. */
+ JBIDXREBLD = 1 << 3, /**< Rebuild index. */
+ JBIDXNUM = 1 << 4, /**< Number index. */
+ JBIDXSTR = 1 << 5, /**< String index.*/
+ JBIDXARR = 1 << 6, /**< Array token index. */
};
enum { /*< Query search mode flags in ejdbqrysearch() */
- EJQRYCOUNT = 1 /*< Query only count(*) */
+ JBQRYCOUNT = 1 /*< Query only count(*) */
};
/**
* @param jb Database object created with `ejdbnew'
* @param path Path to the database file.
* @param mode Open mode bitmask flags:
- * `JDBOREADER` Open as a reader.
- * `JDBOWRITER` Open as a writer.
- * `JDBOCREAT` Create db if it not exists
- * `JDBOTRUNC` Truncate db.
- * `JDBONOLCK` Open without locking.
- * `JDBOLCKNB` Lock without blocking.
- * `JDBOTSYNC` Synchronize every transaction.
+ * `JBOREADER` Open as a reader.
+ * `JBOWRITER` Open as a writer.
+ * `JBOCREAT` Create db if it not exists
+ * `JBOTRUNC` Truncate db.
+ * `JBONOLCK` Open without locking.
+ * `JBOLCKNB` Lock without blocking.
+ * `JBOTSYNC` Synchronize every transaction.
* @return
*/
EJDB_EXPORT bool ejdbopen(EJDB *jb, const char *path, int mode);
* Set index for JSON field in EJDB collection.
*
* - Available index types:
- * - `JDIDXSTR` String index for JSON string values.
- * - `JDIDXNUM` Index for JSON number values.
- * - `JDIDXARR` Token index for JSON arrays and string values.
+ * - `JBIDXSTR` String index for JSON string values.
+ * - `JBIDXNUM` Index for JSON number values.
+ * - `JBIDXARR` Token index for JSON arrays and string values.
*
* - One JSON field can have several indexes for different types.
*
* - Available index operations:
- * - `JDIDXDROP` Drop index of specified type.
- * - Eg: flag = JDIDXDROP | JDIDXNUM (Drop number index)
- * - `JDIDXDROPALL` Drop index for all types.
- * - `JDIDXREBLD` Rebuild index of specified type.
- * - `JDIDXOP` Optimize index of specified type.
+ * - `JBIDXDROP` Drop index of specified type.
+ * - Eg: flag = JBIDXDROP | JBIDXNUM (Drop number index)
+ * - `JBIDXDROPALL` Drop index for all types.
+ * - `JBIDXREBLD` Rebuild index of specified type.
+ * - `JBIDXOP` Optimize index of specified type.
*
* Examples:
* - Set index for JSON path `addressbook.number` for strings and numbers:
- * `ejdbsetindex(ccoll, "album.number", JDIDXSTR | JDIDXNUM)`
+ * `ejdbsetindex(ccoll, "album.number", JBIDXSTR | JBIDXNUM)`
* - Set index for array:
- * `ejdbsetindex(ccoll, "album.tags", JDIDXARR)`
+ * `ejdbsetindex(ccoll, "album.tags", JBIDXARR)`
* - Rebuild previous index:
- * `ejdbsetindex(ccoll, "album.tags", JDIDXARR | JDIDXREBLD)`
+ * `ejdbsetindex(ccoll, "album.tags", JBIDXARR | JBIDXREBLD)`
*
* Many index examples can be found in `testejdb/t2.c` test case.
*
* @param jcoll EJDB database
* @param q Query handle created with ejdbcreatequery()
* @param count Output count pointer. Result set size will be stored into it.
- * @param qflags Execution flag. If EJQRYCOUNT is set the only count of matching records will be computed
+ * @param qflags Execution flag. If JBQRYCOUNT is set the only count of matching records will be computed
* without resultset, this operation is analog of count(*) in SQL and can be faster than operations with resultsets.
* @param log Optional extended string to collect debug information during query execution, can be NULL.
* @return TCLIST with matched bson records data.
- * If (qflags & EJQRYCOUNT) then NULL will be returned
+ * If (qflags & JBQRYCOUNT) then NULL will be returned
* and only count reported.
*/
EJDB_EXPORT TCLIST* ejdbqrysearch(EJCOLL *jcoll, const EJQ *q, uint32_t *count, int qflags, TCXSTR *log);
int main() {
setlocale(LC_ALL, "en_US.UTF-8");
jb = ejdbnew();
- if (!ejdbopen(jb, "addressbook", JDBOWRITER | JDBOCREAT | JDBOTRUNC)) {
+ if (!ejdbopen(jb, "addressbook", JBOWRITER | JBOCREAT | JBOTRUNC)) {
return 1;
}
int init_suite(void) {
jb = ejdbnew();
- if (!ejdbopen(jb, "dbt1", JDBOWRITER | JDBOCREAT | JDBOTRUNC)) {
+ if (!ejdbopen(jb, "dbt1", JBOWRITER | JBOCREAT | JBOTRUNC)) {
return 1;
}
return 0;
int init_suite(void) {
jb = ejdbnew();
- if (!ejdbopen(jb, "dbt2", JDBOWRITER | JDBOCREAT | JDBOTRUNC)) {
+ if (!ejdbopen(jb, "dbt2", JBOWRITER | JBOCREAT | JBOTRUNC)) {
return 1;
}
return 0;
void testSetIndex1() {
EJCOLL *ccoll = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(ccoll);
- CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JDIDXSTR));
- CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JDIDXSTR | JDIDXNUM));
- CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JDIDXDROPALL));
- CU_ASSERT_TRUE(ejdbsetindex(ccoll, "address.zip", JDIDXSTR));
- CU_ASSERT_TRUE(ejdbsetindex(ccoll, "name", JDIDXSTR));
+ CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JBIDXSTR));
+ CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JBIDXSTR | JBIDXNUM));
+ CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JBIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(ccoll, "address.zip", JBIDXSTR));
+ CU_ASSERT_TRUE(ejdbsetindex(ccoll, "name", JBIDXSTR));
//Insert new record with active index
//Record 4
void testQuery3() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.zip", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.zip", JBIDXDROPALL));
bson bsq1;
bson_init_as_query(&bsq1);
void testQuery4() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXDROPALL));
bson bsq1;
bson_init_as_query(&bsq1);
void testQuery6() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JDIDXARR));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JBIDXARR));
bson bsq1;
bson_init_as_query(&bsq1);
void testQuery9() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JBIDXDROPALL));
bson bsq1;
bson_init_as_query(&bsq1);
void testQuery10() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JDIDXSTR));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JBIDXSTR));
//"address.street" : {"$in" : ["Pirogova", "Beverly Hills"]}
bson bsq1;
void testQuery11() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JBIDXDROPALL));
//"address.street" : {"$in" : ["Pirogova", "Beverly Hills"]}
bson bsq1;
void testQuery14() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "drinks", JDIDXARR));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "drinks", JBIDXARR));
//"drinks" : {"$in" : [4, 77676.22]}
bson bsq1;
void testQuery15() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXNUM));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM));
bson bsq1;
bson_init_as_query(&bsq1);
void testQuery16() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL));
bson bsq1;
bson_init_as_query(&bsq1);
void testQuery17() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXNUM));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM));
//"dblscore" : {"$bt" : [0.95, 0.3]}
bson bsq1;
tclistdel(q1res);
ejdbquerydel(q1);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL));
bson_init_as_query(&bsq1);
bson_append_start_object(&bsq1, "dblscore");
void testQuery18() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXARR));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXARR));
//{"name" : {$strand : ["Travolta", "John"]}}
bson bsq1;
//Second query
tcxstrclear(log);
tclistdel(q1res);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXDROPALL));
count = 0;
q1res = ejdbqrysearch(contacts, q1, &count, 0, log);
void testQuery19() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXARR));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXARR));
//{"name" : {$stror : ["Travolta", "Антонов", "John"]}}
bson bsq1;
//No-index query
tcxstrclear(log);
tclistdel(q1res);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXDROPALL));
count = 0;
q1res = ejdbqrysearch(contacts, q1, &count, 0, log);
//{'dblscore' : {'$gte' : 0.93}}
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXNUM));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM));
bson bsq1;
bson_init_as_query(&bsq1);
ejdbquerydel(q1);
//NOINDEX
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL));
//NOINDEX GTE
bson_init_as_query(&bsq1);
//{'dblscore' : {'lte' : 0.93}}
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXNUM));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM));
//LTE
bson bsq1;
tcxstrdel(log);
ejdbquerydel(q1);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL));
//NOINDEX GTE
bson_init_as_query(&bsq1);
void testQuery22() {
EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JDIDXSTR));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JBIDXSTR));
//{"address.country" : {$begin : "Ru"}}
bson bsq1;
tcxstrdel(log);
ejdbquerydel(q1);
- CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JDIDXDROPALL));
+ CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JBIDXDROPALL));
bson_init_as_query(&bsq1);
bson_append_start_object(&bsq1, "address.country");
int init_suite(void) {
assert(QRS < RS);
jb = ejdbnew();
- if (!ejdbopen(jb, "dbt3", JDBOWRITER | JDBOCREAT | JDBOTRUNC)) {
+ if (!ejdbopen(jb, "dbt3", JBOWRITER | JBOCREAT | JBOTRUNC)) {
return 1;
}
srandom(tcmstime());
EJQ *q = ejdbcreatequery(jb, bs, NULL, 0, NULL);
assert(q);
uint32_t count;
- ejdbqrysearch(coll, q, &count, EJQRYCOUNT, NULL);
+ ejdbqrysearch(coll, q, &count, JBQRYCOUNT, NULL);
assert(count);
if (count != 1) {
fprintf(stderr, "CNT=%u\n", count);
i, tcmstime() - st, (unsigned long) ((tcmstime() - st) / QRS));
st = tcmstime();
- CU_ASSERT_TRUE(ejdbsetindex(coll, "rstring", JDIDXSTR));
+ CU_ASSERT_TRUE(ejdbsetindex(coll, "rstring", JBIDXSTR));
fprintf(stderr, "testPerf1(): SET INDEX 'rstring' TIME: %lu ms\n", tcmstime() - st);
st = tcmstime();
EJQ *q = ejdbcreatequery(jb, bs, NULL, 0, NULL);
assert(q);
uint32_t count;
- ejdbqrysearch(coll, q, &count, EJQRYCOUNT, NULL);
+ ejdbqrysearch(coll, q, &count, JBQRYCOUNT, NULL);
assert(count);
acount += count;
ejdbquerydel(q);