From c9c9e86ce2cbaf26d1a1a18b40b2e32516e65103 Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 5 Nov 2012 23:57:13 +0700 Subject: [PATCH] #1 --- README.md | 26 ++++++++++++++++++-- node/ejdb.js | 4 +++- package.json | 3 --- tcejdb/README | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 101 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6867fab..e19249c 100644 --- a/README.md +++ b/README.md @@ -83,13 +83,34 @@ Installation On Debian/Ubuntu linux you can install it as follows: ```sh - sudo apt-get install libcunit1 libcunit1-dev zlib1g zlib1g-dev + sudo apt-get install g++ libcunit1 libcunit1-dev zlib1g zlib1g-dev ``` **Installation from node package manager:** ```npm install ejdb``` +EJDB NodeJS API +---------------------------------- + + +### EJDB.open(dbFile, openMode) + +Open database. Returns database instance handle object. +
Default open mode: `JBOWRITER | JBOCREAT`. +
This is blocking function. + +__Arguments__ + + * {String} dbFile Database main file name + * {Number} `[openMode=JBOWRITER | JBOCREAT]` Bitmast of open modes: + - `JBOREADER` Open as a reader. + - `JBOWRITER` Open as a writer. + - `JBOCREAT` Create db if it not exists + - `JBOTRUNC` Truncate db. + + + EJDB C Library ================================== @@ -168,13 +189,14 @@ Prerequisites -------------------------------- **System libraries:** +* gcc * cunit * zlib On Debian/Ubuntu linux you can install it as follows: ```sh - sudo apt-get install libcunit1 libcunit1-dev zlib1g zlib1g-dev + sudo apt-get install gcc libcunit1 libcunit1-dev zlib1g zlib1g-dev ``` Building diff --git a/node/ejdb.js b/node/ejdb.js index 60a6f27..bf0bc99 100644 --- a/node/ejdb.js +++ b/node/ejdb.js @@ -24,10 +24,12 @@ EJDB.DEFAULT_OPEN_MODE = DEFAULT_OPEN_MODE; * Open database. * Returns database instance handle object . * + * Default open mode: JBOWRITER | JBOCREAT + * * This is blocking function. * * @param {String} dbFile Database main file name - * @param {Number} [openMode] Bitmast of open modes: + * @param {Number} [openMode=JBOWRITER | JBOCREAT] Bitmast of open modes: * - `JBOREADER` Open as a reader. * - `JBOWRITER` Open as a writer. * - `JBOCREAT` Create db if it not exists diff --git a/package.json b/package.json index 70a27ad..e65f26b 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,6 @@ "dependencies" : { "nodeunit" : ">=0.7.0" }, - "devDependencies" : { - "nodeunit" : ">=0.7.0" - }, "scripts" : { "preinstall" : "make all && node-gyp rebuild && make -f tests.mk check", "test" : "make -f tests.mk check-all" diff --git a/tcejdb/README b/tcejdb/README index 60bc822..3fef5be 100644 --- a/tcejdb/README +++ b/tcejdb/README @@ -18,6 +18,78 @@ Features * Collection level transactions. * String token matching queries: ```$stror``` ```$strand``` +NodeJS binding +================================= + +One snippet intro +--------------------------------- +```JavaScript +var EJDB = require("ejdb"); +//Open zoo DB +var jb = EJDB.open("zoo", EJDB.DEFAULT_OPEN_MODE | EJDB.JBOTRUNC); + +var parrot1 = { + "name" : "Grenny", + "type" : "African Grey", + "male" : true, + "age" : 1, + "birthdate" : new Date(), + "likes" : ["green color", "night", "toys"], + "extra1" : null +}; +var parrot2 = { + "name" : "Bounty", + "type" : "Cockatoo", + "male" : false, + "age" : 15, + "birthdate" : new Date(), + "likes" : ["sugar cane"] +}; + +jb.save("parrots", [parrot1, parrot2], function(err, oids) { + if (err) { + console.error(err); + return; + } + console.log("Grenny OID: " + parrot1["_id"]); + console.log("Bounty OID: " + parrot2["_id"]); + + jb.find("parrots", + {"likes" : "toys"}, + {"$orderby" : {"name" : 1}}, + function(err, cursor, count) { + if (err) { + console.error(err); + return; + } + console.log("Found " + count + " parrots"); + while (cursor.next()) { + console.log(cursor.field("name") + " likes toys!"); + } + cursor.close(); //It's not mandatory to close cursor explicitly + jb.close(); //Close the database + }); +}); +``` + +Installation +-------------------------------- +**System libraries:** + +* g++ +* cunit +* zlib + +On Debian/Ubuntu linux you can install it as follows: + +```sh + sudo apt-get install g++ libcunit1 libcunit1-dev zlib1g zlib1g-dev +``` + +**Installation from node package manager:** + ```npm install ejdb``` + + EJDB C Library ================================== @@ -96,13 +168,14 @@ Prerequisites -------------------------------- **System libraries:** +* gcc * cunit * zlib On Debian/Ubuntu linux you can install it as follows: ```sh - sudo apt-get install libcunit1 libcunit1-dev zlib1g zlib1g-dev + sudo apt-get install gcc libcunit1 libcunit1-dev zlib1g zlib1g-dev ``` Building @@ -217,4 +290,3 @@ Limitations/TODOs * Case insensitive string indexes * Collect collection index statistic * Windows port - -- 2.7.4