npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

atom-db

v1.0.2

Published

A lightweight, hyper-flexible object database

Downloads

7

Readme

atom-db | a flexible object database for any environment

Coverage Status Build Status npm version License: MIT

Table of Contents

Introduction

Atom-db is a zero-dependency object / NOSQL data store. A database can have any number of stores, each of which emit onSuccess and onError events to the store instance. You can use the .get and .set methods to persist and retrieve data to and from the store, respectively.

Features

  • zero dependencies
  • fast object retrieval
  • create multiple, namespaced databases with little configuration
  • catch errors in an isolated per-store context via a single event hook

Installation and Usage

Install via NPM with npm i atom-db.

Instantiate your database by requiring the library's built-in init function:

const db = require("atom-db");

const storeA = db("test").registerObjectStore("mock");

Subscribe to the success and error handlers:

storeA.onError(e => {
	console.log(e.target.value.message);
});

storeA.onSuccess(e => {
	console.log(e.target.value);
});

Set some data in the store:

store.set("person", { musician: "Cornelius Cardew" });

Retrieve data:

const musician = store.get("person");

Documentation

Database instance

A database is initialized with a name argument. This can be a String, Number, or Symbol. Initialized database instances have attached to them a registerObjectStore method that can be used to create new stores. The database instance places the registered store modules in a stores array.

You can instantiate any number of separate database instances, each with their own localized stores.

Example:

const db = require("atom-db");
const database = db("mock");

Store Module Registration

A store module is a key-value store bound to the database instance. To register a new store module, call registerObjectStore.

| Method | Return Value | | --- | --- | | registerObjectStore | returns the newly created store module with a localized event-emitter attached |

Example:

const db = require("atom-db");
const store = db("mock").registerObjectStore("people");

Store Module Events

Each store module has a localized event-emitter bound to its scope. To subscribe to the event-emitter, register a function on the onSuccess and onError properties. The functions you register will be dispatched and called once per eventing cycle.

Note: onSuccess and onError return the store instance and are therefore chainable method properties.

Event listeners available on each store instance: | Method | Emitted Data | | --- | --- | | onError | an event object with properties target and value, where value is an Error instance | | onSuccess | an event object with properties target and value, where value is the retrieved data |

Example:

const db = require("atom-db");
const store = db("mock").registerObjectStore("people");

store.onError(e => {
	console.log(e.target.value.message);
});

store.onSuccess(e => {
	console.log(e.target.value);
});

Setting Data in a Store Module

You can set a variety of data in a given store module by using that store's set method. set expects a String or Number key and a corresponding value of any type.

You'll need to subscribe handlers to that store's onError and onSuccess properties prior to setting data.

| Method | Return Value | | --- | --- | | set | returns the store instance itself and is therefore chainable |

Example:

const db = require("atom-db");
const store = db("mock").registerObjectStore("people");

store.onError(e => {
	console.log(e.target.value.message);
});

store.onSuccess(e => {
	console.log(e.target.value);
});

store.set("person", { musician: "Cornelius Cardew" });

Retrieving Data from a Store

You can retrieve previously set data from a given store module by using that store's get method. get expects a key identifier and will trigger the given store's emitter to emit either the onSuccess event (the requested data exists in the store), or the onError event (the requested data either does not exist in the store, or the key argument is malformed).

You'll need to subscribe handlers to that store's onError and onSuccess properties prior to getting data. You'll also need to set data, of course.

| Method | Return Value | | --- | --- | | get | returns the requested value, or undefined if the provided key has not been set in the store |

Example:

const db = require("atom-db");
const store = db("mock").registerObjectStore("people");

store.onError(e => {
	console.log(e.target.value.message);
});

store.onSuccess(e => {
	console.log(e.target.value);
});

store.set("person", { musician: "Cornelius Cardew" });

const p = store.get("person");

Event Properties

onSuccess
{ 
parent: <name prop of store to which data belongs>,
target: {
    value: <retrieved data>
    }
}
onError
{ 
parent: <name prop of store from which the error derives>,
target: {
    value: <an extended instance of Error>
    }
}

Upcoming Features

  • configurable adapters for local storage, node file system, and JSON
  • multiple event registration
  • built-in compose and pipe transformers