pouchq
v0.1.0
Published
Simplified interactions with PouchDB.
Downloads
1
Readme
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);