commit | 0377b9eae7976e7739697d23713d28ad0d010267 | [log] [tgz] |
---|---|---|
author | Nuno Job <nunojobpinto@gmail.com> | Tue Aug 16 11:42:40 2011 +0200 |
committer | Nuno Job <nunojobpinto@gmail.com> | Tue Aug 16 11:42:40 2011 +0200 |
tree | 4eba44dccd82a00842eaccbe354774d317a9738c | |
parent | d1a2919b0979c304b9d8a2137ad7982b26f326db [diff] |
bump to 0.2.0
nano
(short for nanocouch) is a minimalistic couchdb
driver for node.js
npm install nano
a quick example using nano
to use nano
you have to either provide a) a json
configuration object
or b) a configuration file path
like cfg/tests.js
. refer to cfg/couch.example.js for a example
var nano = require('nano')('./cfg/tests.js');
within the nano
variable you have various methods you can call. these include tasks like create, delete or list databases:
nano.db.create("alice");
in this function there is not callback. in nano
the absence of callback means “do this, ignore what happens”
you normally don't want to do that though:
// clean up the database we created previously nano.db.destroy("alice", function(err,headers,response) { nano.db.create("alice", function(){ // specify the database we are going to use var alicedb = nano.use("alice"); alicedb.insert("rabbit", {crazy: true}, function(e,h,r){ if(e) { throw e; } console.log("you have inserted the rabbit.") }); }); });
the alicedb.use
method creates a scope
where you operate inside a single database. this is just a convenience so you don't have to specify the database name every single time you do an update or delete
// 5: var alicedb = nano.use("alice");
in nano
a callback has always three arguments
// 6: alicedb.insert("rabbit", {crazy: true}, function(e,h,r){ // 7: if(e) { throw e; } // 8: console.log("you have inserted the rabbit.") // 9: });
meaning:
e: the `error`, if any. check error.js for more info. h: the http response `headers` from couchdb, if no error. r: the http `response body` from couchdb, if no error.
that‘s it. don’t forget to delete the database you created:
nano.db.destroy("alice");
*
marks optional
nano.db.create(db_name,callback*)
nano.db.get(db_name,callback*)
nano.db.destroy(db_name,callback*)
nano.db.list(callback*)
nano.db.compact(db_name,callback*)
nano.db.replicate(source,target,continuous*,callback*)
nano.use(db_name)
nano.request(opts,callback*)
nano.use: [nano.db.use, nano.db.scope, nano.scope]
nano.request: [nano.relax, nano.dinosaur]
db.insert(doc_name*,doc,callback*)
db.update(doc_name,rev,doc,callback*)
db.destroy(doc_name,rev,callback*)
db.get(doc_name,params*,callback*)
db.list(params*,callback*)
nano.use
simply sets db_name
in scope. this way you don't have to specify it every time
nano.db.get: [db.info(callback*)]
nano.db.replicate: [db.replicate(target,continuous*,callback*)]
nano.db.compact: [db.compact(callback*)]
nano
is minimalistic so it provides advanced users with a way to code their own extension functions:
nano.request(opts,callback*)
to get a document in a specific rev an advanced user might do:
nano.request( { db: "alice" , doc: "rabbit" , method: "GET" , params: { rev: "1-967a00dff5e02add41819138abb3284d"} }, function (_,_,b) { console.log(b) } );
this is the same as (assuming db = nano.use("alice");
):
nano.get("rabbit", {rev: "1-967a00dff5e02add41819138abb3284d"}, function (_,_,b) { console.log(b) );
pipe
support as provided by request_changes
feed_uuids
, _stats
, _config
, _active_tasks
, _all_docs_by_seq
batch
in updates and insertseveryone is welcome to contribute. patches, bugfixes, new features
nano
in githubgit checkout -b my_branch
git push origin my_branch
package.json
test/
and ./run
.always make sure all the tests pass before sending in your pull request!
we will tell santa
_ / _) ROAR! i'm a vegan! .-^^^-/ / __/ / /__.|_|-|_| cannes est superb
git clone git://github.com/dscape/nano.git
(oO)--',-
in caos