Hoodie-like sync API for PouchDB
This PouchDB plugin provides simple methods to keep two databases in sync.
// Initialisation
var db = new PouchDB('dbname')
var api = db.hoodieSync({
// local dbname or remote URL
remote: 'http://example.com/mydb',
// pass own EventEmitter instance if you want,
// otherwise creates its own
emitter: emitter,
// optional ajax options for sync with remote db
// can also be a function. In that case the Function
// gets executed and result passed to all replications
ajax: {
headers: {
authorization: 'Bearer token123'
}
}
})
// starts / stops continuous replication
api.connect()
api.disconnect()
api.isConnected()
// resolve with pulled docs[]
api.pull()
api.pull([doc1, id2])
// resolve with pushed docs[]
api.push()
api.push([doc1, id2])
// resolve with synced docs[]
api.sync()
api.sync([doc1, id2])
// change remoteName
api.changeRemote(newRemote)
api.changeRemote({
remote: 'http://example.com/mydb'
ajax: ajaxOptions
})
// events
api.on('pull', function(doc) {})
api.on('push', function(doc) {})
api.on('connect', function() {})
api.on('disconnect', function() {})
<script src="pouchdb.js"></script>
<script src="pouchdb-hoodie-sync.js"></script>
var PouchDB = require('pouchdb')
PouchDB.plugin( require('pouchdb-hoodie-sync') )
Run all tests and validates JavaScript Code Style using standard
npm test
To run only the tests
npm run test:node
Run tests from single file
node test/unit/connect-test.js
Have a look at the Hoodie project's contribution guidelines. If you want to hang out you can join #hoodie-pouch on our Hoodie Community Slack.