backflip / then-couchdb

A promise-based CouchDB client for node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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);
  });
});

About

A promise-based CouchDB client for node.js


Languages

Language:JavaScript 100.0%