Skip to content
This repository has been archived by the owner on Feb 14, 2020. It is now read-only.

oprogramador/vinberodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vinberodb

MIT License Build Status

NPM status

VinberoDB is a distributed object database. It can be also considered as an ODM.

install

npm install --save vinberodb

usage

The main class is AdvancedManager which has the following public methods:

  • get(key) - gets a stringified node
  • set(key, value) - sets a stringified node
  • getComplex(key, maxLevel) - gets recursively an object with nested fields, maxLevel specifies the maximum depth; when maxLevel is undefined, the full object is returned
  • setComplex(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

VinberoDB provides the following simple managers:

  • InMemorySimpleManager - saves objects only in JavaScript memory (RAM)
  • LevelSimpleManager - an adapter to LevelDB

Example usage:

const { AdvancedManager, InMemorySimpleManager } = require('vinberodb');

const logger = {
  error: () => {},
  info: () => {},
};

const simpleManager = new InMemorySimpleManager();
const manager = new AdvancedManager(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.setComplex(key, value)
  .then(() => expect(manager.getComplex(key)).to.eventually.deep.equal(value));

Usage with LevelDB:

const { AdvancedManager, LevelSimpleManager } = require('vinberodb');
const LevelPromise = require('level-promise');
const levelup = require('levelup');

const logger = {
  error: () => {},
  info: () => {},
};
const db = LevelPromise(levelup('my-database'));
const manager = new AdvancedManager(new LevelSimpleManager(db), logger);

run locally tests

git clone https://github.com/oprogramador/vinberodb.git
npm i
env APP_DIR=src npm run postinstall
npm t

About

Distributed object database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published