rx-pouchdb
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

rx-pouchdb Join the chat at https://gitter.im/ZenyWay/rx-pouchdb

NPM build status Coverage Status Dependency Status

thin RXJS abstraction layer for pouchDB with read and write RXJS operators.

example

a live version of this example can be viewed here in the browser console, or by cloning this repository and running the following commands from a terminal:

npm install
npm run example

the files of this example are available in this repository.

import newRxPouchDb, { DocId, VersionedDoc } from 'rx-pouchdb/dist'
import debug = require('debug')
const PouchDB = require('pouchdb-browser') // no valid type definitions for TS2
debug.enable('example:*,rx-pouchdb:*') // rx-pouchdb uses `debug`
 
const db = new PouchDB('sids')
 
const sids = newRxPouchDb(db, {
  read: { include_docs: true }
})
 
const docs = [{
  _id: 'hubbard-rob_monty-on-the-run',
  title: 'Monty on the Run',
  author: 'Rob Hubbard',
  release: '1985'
}, [{
  _id: 'hubbard-rob_sanxion',
  title: 'Sanxion',
  author: 'Rob Hubbard',
  release: '1986'
}, {
  _id: 'tel-jeroen_ikari-union',
  title: 'Ikari Union',
  author: 'Jeroen Tel',
  release: '1987'
}]]
 
function getId <D extends VersionedDoc>(doc: D): DocId
function getId <D extends VersionedDoc>(doc: D[]|D) {
  return Array.isArray(doc) ? doc.map(getId) : <DocId>{ _iddoc._id }
}
 
const refs = docs.map(getId)
 
// write docs to vault
const write$ = sids.write(docs)
 
// read docs from vault
const read$ = sids.read(refs)
 
// search Rob Hubbard tunes
const search$ = sids.read([{
  startkey: 'hubbard-',
  endkey: 'hubbard-\uffff'
}])
 
write$.forEach(debug('example:write:'))
.catch(debug('example:write:error:'))
.then(() => read$.forEach(debug('example:read:')))
.catch(debug('example:read:error:'))
.then(() => search$.forEach(debug('example:search:')))
.catch(debug('example:search:error:'))
.then(() => db.destroy())
.then(debug('example:destroy:done'))
.catch(debug('example:destroy:error:'))

API v1.0 experimental

ES5 and Typescript compatible. Coded in Typescript 2.

run the unit tests in your browser.

CONTRIBUTING

see the contribution guidelines

LICENSE

Copyright 2017 Stéphane M. Catala

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and Limitations under the License.

Dependencies (5)

Dev Dependencies (31)

Package Sidebar

Install

npm i rx-pouchdb

Weekly Downloads

9

Version

1.1.2

License

SEE LICENSE IN LICENSE

Last publish

Collaborators

  • smcatala