pouchdb-hoodie-unsynced-local-docs

1.0.0 • Public • Published

pouchdb-hoodie-unsynced-local-docs

Build Status Coverage Status Dependency Status devDependency Status

NPM

This PouchDB plugin provides simple methods to check if local DB has unsynced changes.

Usage

// Initialisation
 
var db = new PouchDB('dbname')
var api = db.unsyncedLocalDocs({remote: 'http://example.com/mydb'})
 
api.unsyncedLocalDocs()
.then(function(changes) {
  // changes is array of docs?
})
 
api.unsyncedLocalDocs('docid') // pass doc id
api.unsyncedLocalDocs({_id: 'docid'}) // pass doc with _id property
api.unsyncedLocalDocs(['docid', {_id: 'docid'}]) // array of IDs and objects

Approach

  1. we know localDb, but not the state of remoteDB when we are offline
  2. update_seq(for localDb/remoteDb) + get _local/ ids for both, 1-time replication & continuous replication*
  3. localDb/_changes?since=
  4. if it returns anything: there are changes

hint:

  • https://github.com/pouchdb/pouchdb/blob/master/lib/replicate/genReplicationId.js

Installation

With browserify or on node.js/io.js

Attach this plugin to the PouchDB object:

npm install --save pouchdb
npm install --save pouchdb-hoodie-unsynced-local-docs

Install via npm

var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-hoodie-unsynced-local-docs'))

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.

Package Sidebar

Install

npm i pouchdb-hoodie-unsynced-local-docs

Weekly Downloads

0

Version

1.0.0

License

Apache-2.0

Last publish

Collaborators

  • gr2m
  • zoepage