How to use the pouchdb.sync 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 BeagleLab / beagle / js / main.js View on Github external
var domready = require('domready')
var style = require('beagle-style')
var React = require('react')
var App = React.createFactory(require('./app.jsx'))
var linkHandler = require('./linkhandler.js')
var sampleData = require('../lib/sampleData.js')
var url = require('./lib/url-checks')
var PDFJS = require('beagle-pdf')
var sidebarOpen = false
var sidebarId = 'beagle-sidebar'

// var level = require('level-browserify')
var PouchDB = require('pouchdb')
var db = new PouchDB('test')

PouchDB.sync('test', 'http://54.164.111.240:5984/test')

// DEV: This is how you clear the database
// db.destroy().then(function () {
//   console.log('Done')
// }).catch(function (err) {
//   console.log('err', err)
// })

// console.log('Main.js is being called from inside bundle.min.js')

function getModules (requestModules, cb) {
  // Get the current list of used modules
  chrome.storage.sync.get('modules', function (result) {
    var options = {}

    // If the extension has specified new modules to load
github jonniespratley / angular-cms / routes / cms-router.js View on Github external
router.use(function(req, res, next) {
		console.log('cms-router Time:', Date.now());
		next();
	});

	//Fix for cloud foundry
	if (process.env.VCAP_APP_PORT) {
		config.port = process.env.VCAP_APP_PORT;
	}

	// TODO: Using pouchdb
	var PouchDB = require('pouchdb');
	PouchDB.debug('*');
	var db = new PouchDB(config.db.local);
	var db2 = new PouchDB(config.db.remote);
	PouchDB.sync(db, db2);
	app.locals.db = db;

	console.log('Connected to', config.db.local);

// TODO:

/*
router.route('/users/:user_id')
.all(function(req, res, next) {
  // runs for all HTTP verbs first
  // think of it as route specific middleware!
  next();
})
.get(function(req, res, next) {
  res.json(req.user);
})
github yldio / pouch-websocket-sync-example / net / client.js View on Github external
});

  var host = program.sync.split(':');
  var conn = net.connect(Number(host[1]), host[0]);
  conn.setEncoding('utf8');
  var json = JSONStream();
  conn.
    pipe(json.in).
    pipe(remote.stream).
    pipe(json.out).
    pipe(conn);


  conn.on('data', console.log);

  var sync = PouchDB.sync(localDB, remoteDB, {live: true});
  sync.on('change', function(ch) {
    console.log('change: %j', ch);
  });
}

if (program.randomwrites) {
  var keys = ['a', 'b', 'c', 'd'];
  console.log('producing random writes');
  setInterval(function() {
    var key = _.sample(keys);
    localDB.get(key, function(err, doc) {
      if (! doc) {
        doc = {_id: key};
      }
      doc.value = Date.now();
      localDB.put(doc, function(err) {
github BeagleLab / beagle / js / views / highlight.jsx View on Github external
.then(function (response) {
      console.log('Stored ' + response.id + ' away...', response)

      PouchDB.sync('test', 'http://54.164.111.240:5984/test')
    })
    .catch(function (err) {
github BeagleLab / beagle / js / views / highlight.jsx View on Github external
db.put(value, function (err, response) {
          if (err) { console.log('Failed to save selection', err) }
          console.log('Stored ' + response.id + ' away...', response)

          PouchDB.sync('test', 'http://54.164.111.240:5984/test')

        })
      })
github vibedrive / vibedrive / src / client / Services / db.js View on Github external
startSyncing () {
    var opts = { live: true }

    this.sync = PouchDB.sync(this.local, this.remote, opts)
  }
github chunksnbits / store.pouchdb / lib / adapter / pouch-sync.js View on Github external
PouchSync.sync = function (store, syncStore, options) {

  if (!syncStore) {
    return;
  }

  _.merge({
    live: true,
    retry: true
  }, options);

  if (!_.isString(syncStore) && syncStore.toString() === '[object Store]') {
    syncStore = syncStore._adapter.pouch;
  }

  return PouchDb.sync(store._adapter.pouch, syncStore, options);
};
github yldio / pouch-websocket-sync-example / web / store / configureStore.js View on Github external
client.channel('todos-server', function(err, channel) {
      if (err) throw err;

      const remote = PouchRemoteStream();
      const remoteDB = new PouchDB('todos-server', {
        adapter: 'remote',
        remote
      });

      const sync = PouchDB.sync(db, remoteDB, {live: true});
      channel.pipe(remote.stream).pipe(channel);

      channel.once('end', function() {
        sync.cancel()
      });
    });
github cobbweb / isomorphic-react-example / src / app / Todos / TodoModel.js View on Github external
constructor() {
    this.db = new PouchDB(config.database);
    this.cursor = Atom.getCursor(['data', 'todos']);

    if (config.replicateTo) {
      this.sync = PouchDB.sync(config.database, config.replicateTo, { live: true });
    }

    this.loaded = this.db.allDocs({ include_docs: true }).then((response) => {
      this.initializeData(response);

      if (this.sync) {
        this.sync.on('change', (info) => {
          if (info.direction === 'pull' && info.change.docs.length > 0) {
            this.updateData(info);
          }
        });
      }

      this.db.changes({ live: true, include_docs: true, since: 'now' }).on('change', this.updateData.bind(this));
    });
  }