pouchdb-hoodie-sync
Hoodie-like sync API for PouchDB
This PouchDB plugin provides simple methods to
keep two databases in sync.
Usage
var db = new PouchDB('dbname')
var api = db.hoodieSync({
remote: 'http://example.com/mydb',
emitter: emitter
})
api.connect()
api.disconnect()
api.isConnected()
api.pull()
api.pull([doc1, id2])
api.push()
api.push([doc1, id2])
api.sync()
api.sync([doc1, id2])
api.on('pull', function(doc) {})
api.on('push', function(doc) {})
api.on('connect', function() {})
api.on('disconnect', function() {})
If you need to customise the request to the server, e.g. set custom header for
authorisation, you can use PouchDB.defaults{ajax}
:
var MyPouch = PouchDB.defaults({
ajax: {
headers: {
authorization: 'Basic QWxhZGRpbjpPcGVuU2VzYW1l'
}
}
})
In the browser
<script src="pouchdb.js"></script>
<script src="pouchdb-hoodie-sync.js"></script>
In node.js
var PouchDB = require('pouchdb')
PouchDB.plugin( require('pouchdb-hoodie-sync') )
Testing
In Node.js
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
Contributing
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.
License
Apache 2.0