* {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
+ - `JBOCREAT` Create if db file not exists
- `JBOTRUNC` Truncate db.
---------------------------------------
* {String} cname Name of collection.
* {Boolean} `[prune=false]` If true the collection data will erased from disk.
- * {Function} `[cb]` Callback function with arguments: (error)
+ * {Function} `[cb]` Callback args: (error)
---------------------------------------
* {String} **cname** Name of collection.
* {Array|Object} jsarr Signle JSON object or array of JSON objects to save
- * {Function} `[cb]` Callback function with arguments: (error, {Array} of OIDs for saved objects)
+ * {Function} `[cb]` Callback args: (error, {Array} of OIDs for saved objects)
--------------------------------------
* {String} cname Name of collection
* {String} oid Object identifier (OID)
- * {Function} cb Callback function with arguments: (error, obj)
+ * {Function} cb Callback args: (error, obj)
`obj`: Retrieved JSON object or NULL if it is not found.
--------------------------------------
* {String} cname Name of collection
* {String} oid Object identifier (OID)
- * {Function} cb Callback function with arguments: (error)
+ * {Function} cb Callback args: (error)
--------------------------------------
* {Object} qobj Main JSON query object
* {Array} `[orarr]` Array of additional OR query objects (joined with OR predicate).
* {Object} `[hints]` JSON object with query hints.
- * {Function} cb Callback function with arguments: (error, cursor, count)
+ * {Function} cb Callback args: (error, cursor, count)
`cursor`: Cursor object to traverse records
`count`: Total number of selected records
* {Object} qobj Main JSON query object
* {Array} `[orarr]` Array of additional OR query objects (joined with OR predicate).
* {Object} `[hints]` JSON object with query hints.
- * {Function} cb Callback function with arguments: (error, obj)
+ * {Function} cb Callback args: (error, obj)
`obj` Retrieved JSON object or NULL if it is not found.
+-----------------------------------
<a name="count"/>
### count(cname, qobj, orarr, hints, cb)
* {Object} qobj Main JSON query object
* {Array} `[orarr]` Array of additional OR query objects (joined with OR predicate).
* {Object} `[hints]` JSON object with query hints.
- * {Function} cbcb Callback function with arguments: (error, count)
+ * {Function} cb Callback args: (error, count)
`count`: Number of matching records.
+-----------------------------------
+
+<a name="sync"/>
+### sync(cb)
+Synchronize entire EJDB database with disk.
+
+__Arguments__
+
+ * {Function} cb Callback args: (error)
+
+-----------------------------------
+
+<a name="dropIndexes"/>
+### dropIndexes(cname, path, cb)
+Drop indexes of all types for JSON field path.
+
+__Arguments__
+
+ * {String} cname Name of collection
+ * {String} path JSON field path
+ * {Function} `[cb]` Optional callback function. Callback args: (error)
+
+ -----------------------------------
+
+ <a name="optimizeIndexes"/>
+### optimizeIndexes(cname, path, cb)
+Optimize indexes of all types for JSON field path.
+Performs B+ tree index file optimization.
+
+ __Arguments__
+
+ * {String} cname Name of collection
+ * {String} path JSON field path
+ * {Function} `[cb]` Optional callback function. Callback args: (error)
+
+-----------------------------------
+
+<a name="ensureIndex"/>
+### ensureStringIndex(cname, path, cb)
+### ensureNumberIndex(cname, path, cb)
+### ensureArrayIndex(cname, path, cb)
+
+Ensure index presence of String|Number|Array type for JSON field path
+
+ __Arguments__
+
+ * {String} cname Name of collection
+ * {String} path JSON field path
+ * {Function} `[cb]` Optional callback function. Callback args: (error)
+
+-----------------------------------
+
+<a name="rebuildIndex"/>
+### rebuildStringIndex(cname, path, cb)
+### rebuildNumberIndex(cname, path, cb)
+### rebuildArrayIndex(cname, path, cb)
+
+Rebuild index of String|Number|Array type for JSON field path
+
+ __Arguments__
+
+ * {String} cname Name of collection
+ * {String} path JSON field path
+ * {Function} `[cb]` Optional callback function. Callback args: (error)
+
+-----------------------------------
+
+<a name="dropIndex"/>
+### dropStringIndex(cname, path, cb)
+### dropNumberIndex(cname, path, cb)
+### dropArrayIndex(cname, path, cb)
+
+Drop index of String|Number|Array type for JSON field path
+
+ __Arguments__
+
+ * {String} cname Name of collection
+ * {String} path JSON field path
+ * {Function} `[cb]` Optional callback function. Callback args: (error)
+
+-----------------------------------
+
EJDB C Library
==================================
cmdRemove = 3, //Remove BSON by oid
cmdQuery = 4, //Query collection
cmdRemoveColl = 5, //Remove collection
- cmdSetIndex = 6 //Set index
+ cmdSetIndex = 6, //Set index
+ cmdSync = 7 //Sync database
};
struct BSONCmdData { //Any bson related cmd data
return scope.Close(args.This());
}
+ static Handle<Value> s_sync(const Arguments& args) {
+ HandleScope scope;
+ REQ_FUN_ARG(0, cb);
+ NodeEJDB *njb = ObjectWrap::Unwrap< NodeEJDB > (args.This());
+ EJBTask *task = new EJBTask(cb, njb, cmdSync, NULL, NULL);
+ uv_queue_work(uv_default_loop(), &task->uv_work, s_exec_cmd_eio, s_exec_cmd_eio_after);
+ return scope.Close(args.This());
+ }
+
static Handle<Value> s_ecode(const Arguments& args) {
HandleScope scope;
NodeEJDB *njb = ObjectWrap::Unwrap< NodeEJDB > (args.This());
case cmdSetIndex:
set_index((SetIndexCmdTask*) task);
break;
+ case cmdSync:
+ sync(task);
+ break;
+ default:
+ assert(0);
}
}
case cmdSetIndex:
set_index_after((SetIndexCmdTask*) task);
break;
+ case cmdSync:
+ sync_after(task);
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ void sync(EJBTask *task) {
+ if (!_check_state((EJBTask*) task)) {
+ return;
+ }
+ if (!ejdbsyncdb(m_jb)) {
+ task->cmd_ret = CMD_RET_ERROR;
+ task->cmd_ret_msg = _jb_error_msg();
+ }
+ }
+
+ void sync_after(EJBTask *task) {
+ HandleScope scope;
+ Local<Value> argv[1];
+ if (task->cmd_ret != 0) {
+ argv[0] = Exception::Error(String::New(task->cmd_ret_msg.c_str()));
+ } else {
+ argv[0] = Local<Primitive>::New(Null());
+ }
+ TryCatch try_catch;
+ task->cb->Call(Context::GetCurrent()->Global(), 1, argv);
+ if (try_catch.HasCaught()) {
+ FatalException(try_catch);
}
}
NODE_SET_PROTOTYPE_METHOD(constructor_template, "removeCollection", s_rm_collection);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "isOpen", s_is_open);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "setIndex", s_set_index);
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "sync", s_sync);
//Symbols
target->Set(String::NewSymbol("NodeEJDB"), constructor_template->GetFunction());