grapedb
GrapeDB is a distributed object database. It can be also considered as an ODM.
install
npm install --save grapedb
usage
The main class is AdvancedManager
which has the following public methods:
get(key)
- gets a stringified nodeset(key, value)
- sets a stringified nodegetComplex(key, maxLevel)
- gets recursively an object with nested fields,maxLevel
specifies the maximum depth; whenmaxLevel
isundefined
, the full object is returnedsetComplex(key, value)
- saves an object (creates or updates)
In order to delete an object, use setComplex(key, null)
.
AdvancedManager
requires an injected simple manager and a logger.
The logger should have the following methods:
info(message)
error(message)
The simple manager should have the following methods:
get(key)
set(key, value)
- value is always a string
GrapeDB provides the following simple managers:
InMemorySimpleManager
- saves objects only in JavaScript memory (RAM)LevelSimpleManager
- an adapter to LevelDB
Example usage:
const AdvancedManager InMemorySimpleManager = ; const logger = {} {}; const simpleManager = ;const manager = simpleManager logger;const key = 'foo-key';const value = foo1: bar: 'bar-value' baz: 'baz-value' foo: 'foo-value' foo2: bar: 'bar-value-2' baz: 'baz-value-2' foo: 'foo-value-2' bar: 'foo-value-2-bar-2' foo: 'foo-value-2-foo-2' ; manager ;
Usage with LevelDB:
const AdvancedManager LevelSimpleManager = ;const LevelPromise = ;const levelup = ; const logger = {} {};const db = ;const manager = db logger;
run locally tests
git clone https://github.com/oprogramador/grapedb.git
cd grapedb
npm i
env APP_DIR=src npm run postinstall
npm t