How to use the pouchdb.defaults 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 / update / update / updates.ts View on Github external
import { UserService } from "src/app/shared/_services/user.service";
import PouchDB from 'pouchdb'
PouchDB.defaults({auto_compaction: true, revs_limit: 1})

export const updates = [
  {
    requiresViewsUpdate: true,
    script: (userDb) => {
      return new Promise(resolve => {
        console.log(`This update will never run :-).`);
        resolve();
      })
    }
  },
  // Transform array style input.value from ['foo', 'bar'] to [{name: 'foo', value: 'on'}, {name: 'bar', value: 'on'}]
  {
    requiresViewsUpdate: false,
    script: (userDb) => {
      return new Promise(async resolve => {
github Tangerine-Community / Tangerine / scripts / generate-csv / generate-lines.js View on Github external
async function go(params) {
  const DB = PouchDB.defaults(params.dbDefaults)
  const db = new DB(params.dbName)
  const docs = await getData(db, params.formId, params.skip, params.limit)
  if (docs.length === 0) {
    process.stderr.write('No docs in that range')
    return process.exit()
  }
  // Order each datum's properties by the headers for consistent columns.
  const rows = docs.map(doc => params.headers.map(header => (doc[header]) ? doc[header] : ''))
  const output = new CSV(rows).encode()
  process.stdout.write(output)  
  process.exit()
}
go(params)
github Tangerine-Community / Tangerine / server / src / reporting / process-batch.js View on Github external
const processBatch = async () => {
  // Something may have paused the process like clearing cache.
  reportingWorkerPause = await pathExists(REPORTING_WORKER_PAUSE)
  while (reportingWorkerPause) {
    await sleep(REPORTING_WORKER_PAUSE_LENGTH)
    reportingWorkerPause = await pathExists(REPORTING_WORKER_PAUSE)
  }
  // Set semaphore to tell other processes not to mess with the state file.
  await writeFile(REPORTING_WORKER_RUNNING, '', 'utf-8')
  // Now it's safe to get the state.
  workerState = JSON.parse(await readFile(REPORTING_WORKER_STATE, 'utf-8'))
  workerState = Object.assign({} , defaultState, workerState)
  const DB = PouchDB.defaults(state.pouchDbDefaults)
  const startTime = new Date().toISOString()
  let processed = 0
  // Process batch.
  for (let database of workerState.databases) { 
    const db = new DB(database.name)
    const changes = await db.changes({ since: database.sequence, limit: workerState.batchSizePerDatabase, include_docs: false })
    if (changes.results.length > 0) {
      for (let change of changes.results) {
        try {
          await changeProcessor(change, db)
          processed++
        } catch (error) {
          log.error(`Error on change sequence ${change.seq} with id ${changes.id} - ${error} ::::: `)
        }
      }
      // Even if an error was thrown, continue on with the next sequences.
github local-npm / local-npm / lib / pouchdb-server-lite.js View on Github external
var directory = path.resolve(options.directory);
    var app = express();
    var logger = new Logger(Logger.getLevel(options.logLevel));

    app.use(util.request(logger));
    app.use(compression());
    app.use(favicon(path.resolve(__dirname, '..', 'dist', 'favicon.ico')));

    app.use(corser.create({
        methods: ['GET', 'HEAD', 'POST', 'PUT', 'DELETE'],
        supportsCredentials: true,
        requestHeaders: corser.simpleRequestHeaders.concat(["Authorization", "Origin", "Referer"])
    }));

    // set up express-pouchdb with the prefix (directory)
    var ScopedPouchDB = PouchDB.defaults({
        prefix: directory + '/'
    });
    var configFile = path.resolve(directory, 'config.json');
    var logFile = path.resolve(directory, 'log.txt');
    // hacky, but there doesn't seem to be any other way to prefix the log file
    fs.writeFileSync(configFile, JSON.stringify({
        log: {
            file: logFile
        }
    }), 'utf-8');
    var pouchDBApp = expressPouchDB({
        configPath: configFile
    });
    pouchDBApp.setPouchDB(ScopedPouchDB);
    app.use(pouchDBApp);
github chunksnbits / store.pouchdb / lib / adapter / pouch-server.js View on Github external
PouchServer._express = function (store, serverOptions) {
  if (isNode) {

    // Make sure temporary files created by pouch express are
    // stored into the right folder
    var configPath = serverOptions.configPath.replace(/\/[^\/]*$/, '/');

    var mkdirp = require('mkdirp');
    mkdirp.sync(configPath.replace());

    var PouchDb = require('pouchdb').defaults(store._adapter.pouch.__opts);

    PouchServer.__express = PouchServer.__express || require('express-pouchdb')(PouchDb, serverOptions);
    return PouchServer.__express;
  }
  return null;
};
github yldio / pouch-clerk / test / async-updaters.js View on Github external
var debug = require('debug')('pouch-stream-multi-sync:test');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var describe = lab.experiment;
var before = lab.before;
var after = lab.after;
var it = lab.it;
var Code = require('code');
var expect = Code.expect;

var timers = require('timers');
var PouchDB = require('pouchdb');
var MemPouchDB = PouchDB.defaults({
  db: require('memdown'),
});

var Clerk = require('../');

describe('async updater', function() {

  it('starts when a new doc is found', function(done) {
    var asyncUpdater = {
      start: function(doc) {
        expect(doc.id).to.equal('A');
        clerk.stop(done);
      },
    };

    var clerk = new Clerk({
github Tangerine-Community / Tangerine / client / src / app / shared / _classes / user-database.class.ts View on Github external
import PouchDB from 'pouchdb';
import PouchDBFind from 'pouchdb-find';
import * as PouchDBUpsert from 'pouchdb-upsert';
PouchDB.plugin(PouchDBFind)
PouchDB.plugin(PouchDBUpsert)
PouchDB.defaults({auto_compaction: true, revs_limit: 1})
const SHARED_USER_DATABASE_NAME = 'shared-user-database'

export class UserDatabase {

  userId:string
  username:string
  name:string
  private db:PouchDB

  constructor(username, userId, shared = false) {
    this.userId = userId
    this.username = username
    this.name = username
    if (shared) {
      this.db = new PouchDB(SHARED_USER_DATABASE_NAME)
    } else {
github MikeBild / introduction-graphql / examples / pouchdb / lib / server.js View on Github external
const express = require('express');
const expressCors = require('cors');
const expressMorgan = require('morgan');
const expressBodyParser = require('body-parser');
const PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-adapter-node-websql'))
const DefaultPouch = PouchDB.defaults({prefix: 'databases/', adapter: 'websql'});
const expressPouchDB = require('express-pouchdb')(DefaultPouch, {
  logPath: 'databases/pouchdb.log',
  configPath: 'pouchdb-config.json',
  mode: 'fullCouchDB',
});
const app = express();
const databases = {};

app.enable('trust proxy');
app.disable('x-powered-by');
app.use(expressMorgan('dev'));
app.use(expressPouchDB);
app.use(expressCors());
app.use(expressBodyParser.json({limit: '10mb'}));

let server = undefined;
github hoodiehq / hoodie / server / config / db / factory.js View on Github external
function getDatabaseFactory (config) {
  var PouchDB = require('pouchdb').defaults(config.db)
  var db = function getDatabase (name) {
    if (config.db.url) {
      return new PouchDB(url.resolve(config.db.url, encodeURIComponent(name)))
    }
    return new PouchDB(name)
  }
  db.PouchDB = PouchDB
  return db
}
github Tangerine-Community / Tangerine / server / src / db.js View on Github external
const PouchDB = require('pouchdb')
const dbDefaults = require('./db-defaults.js')
module.exports = PouchDB.defaults(dbDefaults, {timeout: 50000})