Tank DB
Distributed graph database
#
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.
#
SetupAfter install TANK with NPM (npm install --save tankdb
), add the following to your server code to load the library:
const Tank = ;
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 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#
ConstructorUsed to create a new TANK database instance
let db = ;
#
tank.getFollows a path, directing where to act. This function DOES NOT actually fetch data, it only follows a path.
db;
#
tank.putSave data into TANK, syncing it with your connected peers.
db;
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.onSubscribe to updates and changes on a node or property in realtime.
db;
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.onceGet the current data without subscribing to updates, responds with undefined
if the data can not be found.
db;
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;users;
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#
LevelDBLevelDB 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.
;
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
.
#
WebSocketUsing 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.
;
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 TankDBSupporting this project can be done in multiple ways, as listed below.
- Open an issue about a bug you found or to request a new feature
- Open a merge request to fix a bug you found or to implement a new feature
- Contribute on patreon