How to use the pouchdb.plugin 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 redgeoff / delta-pouch / test / index.js View on Github external
/*jshint expr:true */
'use strict';

var Pouch = require('pouchdb');

// Use mem adapter as level down adapter has problems running on virtualbox:
// https://github.com/Level/levelup/issues/222
Pouch.plugin(require('pouchdb-adapter-memory'));

var deltaPlugin = require('../');
Pouch.plugin(deltaPlugin);

var chai = require('chai');
chai.use(require("chai-as-promised"));

chai.should(); // var should = chai.should();
var Promise = require('bluebird');

var dbs;
if (process.browser) {
  dbs = 'testdb' + Math.random() +
    ',http://localhost:5984/testdb' + Math.round(Math.random() * 100000);
} else {
  dbs = process.env.TEST_DB ? process.env.TEST_DB : 'testdb';
github garbados / linkfriend / src / js / lib / db.js View on Github external
doc.tags.forEach(emit)
        }
      }.toString(),
      reduce: '_count'
    },
    dateSort: {
      map: function (doc) {
        if (/^bookmark/.test(doc._id) && doc.createdAt) {
          emit(doc.createdAt)
        }
      }.toString()
    }
  }
}

PouchDB.plugin({
  setup: async function () {
    // add mango indexes
    await this.createIndex({
      index: {
        // TODO partial filter selector, once implemented: https://github.com/pouchdb/pouchdb/issues/7467
        fields: ['_id', 'tags']
      },
      ddoc: 'tag-search'
    })
    // add design documents
    try {
      await this.put(designTags)
    } catch (error) {
      // update ddoc if it differs from the one found.
      if (error.name === 'conflict') {
        const ddoc = await this.get(designTags._id)
github getbitpocket / bitpocket-mobile-app / src / app / app.module.ts View on Github external
import { NgModule, ErrorHandler  } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { IonicStorageModule, Storage } from '@ionic/storage';
import { IonicApp, IonicModule, IonicErrorHandler, ModalController } from 'ionic-angular';

// Pouch DB
import PouchDB from 'pouchdb';
import pouchdbUpsert from 'pouchdb-upsert';
import pouchFind from 'pouchdb-find';
PouchDB.plugin(pouchdbUpsert);
PouchDB.plugin(pouchFind);
// PouchDB.debug.enable('pouchdb:find');
window['PouchDB'] = PouchDB;

// Main Component
import { BitPocketApp } from './app.component';

// Providers
import {
  Config,
  Repository,
  QRScanner,
  CurrencyService,
  AccountService,
  TransactionServiceWrapper,
  CryptocurrencyService,
github moneybutton / yours-core / lib / contentstore.js View on Github external
var util = require('util')
var events = require('events')
var Content = require('./content')
var q = require('q')
var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-find'))
// PouchDB.debug.enable('*')
var bitcore = require('bitcore')
var DattUtil = require('./util')
var logger = require('./logger')

/**
 * The content store is for storing "content", i.e. the content that can be
 * stored and retrieved on the network. TODO: This somehow needs to be
 * refactored to support not just 'content', but also 'actions', i.e. upvoting
 * someone or flagging a piece of content. Actions may also be called
 * 'content', that is yet-to-be-decided, but either way, content and actions
 * need to have some kind of unified interface to the database.
 */
function ContentStore (options) {
  this.db = undefined
github chunksnbits / store.pouchdb / lib / store-loader.js View on Github external
/* jshint node:true */

'use strict';

var _ = require('lodash');
var isNode = require('detect-node');

var PouchDb = require('pouchdb');
var PouchDbStore = require('./store');

PouchDb.plugin(PouchDbStore);

function PouchDbStoreLoader () {}

PouchDbStoreLoader.prototype.load = function (dbName, options) {

  options = _.extend({}, options);

  var stores = {};

  if (!stores[dbName]) {
    var pouch = new PouchDb(dbName, options);
    var store = PouchDbStore.load(pouch, options);

    stores[dbName] = store;
  }
github jo / pouch-box / test / index.js View on Github external
var test = require('tape')
var PouchDB = require('pouchdb')
var memdown = require('memdown')
var nacl = require('tweetnacl')

PouchDB.plugin(require('../'))

var keyPair = nacl.box.keyPair()
var permitId = 'permit/' + nacl.util.encodeBase64(keyPair.publicKey)
var dbname = 'test'

test('basics', function(t) {
  var db = new PouchDB(dbname, { db: memdown })
  var receiver

  db.box(keyPair)
    .then(function(permit) {
      receiver = permit.receiver()
      
      t.ok(permit.databaseKey.publicKey, 'returns database public key')
      t.ok(permit.databaseKey.secretKey, 'returns database secret key')
    })
github jhonnyrogerb / angular-podcast-app / src / app / core / services / pouchdb-audio.service.ts View on Github external
import { Injectable } from '@angular/core';
import PouchDB from 'pouchdb';
import PouchDBFind from 'pouchdb-find';
import PouchDBFindAdapterWebSQl from 'pouchdb-adapter-websql';

PouchDB.plugin(PouchDBFind, PouchDBFindAdapterWebSQl);

@Injectable()
export class PouchdbAudioService {
  db: any;


  constructor() {
    if (!this.db) this.db = new PouchDB('angular-podcast-audio', {adapter: 'websql'});
    this.createIndexes();
  }


  private async createIndexes() {
    try {
      await this.db.createIndex({ index: { fields: ['lastPlay'] } });
    } catch (err) {
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 AugurProject / augur / packages / augur-sdk / src / state / db / AbstractDB.ts View on Github external
import fs from 'fs';
import Find from 'pouchdb-find';
import Memory from 'pouchdb-adapter-memory';
import PouchDB from 'pouchdb';
import Upsert from 'pouchdb-upsert';
import pouchdbDebug from 'pouchdb-debug';

import * as _ from 'lodash';
import DatabaseConfiguration = PouchDB.Configuration.DatabaseConfiguration;
import PouchDb from 'pouchdb-browser';

PouchDB.plugin(Find);
PouchDB.plugin(Memory);
PouchDB.plugin(Upsert);
PouchDB.plugin(pouchdbDebug);

interface DocumentIDToDoc {
  [docId: string]: PouchDB.Core.ExistingDocument<{}>;
}

export interface BaseDocument {
  _id: string;
  _rev?: string;
}

export abstract class AbstractDB {
  db: PouchDB.Database;
  protected networkId: number;
  readonly dbName: string;
  public numIndexes: number = 0;
github ashteya / ionic2-tutorial-pouchdb / src / services / birthday.service.ts View on Github external
initDB() {
        PouchDB.plugin(cordovaSqlitePlugin);
        this._db = new PouchDB('birthdays.db', { adapter: 'cordova-sqlite' });
    }