0.1.0 • Published 6 years ago

pouchq v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

PouchQ

Simplified interactions with PouchDB. These were developed for a specific project but have mostly been generalized for usage elsewhere.

npm i -S pouchq

Usage

You'll need to install and create a PouchDB database first. For example:

npm i pouchdb
// script.js
const PouchDB = require('pouchdb');
const db = new PouchDB('my_db');

This library simplifies managing large changes with a database. Everything returns a Promise. Examples assume availability of await and async.

// script.js
const PouchDB = require('pouchdb');
const PouchQ = require('pouchq');

const db = new PouchDB('my_db');
const pq = PouchQ(db); // you can overwrite db in some commands

Set all instances of key to value.

pq.blankDatabase(key, value, [optionalDB]);

Get or create a doc. Makes the assumption that docs hold values on a key called value.

const doc = await pq.safelyGet(id, defaultValue, [optionalDB])

Delete all docs in a database (from the index, not from disk).

pq.deleteDatabase([optionalDB]);

Get docs from a response.

const docs = await db.allDocs({include_docs: true}).then(pq.filterAllDocs);

Remove ._id, ._rev from docs. Also makes sure .value is a number (which is probably too specific for most projects).

const docs = await db.allDocs({include_docs: true}).then(pq.filterAllDocs).then(pq.postQueryCleanup);
0.1.0

6 years ago

0.0.1

6 years ago