"Pouchy is the sugar API for PouchDB that I've been hoping someone would write" @nolanlawson
simple, enhanced PouchDB. Pouchy wraps & extends PouchDB and provides various sorely needed sugar methods. further, it assists by standardizing the returned document format. most methods provided are very simple PouchDB-native method modifiers, but are targeted to save you frequent boilerplate re-typing! this library also proxies the PouchDB API directly, so you can use it like a PouchDB instance itself!
yarn add pouchy
if you need node support to flush databases to disk, versus using pouchy as an api client to remote couch/pouches, add your preferred adapters too. e.g.:
yarn add pouchy pouchdb-adapter-leveldb
api docs and examples officially live here.
here are some basic examples:
// local, node database
import Pouchy from 'pouchy'
import level from 'pouchdb-adapter-leveldb'
Pouchy.plugin(level)
type Fruit = { type: string, tastes: string }
const fruit = new Pouchy<Fruit>({ name: 'fruit' })
const orange = await fruit.save({ type: 'orange', tastes: 'delicious' })
console.log(orange)
/**
{
type: 'orange',
tastes: 'delicious',
_id: 'EA1F2B55-2482-89C6-907E-6F938C59F734',
_rev: '1-f60b9b7d775a89d280e1f4c07122b863'
}
*/
// local & remote replicated database!
import Pouchy from 'pouchy'
import memory from 'pouchdb-adapter-memory'
Pouchy.plugin(memory)
const customers = new Pouchy({
name: 'customers',
replicate: 'sync',
url: 'http://mydomain.org/db/customers'
})
customers.save({ firstName: 'bill', lastName: 'brasky' })
// wait for it... and couchdb/pouchdb-server @ http://mydomain.org/db/customers
// will receive bill brasky!
why use pouchy over pouchdb?
_id and _rev can be obnoxious with pouchdb (no hard feelings, of course)._ids and _revs inconsistently. some methods return docs with an id attribute. some return docs with _id. the same happens for rev._rev nested under other attributes, vs. being at the top of the document._id and a _rev in a return result, you'll get those attributes back on the top of your documents, every time..all(), to get all full documents in your store, in a simple array..clear()/.deleteAll() to purge your store of its docs..find to return simply an array of docs!pouchdb-find plugin, which is super handy and regularly recommended for use.Thanks! cdaringe
rev/id ==> _rev/_id mappingrev or id exist on docs returned from pouch exist, but no _rev or _id exist, that particular kv pair will be moved to the _-prefixed key and the non prefixed key will be removed.getReplicationOptionsdestroy, actually destroy gracefully. that means, don't resolve the promise/callback until live dbs have all http requests fully settled. see here for more info..asCallback.Pouchy.PouchDB.plugin(...). The following plugins are available by default:bulkGet when no docs are provided.all({ include_docs: false }) to properly handle .rev/._revhasLikelySynced event'both' sync option, added {} option. dropped replicateLivedestroy, which .cancels any replication from .syncEmitter (see replicate). deprecate 6.2.0-1. changeEmitter => syncEmitter (rapid patch, so no major bump)this.syncEmitter when using the replicate APIbulkGet_id was still id when doing .all({ include_docs: false })name if passed. url will still be used for replication if requested. prior versions preferred url to the Pouch constructor over namechanges, and associated on/off. didn't work out-of-the-box anyway. may return in 4.xfs location. Previously was not honoring path optionGenerated using TypeDoc