Giter VIP home page Giter VIP logo

objdb's Introduction

Object DB

build status coverage status

A simple Object database with emitter.

Installation

npm i smujmaiku/objdb

Methods

const db = new ObjDb();

db.set('a.b', 1);
db.get('a');
// { b: 1 }

db.on('c', console.log);
db.set('c.d', 2);
// { d: 2 }

constructor([conf], [db], [debug])

conf is an Object of configurations:

  • debounce: Time in ms to debounce emits.
  • upkeep: Time in ms to run cleaning functions.
  • expire: Default time in ms to expire set data.
  • permanent: Default set data to not expire.

db parameter is sent directly to the set(db) method. debug allows providing a function to send some debugging information to.

on(name, cb)

Creates a listener on the name provided.

once(name, cb)

Creates a one time listener on the name provided. This will fire immediately if data already exists at that name.

off(name, [cb])

Releases a listener matching the name. Should a cb be provided that will be matched as well. Providing true as the name will release all listeners.

get(name)

Returns data at the name.

set(name, data, [meta])

Sets data at the name. This will debounce firing emitters related to this name. meta Object data will be stored separate of the data and can contain the following:

  • e: Time to expire against Date.now()
  • p: Flag as permanent and to not expire.

set(obj)

data and meta Objects can be combined into a single Object obj and provided as a single argument.

set({
	'a': 1,
	'a$meta': { p: true },
	'b.c': 2,
});
// Is equivalent to:
set('a', 1, { p: true });
set('b.c', 2);

del(names)

Deletes names data. Can be provided an Array of names. This will debounce firing emitters related to these names.

restore(stream)

Restores a database from a file stream. Providing a path as the stream will create the file stream for that path.

backup(stream)

Creates a database backup to a file stream. Providing a path as the stream will create the file stream for that path.

License

Copyright (c) 2017-2019, Michael Szmadzinski. (MIT License)

objdb's People

Contributors

smujmaiku avatar

Stargazers

Dan P. avatar

Watchers

 avatar

objdb's Issues

v0.2.0

  • Refactor directories
  • Webkit for browsers
  • Move server bits downstream
  • Add deep event

Unexpected events when using set

Something seems amiss when deleting a nested value with set. I think this might be affecting downstream packages receiving events and through the socketio class.

> const Obj = require('objdb');
> const db = new Obj();
> db.on('a.b', (...args) => console.log('a.b', ...args));
> db.set({'a.b.c.d': 1});
a.b { c: { d: 1 } }

> db.set({'a.b.c.d': null});
a.b undefined
a.b undefined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.