pouchdb-orbit
v1.0.2-alpha
Published
A plugin for PouchDB that adds replication over OrbitDB.
Downloads
5
Readme
PouchDB-Orbit
An OrbitDB plugin for PouchDB that adds some methods for P2P replication:
const PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-orbit'))
// ... once you have an orbit instance ...
const db = new PouchDB(dbName)
db.load(orbit).then(function () {
// DB now synced over IPFS
console.log('hooray!')
// share this address with friends
// and they can replicate the DB
// across P2P infrastructure
console.log(db.address)
})
You can also pre-load from a certain hash:
// ... using the hash from above ...
db.load(orbit, address).then(function () {
// DB is now synced with the given hash!
// Any properly formatted log entries
// will have been mapped to the DB.
})
Install
Install with npm:
npm i pouchdb-orbit
Then, in your code, register it with PouchDB as a plugin like this:
const PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-orbit'))
Usage
The plugin adds some methods and properties to each PouchDB instance:
.load(orbit, [address]) -> Promise
Creates an OrbitDB store and registers event listeners with it and the PouchDB changes feed in order to both stores synchronized with each other. Returns a promise that resolves once the the OrbitDB store is ready for querying.
.merge(address)
Retrieves entries from the given OrbitDB address and merges them locally, adding them to PouchDB. Returns a promise that resolves once all the documents have been processed.
.address
Getter for the OrbitDB address ({ root, path }
) for this database.
.key
Getter for the keypair for this OrbitDB instance.