got-couch
v1.2.0
Published
A got based couchdb driver/interface
Downloads
11
Readme
got-couch
A got based couch driver/interface
NOTE: This driver is very incomplete, however, the goal is to support the all of the CouchDB version 2 features and to cover the entire REST API.
Usage
const GotCouch = require('got-couch')
const CONFIG = {
url: 'http://localhost'
, port: 5984
, username: 'root'
, password: 'password'
}
const DB_NAME = 'my-test'
GotCouch(CONFIG).then((couchdb) => {
// create a database
//http://docs.couchdb.org/en/2.0.0/api/database/common.html#put--db
couchdb.db.create(DB_NAME).then((response) => { /* ... */ })
// get information about a database
// http://docs.couchdb.org/en/2.0.0/api/database/common.html#get--db
couchdb.db.info(DB_NAME).then((response) => { /* ... */})
// delete a database
// http://docs.couchdb.org/en/2.0.0/api/database/common.html#delete--db
couchdb.db.delete(DB_NAME).then((response) => { /* ... */})
// insert a document with a generated identifier
// http://docs.couchdb.org/en/2.0.0/api/database/common.html#post--db
couchdb.insert(DB_NAME, { test: 'stuff' /* ... */ })
.then((response) => { /* ... */ })
// insert a document with a specified identifier (`docid`)
// http://docs.couchdb.org/en/2.0.0/api/document/common.html#put--db-docid
couchdb.create(DB_NAME, 'docid', { test: 'stuff' /* ... */ })
.then((response) => { /* ... */ })
// retrieve a document by its identifier (`docid`).
// http://docs.couchdb.org/en/2.0.0/api/document/common.html#get--db-docid
couchdb.get(DB_NAME, 'docid').then((response) => { /* ... */ })
// list all the documents in the given database.
// http://docs.couchdb.org/en/2.0.0/api/database/bulk-api.html#db-all-docs
couchdb.list(DB_NAME, {}).then((response) => { /* ... */ })
})
Response Object
{
headers: { /* document headers */ }
, body: { /* body of the stored document */ }
, raw: { /* raw response object from couchdb */ }
}