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

tankdb

v0.9.5

Published

Distributed graph database

Downloads

87

Readme

Tank DB

Distributed graph database

NPM


Why? #

All graph (or graph-like) databases I tested are not yet production-ready. This library was written as a common subset of these tested libraries, allowing me to upgrade into one of those once they are deemed stable.

Setup #

After install TANK with NPM (npm install --save tankdb), add the following to your server code to load the library:

const Tank = require('tankdb');

Once you've loaded the libraries, you'll have to decide how you want the storage to be handled. By default, no adapters for storage and networking are loaded. You'll have to load these as described in the adapters section.

To initialize your TANK, the following code should be used:

let db = Tank(opts);

Tank doesn't care whether you use Tank or new Tank. It simply handles both cases. Options to pass are described later in this readme.

API #

Constructor #

Used to create a new TANK database instance

let db = Tank(opts);

tank.get #

Follows a path, directing where to act. This function DOES NOT actually fetch data, it only follows a path.

db.get( key );

tank.put #

Save data into TANK, syncing it with your connected peers.

db.get( key ).put({ hello: 'world' });

You do not need to re-save the entire object every time, TANK will automatically merge your data into what already exists as a "partial" update.

TODO: describe supported data types

tank.on #

Subscribe to updates and changes on a node or property in realtime.

db.get( key ).on( callback );

A request is made to the network for the current path, after which responses will trigger the callback. Updates to the data will also trigger the callback, allowing you to act whenever the data is updated.

tank.once #

Get the current data without subscribing to updates, responds with undefined if the data can not be found.

db.get( key ).once( callback );

Just like .on, it sends out a request for the current path. The callback will only be fired once on received data.

tank.map #

.map iterates over each property and item on a node, passing it down the chain, behaving like Array.map on your data. It also subscribes to every item as well and listens for newly inserted items. It accepts a callback to transform the data before pasing it on to the next listener.

let users = db.get('users');
users.map( callback );

Summary of behaviors:

  • users.map().on(cb) subscribes to changes on every user and to users as they are added.
  • users.map().once(cb) gets each user once, including ones that are added over time.
  • users.once().map().on(cb) gets the user list once, but subscribes to changes on each of those users (not added ones).
  • users.once().map().once() gets the user list once, gets each of those users only once (not added ones).

Adapters #

LevelDB #

LevelDB is the recommended storage layer for TANK. To enable LevelDB support, add the following line after loading the tank library but BEFORE instantiating the database.

require('tankdb/lib/adapter/level');

This adapter is not restricted to leveldb though. Any storage engine with compatible get and put methods should be supported. To pass a leveldb instance to your Tank instance, pass the initialized instance into opts.level.

WebSocket #

Using WebSockets is the only method of networking supported so far. To make TANK start using them, add the following line after loading the library but BEFORE instantiating the database.

require('tankdb/lib/adapter/websocket');

Custom websocket libraries are supported (well, libraries honering it's API). To use a custom library, pass it into opts.WebSocket. Peers to connect to can be passed into opt.peers, allowing you to set up a server..

Supporting TankDB #

Supporting this project can be done in multiple ways, as listed below.