CouchDB library with a simple, functional-programing-friendly API, returning Bluebird promise.
Forked from Cot
Summary
Installing
npm install blue-cot
Differences with Cot
- Returns Bluebird promises
- Class-less, thus a different initialization, but the rest of the API stays the same
- Consequently,
blue-cot
is this
-free: no need to bind functions contexts! 4xx
and 5xx
responses will return rejected promises (should be handled with .catch
)- Adds some view functions goodies
Initialization
const bluecot = require('blue-cot')
const config = {
hostname: 'localhost'
port: 5984,
ssl: true
auth: 'username:password'
user: 'username'
pass: 'password'
debug: true
}
const getDbApi = bluecot(config)
const db = getDbApi('some-db-name')
API
Common API
Cot API Documentation
Those are the same than for cot-node
. Just remember this difference in error handling: here, 4xx
and 5xx
responses from CouchDB will return rejected promises (should be handled with .catch
)
- docUrl
- info
- get
- exists
- put
- post
- batch
- update
- delete
- bulk
- buildQueryString
- viewQuery
- view
- allDocs
- viewKeysQuery
- viewKeys
- allDocsKeys
- changes
Specific API
Additional database functions
fetch
takes doc ids, returns docs
db.fetch([ 'doc-1', 'doc-2', 'doc-3' ])
.then(function (docs) {
docs[0]._id === 'doc-1'
docs[1]._id === 'doc-2'
docs[2]._id === 'doc-3'
})
View functions
To access those, pass a design doc name as second argument
const db = getDbApi('some-db-name', 'some-design-doc-name')
viewCustom
viewByKeysCustom
viewByKey
viewFindOneByKey
viewByKeys
see lib/view_functions
If you find this module useful, consider making a PR to improve the documentation