Relax, superagent on a couch
Relax is a lightweight, high-level CouchDB client. It's built upon superagent library. Relax API eliminates the need to write so criminally-long HTTP-requests in the Couch style. Relax API has been inspired by the jQuery.couch.js API.
It's available as a node.js module, named relax-component
v 0.1.x works with node.js v.6.x and superagent v.2.1.0
Usage
var Relax = ;var relax = ;relax;var admin = 'http://admin:kjre4317@localhost:5984';
Chainable or callback forms
Each method has chainable and callback-style api. Chainable form always returns superagent-response. While callback form returns what you are expect to be returned from CouchDB:
Chainable-form:
relax
Callback-form:
relax
complex ddoc handlers
Note complex form of ddoc handlers .show().get(), .list().view(), .update().post(), .update().put()
Methods
setters:
- .dbname()
session methods:
- .login(), .logout(), .session(), .signup()
server methods:
- .uuids()
example
relax ;
--> {"uuids":["11eaa495bfae96d36d6a53f21a01adf6","11eaa495bfae96d36d6a53f21a01b9b7"]}
relax;
--> ["11eaa495bfae96d36d6a53f21a01adf6","11eaa495bfae96d36d6a53f21a01b9b7"]
database methods:
- .exists(), .create(), .drop(), .info()
example
relax
--> true
document methods:
- .get(), .post(), .put(), .push() (aka crude get-then-put, use .update instead)
example
var doc = text: 'some text' count: 1;relax
-->
relax
-->
array of documents methods:
- .all(), .bulk()
relax alldocs
-->
design doc handlers:
- .view(), .show().get(), .list().view(), .update().post(), .update().put()
_view
design document:
{ };
component:
relax ;
-->
_show
design document:
var { return body : "just " + doctext ;}var doc = _id: 'some-id' text: 'some text' count: 0;var ddoc = _id: '_design/spec' shows: 'justText': justText ;
component:
relax ;
--> just some text
_list
design document:
var { ; var row; whilerow = ; ;}
component:
relax ;
--> some text
_update
design document:
var { var field = reqqueryfield; var value = reqqueryvalue; var message = "set "+field+" to "+value; docfield = value; return doc message;}
component:
relax ;
--> set world to test
not yet included
- .allDbs, .activeTasks, .stats, .config, .compact, .replicate, .viewCleanUp, etc
if you need them, use straight SA-request.get(path) instead
Installation
With node.js:
$ npm install relax-component
or with component
$ component install mbykov/relax
Or as standalone and minified version:
API
View more examples in test suite
Running node tests
$ make test
Running browser tests
push test/* to local couchdb, and open text/index.html
License
GNU GPL