Comparing version 0.2.0 to 0.3.1
173
nano.js
@@ -65,8 +65,8 @@ /* Minimal Couch In Node | ||
* | ||
* @param {opts} The request options; e.g. {db: "test", method: "GET"} | ||
* {opts.db} REQUIRED The database name | ||
* {opts.method} REQUIRED The HTTP Method | ||
* {opts.doc} The document URI, if any | ||
* {opts.body} The body, if any | ||
* @param {callback} The function to callback | ||
* @param {opts:object} The request options; e.g. {db: "test", method: "GET"} | ||
* {opts.db:string} The database name | ||
* {opts.method:string} The HTTP Method | ||
* {opts.doc:string:optional} The document URI, if any | ||
* {opts.body:object|string:optional} The JSON body, if any | ||
* @param {callback:function:optional} The function to callback | ||
* | ||
@@ -105,2 +105,15 @@ * @return Execution of the code in your callback. Hopefully you are handling | ||
} | ||
/* | ||
* Merges options with params (if any) | ||
* | ||
* @param {opts:object} The request options | ||
* @param {params:object} The aditional query string params | ||
*/ | ||
function merge_opts_with_params(opts,params) { | ||
if(params) { | ||
opts.params = params; | ||
} | ||
return opts; | ||
} | ||
@@ -112,2 +125,3 @@ /**************************************************************************** | ||
* Creates a CouchDB Database | ||
* http://wiki.apache.org/couchdb/HTTP_database_API | ||
* | ||
@@ -127,2 +141,4 @@ * e.g. function recursive_retries_create_db(tried,callback) { | ||
* | ||
* @param {db_name:string} The name of the database | ||
* | ||
* @see relax | ||
@@ -142,2 +158,4 @@ */ | ||
* | ||
* @param {db_name:string} The name of the database | ||
* | ||
* @see relax | ||
@@ -156,2 +174,4 @@ */ | ||
* | ||
* @param {db_name:string} The name of the database | ||
* | ||
* @see relax | ||
@@ -181,2 +201,4 @@ */ | ||
* | ||
* @param {db_name:string} The name of the database | ||
* | ||
* @see relax | ||
@@ -188,18 +210,34 @@ */ | ||
/* | ||
* Replicates a CouchDB Database | ||
* | ||
* e.g. nano.db.replicate(db_1, db_2); | ||
* | ||
* @see relax | ||
*/ | ||
function replicate_db(source, target, continuous, callback) { | ||
if(typeof continuous === "function") { | ||
callback = continuous; | ||
continuous = false; | ||
} | ||
var body = {source: source, target: target}; | ||
if(continuous) { body.continuous = true; } | ||
relax({db: "_replicate", body: body, method: "POST"},callback); | ||
} | ||
/* | ||
* Replicates a CouchDB Database | ||
* | ||
* e.g. nano.db.replicate(db_1, db_2); | ||
* | ||
* @param {source:string} The name of the source database | ||
* @param {target:string} The name of the target database | ||
* @param {continuous:bool:optional} Turn on continuous replication | ||
* | ||
* @see relax | ||
*/ | ||
function replicate_db(source, target, continuous, callback) { | ||
if(typeof continuous === "function") { | ||
callback = continuous; | ||
continuous = false; | ||
} | ||
var body = {source: source, target: target}; | ||
if(continuous) { body.continuous = true; } | ||
relax({db: "_replicate", body: body, method: "POST"},callback); | ||
} | ||
/* | ||
* Returns the CouchDB + Nano Configuration | ||
* | ||
* @see relax | ||
*/ | ||
function config(callback) { | ||
relax({db: "_config", method: "GET"}, function (e,h,r) { | ||
if(e) { callback(e); } | ||
callback(null,h,{nano: cfg, couch: r}); | ||
}); | ||
} | ||
@@ -214,17 +252,20 @@ /**************************************************************************** | ||
* Inserts a document in a CouchDB Database | ||
* http://wiki.apache.org/couchdb/HTTP_Document_API | ||
* | ||
* @param {doc:object|string} The document | ||
* @param {doc_name:string:optional} The name of the document | ||
* | ||
* @see relax | ||
*/ | ||
function insert_doc(doc_name,doc,callback) { | ||
var opts = {db: db_name}; | ||
if(typeof doc === "function") { | ||
callback = doc; | ||
opts.body = doc_name; | ||
opts.method = "POST"; | ||
function insert_doc(doc,doc_name,callback) { | ||
var opts = {db: db_name, body: doc, method: "POST"}; | ||
if(doc_name) { | ||
if(typeof doc_name === "function") { | ||
callback = doc_name; | ||
} | ||
else { | ||
opts.doc = doc_name; | ||
opts.method = "PUT"; | ||
} | ||
} | ||
else { | ||
opts.doc = doc_name; | ||
opts.body = doc; | ||
opts.method = "PUT"; | ||
} | ||
relax(opts,callback); | ||
@@ -234,10 +275,15 @@ } | ||
/* | ||
* 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); | ||
} | ||
* Updates a document in a CouchDB Database | ||
* | ||
* | ||
* @param {doc_name:string} The name of the document | ||
* @param {rev:string} The previous document revision | ||
* @param {doc:object|string} The document | ||
* | ||
* @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); | ||
} | ||
@@ -247,2 +293,5 @@ /* | ||
* | ||
* @param {doc_name:string} The name of the document | ||
* @param {rev:string} The previous document revision | ||
* | ||
* @see relax | ||
@@ -258,10 +307,19 @@ */ | ||
* | ||
* e.g. db2.get("foo", {revs_info: true}, function (e,h,b) { | ||
* console.log(e,h,b); | ||
* return; | ||
* }); | ||
* | ||
* @param {doc_name:string} The name of the document | ||
* @param {params:object:optional} Additions to the querystring | ||
* | ||
* @see relax | ||
*/ | ||
function get_doc(doc_name,params,callback) { | ||
var opts = {db: db_name, doc: doc_name, method: "GET"}; | ||
if(typeof params === "function") { | ||
callback = params; | ||
params = {}; | ||
params = null; | ||
} | ||
relax({db: db_name, doc: doc_name, method: "GET", params: params},callback); | ||
relax(merge_opts_with_params(opts,params),callback); | ||
} | ||
@@ -272,11 +330,28 @@ | ||
* | ||
* @param {params:object:optional} Additions to the querystring | ||
* | ||
* @see get_doc | ||
* @see relax | ||
*/ | ||
function list_docs(params,callback) { | ||
var opts = {db: db_name, doc: "_all_docs", method: "GET"}; | ||
if(typeof params === "function") { | ||
callback = params; | ||
params = {}; | ||
params = null; | ||
} | ||
relax({db: db_name, doc: "_all_docs", method: "GET", params: params},callback); | ||
relax(merge_opts_with_params(opts,params),callback); | ||
} | ||
/* | ||
* Bulk update/delete/insert functionality | ||
* http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API | ||
* | ||
* @param {docs:object} The documents as per the CouchDB API (check link) | ||
* | ||
* @see get_doc | ||
* @see relax | ||
*/ | ||
function bulk_docs(docs,callback) { | ||
relax({db: db_name, doc: "_bulk_docs", body: docs, method: "POST"},callback); | ||
} | ||
@@ -299,5 +374,10 @@ public_functions = { info: function(cb) { get_db(db_name,cb); } | ||
, destroy: destroy_doc | ||
//, bulk: bulk_doc | ||
, bulk: bulk_docs | ||
, list: list_docs | ||
//, views: {} | ||
// , attachment: { insert: insert_att | ||
// , update: update_att | ||
// , get: get_att | ||
// , destroy: destroy_att | ||
// } | ||
}; | ||
@@ -319,2 +399,3 @@ return public_functions; | ||
, request: relax | ||
, config: config | ||
, relax: relax // Alias | ||
@@ -321,0 +402,0 @@ , dinosaur: relax // Alias |
{ "name": "nano" | ||
, "description": "NanoCouch is a minimalistic driver for CouchDB built on mikeals/request" | ||
, "homepage": "http://github.com/dscape/nano" | ||
, "version": "0.2.0" | ||
, "version": "0.3.1" | ||
, "author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)" | ||
@@ -6,0 +6,0 @@ , "keywords": ["CouchDB", "data", "request", "json", "nosql", "micro", "nano"] |
@@ -38,3 +38,3 @@ # nano | ||
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 | ||
the `nano.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 | ||
@@ -76,2 +76,3 @@ // 5: var alicedb = nano.use("alice"); | ||
`nano.request(opts,callback*)` | ||
`nano.config(callback)` | ||
@@ -87,3 +88,3 @@ #### aliases | ||
`db.insert(doc_name*,doc,callback*)` | ||
`db.insert(doc,doc_name*,callback*)` | ||
`db.update(doc_name,rev,doc,callback*)` | ||
@@ -131,4 +132,2 @@ `db.destroy(doc_name,rev,callback*)` | ||
5. support bulk load | ||
6. `_uuids`, `_stats`, `_config`, `_active_tasks`, `_all_docs_by_seq` | ||
7. support `batch` in updates and inserts | ||
@@ -135,0 +134,0 @@ ## contribute |
@@ -14,5 +14,5 @@ var vows = require('/usr/lib/node_modules/vows/lib/vows') | ||
async.parallel( | ||
[ function(cb) { db.insert("foobar", {"foo": "bar"}, cb); } | ||
, function(cb) { db.insert("barfoo", {"bar": "foo"}, cb); } | ||
, function(cb) { db.insert("foobaz", {"foo": "baz"}, | ||
[ function(cb) { db.insert({"foo": "bar"},"foobar",cb); } | ||
, function(cb) { db.insert({"bar": "foo"},"barfoo",cb); } | ||
, function(cb) { db.insert({"foo": "baz"},"foobaz", | ||
function (e,h,b) { db.destroy("foobaz", b._rev, cb); }); } | ||
@@ -39,3 +39,3 @@ ], | ||
vows.describe('nano.db.compact').addBatch({ | ||
"destroy_db": { | ||
"compact_db": { | ||
topic: function () { compact_db(this.callback); } | ||
@@ -42,0 +42,0 @@ , "=": compact_db_ok |
@@ -15,5 +15,5 @@ var vows = require('/usr/lib/node_modules/vows/lib/vows') | ||
async.parallel( | ||
[ function(cb) { db.insert("foobar", {"foo": "bar"}, cb); } | ||
, function(cb) { db.insert("barfoo", {"bar": "foo"}, cb); } | ||
, function(cb) { db.insert("foobaz", {"foo": "baz"}, cb); } | ||
[ function(cb) { db.insert({"foo": "bar"},"foobar",cb); } | ||
, function(cb) { db.insert({"bar": "foo"},"barfoo",cb); } | ||
, function(cb) { db.insert({"foo": "baz"},"foobaz",cb); } | ||
, function(cb) { nano.db.create("db_re1_replica", cb); } | ||
@@ -20,0 +20,0 @@ ], |
@@ -13,3 +13,3 @@ var vows = require('/usr/lib/node_modules/vows/lib/vows') | ||
nano.db.create(db_name, function () { | ||
db.insert("foo", {foo: "bar"}, function (_,_,b) { | ||
db.insert({foo: "bar"}, "foo", function (_,_,b) { | ||
db.destroy("foo", b.rev, function (e,h,b) { | ||
@@ -16,0 +16,0 @@ callback(e,h,b); |
@@ -15,3 +15,3 @@ var vows = require('/usr/lib/node_modules/vows/lib/vows') | ||
nano.db.create(db_name, function () { | ||
db.insert("foo", {foo: "bar"}, function () { | ||
db.insert({foo: "bar"}, "foo", function () { | ||
db.get("foo", function (e,h,b) { | ||
@@ -38,4 +38,4 @@ callback(e,h,b); | ||
nano.db.create(db2_name, function () { | ||
db2.insert("foo", {foo: "bar"}, function () { | ||
db2.insert("foo", {foo: "bar"}, function () { // Conflict, no rev | ||
db2.insert({foo: "bar"}, "foo", function () { | ||
db2.insert({foo: "bar"}, "foo", function () { // Conflict, no rev | ||
db2.get("foo", {revs_info: true}, function (e,h,b) { | ||
@@ -42,0 +42,0 @@ callback(e,h,b); |
@@ -19,5 +19,5 @@ var vows = require('/usr/lib/node_modules/vows/lib/vows') | ||
async.parallel( | ||
[ function(cb) { db.insert("foobar", {"foo": "bar"}, cb); } | ||
, function(cb) { db.insert("barfoo", {"bar": "foo"}, cb); } | ||
, function(cb) { db.insert("foobaz", {"foo": "baz"}, cb); } | ||
[ function(cb) { db.insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db.insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db.insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
@@ -43,5 +43,5 @@ function(err, results){ | ||
async.parallel( | ||
[ function(cb) { db2.insert("foobar", {"foo": "bar"}, cb); } | ||
, function(cb) { db2.insert("barfoo", {"bar": "foo"}, cb); } | ||
, function(cb) { db2.insert("foobaz", {"foo": "baz"}, cb); } | ||
[ function(cb) { db2.insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db2.insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db2.insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
@@ -72,5 +72,5 @@ function(err, results){ | ||
async.parallel( | ||
[ function(cb) { db3.insert("foobar", {"foo": "bar"}, cb); } | ||
, function(cb) { db3.insert("barfoo", {"bar": "foo"}, cb); } | ||
, function(cb) { db3.insert("foobaz", {"foo": "baz"}, cb); } | ||
[ function(cb) { db3.insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db3.insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db3.insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
@@ -77,0 +77,0 @@ function(err, results){ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38242
23
943
169