How to use the pouchdb.replicate function in pouchdb

To help you get started, we’ve selected a few pouchdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github automerge / trellis / src / lib / pouch_adapter.js View on Github external
this.db.put({ _id: this.docId }).then((result) => {
          this.doc._rev = result.rev

          if(this.onLoad) this.onLoad(null)
        })
      } else {
        console.log(error)
      }
    })

    // Set up replication subscriptions
    let options = { live: true }
    PouchDB.replicate(this.db, this.remote, options)
      .on("error", console.log)

    PouchDB.replicate(this.remote, this.db, options)
      .on("change", (info) => {
        console.log("Remote change")

        this.db.get(this.doc._id).then((doc) => {
          this.doc = doc

          if(this.onChange) this.onChange(doc.state)
        })
      })
      .on("error", console.log)
  }
github couchbaselabs / mini-hacks / gcm-web-push-notifications / src / app.js View on Github external
var PouchDB = require('pouchdb');

// Expose PouchDB on the window object to use the
// PouchDB Chrome debugger extension http://bit.ly/1L6dArH
window.PouchDB = PouchDB;


var db = new PouchDB('timely-news');
PouchDB.plugin(require('pouchdb-find'));

PouchDB.replicate('timely-news', 'http://localhost:4984/db', {
  live: true
});

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('./service-worker.js', {scope: './'});
  navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
    serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly: true})
      .then(function (pushSubscription) {
        console.log('The reg ID is :: ', pushSubscription.subscriptionId);

        db.createIndex({index: {fields: ['type']}})
          .then(function() {
            db.find({
              selector: {type: 'profile'}
            }).then(function (res) {
              console.log(res);
github automerge / trellis / src / lib / pouch_adapter.js View on Github external
if(this.onLoad) this.onLoad(this.doc.state)
    }).catch((error) => {
      if(error.status === 404) {
        this.db.put({ _id: this.docId }).then((result) => {
          this.doc._rev = result.rev

          if(this.onLoad) this.onLoad(null)
        })
      } else {
        console.log(error)
      }
    })

    // Set up replication subscriptions
    let options = { live: true }
    PouchDB.replicate(this.db, this.remote, options)
      .on("error", console.log)

    PouchDB.replicate(this.remote, this.db, options)
      .on("change", (info) => {
        console.log("Remote change")

        this.db.get(this.doc._id).then((doc) => {
          this.doc = doc

          if(this.onChange) this.onChange(doc.state)
        })
      })
      .on("error", console.log)
  }
github lil5 / simple-cryptor-pouch / test / index.spec.js View on Github external
return new Promise((resolve, reject) => {
            PouchDB
              .replicate(originalDB, changedDB,
                {live: false, retry: false})
              .on('complete', info => resolve({output: info, message: 'complete'}))
              .on('error', err => reject(Error({output: err, message: 'error'})))
              .on('denied', err => reject(Error({output: err, message: 'denied'})))
          })
            .then(response => {
github hivewallet / hive-ios / app / lib / db / index.js View on Github external
function firstTimePull() {
  PouchDB.replicate(remote, db, {
    complete: function(){
      db.get(id, function(err){
        if(err) {
          if(err.status === 404) return initializeRecord();
          return console.error(err)
        }

        emitter.emit('db-ready')
      })
    }
  })
}
github hivewallet / hive-ios / app / lib / db / index.js View on Github external
function setupPulling(){
  PouchDB.replicate(remote, db, {
    live: true,
    onChange: function() {
      emitter.emit('db-ready')
    }
  })
}
github hivewallet / hive-ios / app / lib / db / index.js View on Github external
db.get(id, function(err, doc){
    var data = JSON.parse(decrypt(doc.data, sercret))
    processData(data)

    doc.data = encrypt(JSON.stringify(data), sercret)
    db.put(doc, callback)

    PouchDB.replicate(db, remote, function(err){
      if(err) console.error("failed to replicate changes to server", err)
    })
  })
}