2.0.3 • Published 9 years ago
maokai v2.0.3
Maokai
Experimental, you have been warned.
npm install maokai
Experimental in-memory database for NodeJS that journals mutations/changes to disk and repeats them on load to restore the model to previous state. It also supports in-memory transaction of sorts, see kernel.js and it's usage of proxywrapper.js
Currently there is one function available named execute
and it's Promise-based.
It works for both commands and queries and detects when a operation changes the model with the help of proxywrapper.js, only changes are journaled to disk.
const Maokai = require('maokai');
const configuration = {
path: './test/temp/',
readonlyJournal: false,
forceNewJournal: false
};
const core = new Maokai(configuration);
// Update/Insert, second parameter is what should be supplied as data
// to the function passed in the first parameter
core.execute((model, data) => model.name = data, "CodeDux");
// You can also return data
core.execute((model) => { return model.name; })
.then((result) => {/* Do something with the result */});
// Or as part of changes
core.execute((model, data) => {
model.name = data;
return model.age;
}, "CodeDux").then((result) => {/* Do something with the result */});