then-couchdb

0.4.4 • Public • Published

then-couchdb

then-couchdb is a promise-based CouchDB client for node.js. It supports all the features of CouchDB in a simple, user-friendly package.

Usage

Creating a client.

var couchdb = require('then-couchdb');
var db = couchdb.createClient('http://localhost:5984/my-database');

Save and fetch a single document.

db.save({ name: 'one' }).then(function (doc) {
  assert(doc);
  assert(doc._id);
  assert(doc._rev);
 
  db.get(doc._id).then(function (doc) {
    assert(doc);
    assert.equal(doc.name, 'one');
  });
});

Save and fetch many documents in bulk.

db.saveAll([
  { name: 'one' },
  { name: 'two' },
  { name: 'three' }
]).then(function (docs) {
  assert(Array.isArray(docs));
  assert.equal(docs.length, 3);
 
  var keys = docs.map(function (doc) {
    return doc._id;
  });
 
  db.getAll(keys).then(function (docs) {
    assert(Array.isArray(docs));
    assert.equal(docs.length, 3);
  });
});

Package Sidebar

Install

npm i then-couchdb

Weekly Downloads

0

Version

0.4.4

License

MIT

Last publish

Collaborators

  • mjackson