How to use the pouchdb.adapter 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 Tangerine-Community / Tangerine / client / src / app / core / sync-records / peers / peers.component.ts View on Github external
async transferData() {
    if (this.window.isCordovaApp) {
      PouchDB.plugin(window['PouchReplicationStream'].plugin);
      PouchDB.adapter('writableStream', window['PouchReplicationStream'].adapters.writableStream);
      let dumpedString = '';
      const stream = new window['Memorystream']();
      stream.on('data', function(chunk) {
        dumpedString += chunk.toString();
      });
      const username = this.userService.getCurrentUser();
      const source = new PouchDB(username);
      source.dump(stream).then(function () {
        // console.log('Yay, I have a dumpedString: ' + dumpedString);
        window['TangyP2PPlugin'].transferData(dumpedString, function(message) {
          const objectConstructor = ({}).constructor;
          if (message.constructor === objectConstructor) {
            const messageStr = message.message;
            document.querySelector('#p2p-results').innerHTML += messageStr + '<br>';
          } else {
            console.log('Message: ' + message);
github Tangerine-Community / Tangerine / client / src / app / core / sync-records / peers / peers.component.ts View on Github external
window['TangyP2PPlugin'].listenForTransfer(null, (message) =&gt; {
        const objectConstructor = ({}).constructor;
        // test if it's an object:
        if (message.constructor === objectConstructor) {
          const messageStr = message.message;
          // TODO: JSONObject is available if we need it.
          // const object = message.object;
          if (message.messageType === 'payload') {
            PouchDB.plugin(window['PouchReplicationStream'].plugin);
            PouchDB.adapter('writableStream', window['PouchReplicationStream'].adapters.writableStream);
            const writeStream =  new window['Memorystream'];
            writeStream.end(messageStr);
            const username = this.userService.getCurrentUser();
            const dest = new PouchDB(username);
            const pluginMessage = 'I loaded data from the peer device.';
            dest.load(writeStream).then(function () {
              document.querySelector('#p2p-results').innerHTML += pluginMessage + '<br>';
            }).catch(function (err) {
              message = 'oh no an error: ' + err;
              console.log(message);
              document.querySelector('#p2p-results').innerHTML += message + '<br>';
            });
          } else {
            console.log('Message: ' + messageStr);
            document.querySelector('#p2p-results').innerHTML += messageStr + '<br>';
          }
github scottmtp / pouch-replicate-webrtc / index.js View on Github external
var PouchReplicator = function(name, pouchDb, replicationOptions) {
  ReplicatorCommon.call(this, name);

  // PouchReplicator
  this.pouchDb = pouchDb;
  this.replicationOptions = replicationOptions;
  this.marker = '__end__';
  this.replData = [];

  PouchDB.plugin(replicationStream.plugin);
  PouchDB.adapter('writableStream', replicationStream.adapters.writableStream);
};
github HospitalRun / hospitalrun-frontend / tests / helpers / run-with-pouch-dump.js View on Github external
return navigator.serviceWorker.ready.then(() => {
          if (navigator.serviceWorker.controller && navigator.serviceWorker.controller.postMessage) {
            PouchDB.adapter('worker', PouchDBWorker);
            db = new PouchDB('hospitalrun-test-database', {
              adapter: 'worker',
              worker: () => navigator.serviceWorker
            });
            return  db.load(dump).then(() => {
              return db;
            });
          } else {
            return promise.then(() => db);
          }
        });
      } else {
github yldio / pouch-websocket-sync-example / net / client.js View on Github external
var program = require('commander');
program.
  version(require('../package').version).
  option('-s, --sync ', 'Sync with server').
  option('-r, --randomwrites', 'Produce random writes on local database').
  parse(process.argv);

var localDB = new PouchDB({
  name: 'localdb',
  db: require('memdown'),
});

console.log('program:', program.sync);

if (program.sync) {
  PouchDB.adapter('remote', Remote.adapter);
  var remote = Remote();
  var remoteDB = new PouchDB({
    name: 'remotedb',
    adapter: 'remote',
    remote: remote,
  });

  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);
github nolanlawson / pokedex.org / bin / build-monsters-supplemental-database.js View on Github external
#!/usr/bin/env node

require('regenerator/runtime');

var PouchDB = require('pouchdb');
var repStream = require('pouchdb-replication-stream');
var transformPouch = require('transform-pouch');
var load = require('pouchdb-load');
PouchDB.plugin(repStream.plugin);
PouchDB.adapter('writableStream', repStream.adapters.writableStream);
PouchDB.plugin(transformPouch);
PouchDB.plugin({loadIt: load.load});
var memdown = require('memdown');
var bluebird = require('bluebird');
var fs = bluebird.promisifyAll(require('fs'));
var zpad = require('zpad');

var species = require('../src/js/shared/data/species');
var jpnNames = require('../src/js/shared/data/japaneseNames');
var hepburnNames = require('../src/js/shared/data/hepburnNames');
var eggGroups = require('../src/js/shared/data/eggGroups');
var supplemental = require('../src/js/shared/data/supplemental');
var shortRevs = require('short-revs');

var target = new PouchDB('inmem2', {db: memdown});
github nolanlawson / pokedex.org / bin / build-monsters-database.js View on Github external
#!/usr/bin/env node

require('regenerator/runtime');

var fetch = require('node-fetch');
var PouchDB = require('pouchdb');
var repStream = require('pouchdb-replication-stream');
PouchDB.plugin(repStream.plugin);
PouchDB.adapter('writableStream', repStream.adapters.writableStream);
var memdown = require('memdown');
var db = new PouchDB('inmem', {db: memdown});
var fs = require('fs');
var zpad = require('zpad');
var shortRevs = require('short-revs');

var NUM_MONSTERS = 649;

async function doIt() {
  for (var i = 1; i &lt;= NUM_MONSTERS; i++) {
    var result = await fetch(`http://pokeapi.co/api/v1/pokemon/${i}`);
    var json = await result.json();
    json._id = zpad(json.national_id, 5);
    await db.put(json);
  }
github yldio / pouch-websocket-sync-example / web / store / configureStore.js View on Github external
import * as types from '../constants/ActionTypes'
import PouchMiddleware from '../middlewares/pouch'
import { createStore, applyMiddleware } from 'redux'
import rootReducer from '../reducers'
import PouchDB from 'pouchdb'
import PouchRemoteStream from 'pouch-remote-stream'
import WebsocketStream from 'websocket-stream'
import Reconnect from 'reconnect-core'
import PipeChannels from 'pipe-channels'

PouchDB.adapter('remote', PouchRemoteStream.adapter);

export default function configureStore() {
  var db = new PouchDB('todos');

  var reconnect = Reconnect(function(address) {
    return WebsocketStream(address);
  });

  var re = reconnect(function(ws) {

    var client = PipeChannels.createClient();
    ws.pipe(client).pipe(ws);

    client.channel('todos-server', function(err, channel) {
      if (err) throw err;
github nolanlawson / pokedex.org / bin / build-moves-database.js View on Github external
#!/usr/bin/env node

require('regenerator/runtime');

var PouchDB = require('pouchdb');
var repStream = require('pouchdb-replication-stream');
var load = require('pouchdb-load');
PouchDB.plugin(repStream.plugin);
PouchDB.adapter('writableStream', repStream.adapters.writableStream);
PouchDB.plugin({loadIt: load.load});
var memdown = require('memdown');
var bluebird = require('bluebird');
var fs = bluebird.promisifyAll(require('fs'));
var zpad = require('zpad');
var fetch = require('node-fetch');
var pick = require('lodash').pick;
var fetch = require('node-fetch');
var shortRevs = require('short-revs');

var csvUrl = 'https://raw.githubusercontent.com/phalt/pokeapi/0d666b130363b26621c339e5f8415a02dcd4806b/data/v2/csv/moves.csv';

var db = new PouchDB('inmem2', {db: memdown});

var typeIdsToNames = {
  '7': 'Bug',
github nolanlawson / pokedex.org / bin / build-monsters-skim-database.js View on Github external
#!/usr/bin/env node

require('regenerator/runtime');

var PouchDB = require('pouchdb');
var repStream = require('pouchdb-replication-stream');
var transformPouch = require('transform-pouch');
var load = require('pouchdb-load');
PouchDB.plugin(repStream.plugin);
PouchDB.adapter('writableStream', repStream.adapters.writableStream);
PouchDB.plugin(transformPouch);
PouchDB.plugin({loadIt: load.load});
var memdown = require('memdown');
var bluebird = require('bluebird');
var fs = bluebird.promisifyAll(require('fs'));
var pick = require('lodash').pick;
var shortRevs = require('short-revs');

var source = new PouchDB('inmem', {db: memdown});
var target = new PouchDB('inmem2', {db: memdown});

target.transform({
  incoming: doc => {
    doc = pick(doc, '_id', '_rev', '_revisions', 'descriptions',
      'types', 'attack', 'defense', 'speed', 'sp_atk', 'sp_def', 'hp',
      'weight', 'height', 'national_id', 'name', 'male_female_ratio',