OrbitDB
Distributed, peer-to-peer database on IPFS.
Introduction
orbit-db
is a distributed, peer-to-peer database for applications. You can use orbit-db
for different data models: Key-Value Store, Eventlog (append-only log), Feed (add and remove log) and Counters. The database gets replicated automatically with peers who are connected to the same database.
This is the Javascript implementation and it works both in Node.js and Browsers.
- Client-side database to be embedded in Javascript applications
- Stores all data in IPFS
- Aggregation happens on client side and data is eventually consistent
- Designed to work offline first
Node.js
Browser
Data stores
Currently available data stores:
Install
From npm:
npm install orbit-db
From git:
git clone https://github.com/haadcode/orbit-db.git
cd orbit-db
npm install
Usage
'use strict'
const IpfsApi = require('ipfs-api')
const OrbitDB = require('orbit-db')
const ipfs = IpfsApi('localhost', '5001')
const orbitdb = new OrbitDB(ipfs)
const db = orbitdb.eventlog("feed name")
db.add("hello world")
.then(() => {
const latest = db.iterator({ limit: 5 }).collect()
console.log(latest.join("\n"))
})
Examples
Browser example
npm install
npm run build:examples
npm run examples:browser
Node.js example
npm install
npm run examples:node
See detailed example and run it with:
node examples/eventlog.js
'use strict'
const IpfsDaemon = require('ipfs-daemon')
const OrbitDB = require('orbit-db')
IpfsDaemon()
.then((res) => {
const orbitdb = new OrbitDB(res.ipfs)
const db = orbitdb.eventlog("|orbit-db|examples|eventlog-example")
const creatures = ['🐙', '🐷', '🐬', '🐞', '🐈', '🙉', '🐸', '🐓']
const query = () => {
const index = Math.floor(Math.random() * creatures.length)
db.add(creatures[index])
.then(() => {
const latest = db.iterator({ limit: 5 }).collect()
let output = ``
output += `---------------------------------------------------\n`
output += `Latest Visitors\n`
output += `---------------------------------------------------\n`
output += latest.reverse().map((e) => e.payload.value).join('\n') + `\n`
console.log(output)
})
.catch((e) => {
console.error(e.stack)
})
}
setInterval(query, 1000)
})
.catch((err) => console.error(err))
API
TODO
- orbit-db-kvstore
- put(key, value)
- set(key, value)
- get(key)
- orbit-db-eventstore
- add(value)
- get(hash)
- iterator(options)
- orbit-db-feedstore
- add(value)
- del(hash)
- get(hash)
- iterator(options)
- orbit-db-counterstore
- inc([value])
Development
Run Tests
npm test
Build distributables
npm run build
Background
TODO
Check out a visualization of the data flow at https://github.com/haadcode/proto2
Live demo: http://celebdil.benet.ai:8080/ipfs/Qmezm7g8mBpWyuPk6D84CNcfLKJwU6mpXuEN5GJZNkX3XK/
TODO: list of modules used, orbit-db-pubsub, etc.
Contributing
TODO
License
MIT ©️ 2016, Haadcode