Added version 0.1.6
Added Update
Refactored tests to cleanup as the very first thing they do
diff --git a/README.md b/README.md
index 7f1e372..741c45d 100644
--- a/README.md
+++ b/README.md
@@ -53,7 +53,8 @@
Assuming `var db = nano.use("somedb");`:
- db.insert(doc_name,doc,callback)
+ db.insert(doc_name,doc,callback) // doc_name is optional
+ db.update(doc_name,rev,doc,callback)
db.destroy(doc_name,rev,callback)
db.get(doc_name,callback)
db.list(callback)
@@ -65,7 +66,7 @@
nano.db.get(db_name,callback)
nano.db.list(callback)
nano.db.compact(db_name,callback)
- nano.db.replicate(source,target,continuous,callback) // Continuous is optional
+ nano.db.replicate(source,target,continuous,callback) // continuous is optional
### Other / Advanced
@@ -87,6 +88,8 @@
3. Convenience functions for attachments
4. Support views
5. Support bulk load
+6. `_uuids`, `_stats`, `_config`, `_active_tasks`, `_all_docs_by_seq`
+7. Support `batch` in updates and inserts.
Great segway to contribute.
diff --git a/nano.js b/nano.js
index c2cd218..c1005ea 100644
--- a/nano.js
+++ b/nano.js
@@ -219,6 +219,16 @@
}
/*
+ * Updates a document in a CouchDB Database
+ *
+ * @see relax
+ */
+ function update_doc(doc_name,rev,doc,callback) {
+ doc._rev = rev;
+ relax({ db: db_name, doc: doc_name, method: "PUT", body: doc},callback);
+ }
+
+ /*
* Destroy a document from CouchDB Database
*
* @see relax
@@ -259,6 +269,7 @@
//, changes: { add: add_listener
// , remove: remove_listener}
, insert: insert_doc
+ , update: update_doc
, get: get_doc
, destroy: destroy_doc
//, bulk: bulk_doc
diff --git a/package.json b/package.json
index a699e1a..e2894d9 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{ "name": "nano"
, "description": "NanoCouch is a minimalistic driver for CouchDB built on mikeals/request"
, "homepage": "http://github.com/dscape/nanocouch"
-, "version": "0.1.5"
+, "version": "0.1.6"
, "author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)"
, "keywords": ["CouchDB", "data", "request", "json", "nosql", "micro", "nano"]
, "dependencies": { "request": ">=1.9.8", "b64": "1.0.0" }
diff --git a/tests/db/create.js b/tests/db/create.js
index a229b61..ffa75df 100644
--- a/tests/db/create.js
+++ b/tests/db/create.js
@@ -16,9 +16,9 @@
}
function create_db_ok(e,h,b) {
+ nano.db.destroy("db_cr1");
assert.isNull(e);
assert.equal(b.ok, true);
- nano.db.destroy("db_cr1");
}
/*****************************************************************************
@@ -40,8 +40,8 @@
}
function recursive_retries_create_db_ok(v) {
- assert.equal(v,true);
nano.db.destroy("db_cr2");
+ assert.equal(v,true);
}
vows.describe('nano.db.create').addBatch({
diff --git a/tests/db/destroy.js b/tests/db/destroy.js
index c1adc4e..5ccac94 100644
--- a/tests/db/destroy.js
+++ b/tests/db/destroy.js
@@ -16,9 +16,9 @@
}
function destroy_db_ok(e,h,b) {
+ nano.db.destroy("db_de1");
assert.isNull(e);
assert.equal(b.ok, true);
- nano.db.destroy("db_de1");
}
vows.describe('nano.db.destroy').addBatch({
diff --git a/tests/db/get.js b/tests/db/get.js
index 2bc13c2..17c4657 100644
--- a/tests/db/get.js
+++ b/tests/db/get.js
@@ -16,11 +16,11 @@
}
function get_db_ok(e,h,b) {
+ nano.db.destroy("db_ge1");
assert.isNull(e);
assert.equal(b.doc_count,0);
assert.equal(b.doc_del_count,0);
assert.equal(b.db_name,"db_ge1");
- nano.db.destroy("db_ge1");
}
vows.describe('nano.db.get').addBatch({
diff --git a/tests/db/list.js b/tests/db/list.js
index 7aa302f..fd1b589 100644
--- a/tests/db/list.js
+++ b/tests/db/list.js
@@ -16,9 +16,9 @@
}
function list_db_ok (e,h,b) {
+ nano.db.destroy("db_li1");
assert.isNull(e);
assert.notEqual(b.indexOf("db_li1"),-1);
- nano.db.destroy("db_li1");
}
vows.describe('nano.db.list').addBatch({
diff --git a/tests/doc/destroy.js b/tests/doc/destroy.js
index cbb13c3..02f0d7e 100644
--- a/tests/doc/destroy.js
+++ b/tests/doc/destroy.js
@@ -20,11 +20,11 @@
}
function destroy_doc_ok(e,h,b) {
+ nano.db.destroy(db_name);
assert.isNull(e);
assert.ok(b.ok);
assert.equal(b.id, "foo");
assert.ok(b.rev);
- nano.db.destroy(db_name);
}
vows.describe('db.destroy').addBatch({
diff --git a/tests/doc/get.js b/tests/doc/get.js
index 7c60581..20b5e97 100644
--- a/tests/doc/get.js
+++ b/tests/doc/get.js
@@ -20,11 +20,11 @@
}
function get_doc_ok(e,h,b) {
+ nano.db.destroy(db_name);
assert.isNull(e);
assert.ok(b._rev);
assert.equal(b._id, "foo");
assert.equal(b.foo, "bar");
- nano.db.destroy(db_name);
}
vows.describe('db.get').addBatch({
diff --git a/tests/doc/insert.js b/tests/doc/insert.js
index 4629320..70585b9 100644
--- a/tests/doc/insert.js
+++ b/tests/doc/insert.js
@@ -15,11 +15,11 @@
}
function insert_doc_ok(e,h,b) {
+ nano.db.destroy(db_name);
assert.isNull(e);
assert.ok(b.ok);
assert.ok(b.rev);
assert.ok(b.id);
- nano.db.destroy(db_name);
}
vows.describe('db.insert').addBatch({
diff --git a/tests/doc/list.js b/tests/doc/list.js
index f0eaae5..868d24c 100644
--- a/tests/doc/list.js
+++ b/tests/doc/list.js
@@ -23,10 +23,10 @@
}
function list_doc_ok(e,h,b) {
+ nano.db.destroy(db_name);
assert.isNull(e);
assert.equal(b.total_rows,3);
assert.ok(b.rows);
- nano.db.destroy(db_name);
}
vows.describe('doc.list').addBatch({
diff --git a/tests/doc/update.js b/tests/doc/update.js
new file mode 100644
index 0000000..6b0376d
--- /dev/null
+++ b/tests/doc/update.js
@@ -0,0 +1,35 @@
+var vows = require('/usr/lib/node_modules/vows/lib/vows')
+ , assert = require('assert')
+ , cfg = require('../../cfg/tests.js')
+ , nano = require('../../nano')(cfg)
+ , db_name = "doc_up1"
+ , db = nano.use(db_name);
+
+/*****************************************************************************
+ * update_doc *
+ *****************************************************************************/
+function update_doc(callback) {
+ nano.db.create(db_name, function () {
+ db.insert("foo", {foo: "bar"}, function (_,_,b) {
+ db.update("foo", b.rev, {foo: "baz"}, function (e,_,b) {
+ callback(e,b);
+ return;
+ });
+ });
+ });
+}
+
+function update_doc_ok(e,b) {
+ nano.db.destroy(db_name);
+ assert.isNull(e);
+ assert.equal(b.id, "foo");
+ assert.ok(b.ok);
+ assert.ok(b.rev);
+}
+
+vows.describe('db.update').addBatch({
+ "update_doc": {
+ topic: function () { update_doc(this.callback); }
+ , "=": update_doc_ok
+ }
+}).exportTo(module);
\ No newline at end of file