Comparing version 0.3.1 to 0.3.2
78
nano.js
@@ -20,4 +20,5 @@ /* Minimal Couch In Node | ||
, qs = require('querystring') | ||
, _ = require('underscore') | ||
, error = require('./error') | ||
, headers = { "content-type": "application/json", "accept": "application/json" } | ||
, headers = { "content-type": "application/json" } | ||
, nano; | ||
@@ -68,5 +69,7 @@ | ||
* {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 | ||
* {opts.method:string} The http Method | ||
* {opts.doc:string:optional} The document name | ||
* {opts.att:string:optional} The attachment name | ||
* {opts.content_type:string:optional} The content type, else json will be used | ||
* {opts.body:object|string|binary:optional} The JSON body | ||
* @param {callback:function:optional} The function to callback | ||
@@ -84,8 +87,12 @@ * | ||
if(!callback) { callback = function () { return; }; } // Void Callback | ||
if(opts.doc) { url += "/" + opts.doc; } // Add the document to the URL | ||
if(opts.doc) { | ||
url += "/" + opts.doc; // Add the document to the URL | ||
if(opts.att) { url += "/" + opts.att; } // Add the attachment to the URL | ||
} | ||
if(opts.content_type) { req.headers["content-type"] = opts.content_type; } | ||
if(opts.body) { | ||
if(typeof opts.body === "object") { req.body = JSON.stringify(opts.body); } | ||
else { req.body = opts.body; } | ||
else { req.body = opts.body; } // String or binary | ||
} | ||
req.uri = url + (params ? "?" + qs.stringify(params) : ""); | ||
req.uri = url + (_.isEmpty(params) ? "" : "?" + qs.stringify(params)); | ||
request(req, function(e,h,b){ | ||
@@ -107,15 +114,2 @@ if(e) { | ||
} | ||
/* | ||
* 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; | ||
} | ||
@@ -311,8 +305,7 @@ /**************************************************************************** | ||
function get_doc(doc_name,params,callback) { | ||
var opts = {db: db_name, doc: doc_name, method: "GET"}; | ||
if(typeof params === "function") { | ||
callback = params; | ||
params = null; | ||
params = {}; | ||
} | ||
relax(merge_opts_with_params(opts,params),callback); | ||
relax({db: db_name, doc: doc_name, method: "GET", params: params},callback); | ||
} | ||
@@ -329,8 +322,7 @@ | ||
function list_docs(params,callback) { | ||
var opts = {db: db_name, doc: "_all_docs", method: "GET"}; | ||
if(typeof params === "function") { | ||
callback = params; | ||
params = null; | ||
params = {}; | ||
} | ||
relax(merge_opts_with_params(opts,params),callback); | ||
relax({db: db_name, doc: "_all_docs", method: "GET", params: params},callback); | ||
} | ||
@@ -349,4 +341,31 @@ | ||
relax({db: db_name, doc: "_bulk_docs", body: docs, method: "POST"},callback); | ||
} | ||
} | ||
/************************************************************************** | ||
* attachment * | ||
**************************************************************************/ | ||
/* | ||
* Inserting an attachment | ||
* http://wiki.apache.org/couchdb/HTTP_Document_API | ||
* | ||
* Don't forget that params.rev is required in all cases except when | ||
* creating a new document with a new attachment via this method | ||
* | ||
* @param {doc_name:string} The name of the document | ||
* @param {att_name:string} The name of the attachment | ||
* @param {att:buffer} The attachment data | ||
* @param {content_type:string} The attachment content type | ||
* @param {params:object:optional} Additions to the querystring | ||
* | ||
* @see relax | ||
*/ | ||
function insert_att(doc_name,att_name,att,content_type,params,callback) { | ||
if(typeof params === "function") { | ||
callback = params; | ||
params = {}; | ||
} | ||
relax({ db: db_name, att: att_name, method: "PUT", content_type: content_type | ||
, doc: doc_name, params: params, body: att},callback); | ||
} | ||
public_functions = { info: function(cb) { get_db(db_name,cb); } | ||
@@ -371,7 +390,6 @@ , replicate: function(target,continuous,cb) { | ||
//, views: {} | ||
// , attachment: { insert: insert_att | ||
// , update: update_att | ||
, attachment: { insert: insert_att | ||
// , get: get_att | ||
// , destroy: destroy_att | ||
// } | ||
} | ||
}; | ||
@@ -378,0 +396,0 @@ return public_functions; |
{ "name": "nano" | ||
, "description": "NanoCouch is a minimalistic driver for CouchDB built on mikeals/request" | ||
, "homepage": "http://github.com/dscape/nano" | ||
, "version": "0.3.1" | ||
, "version": "0.3.2" | ||
, "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" } | ||
, "devDependencies": { "async": "~0.1.9", "vows": "~0.5.10" } | ||
@@ -9,0 +8,0 @@ , "main": "./nano.js" |
@@ -30,4 +30,4 @@ # nano | ||
// specify the database we are going to use | ||
var alicedb = nano.use("alice"); | ||
alicedb.insert("rabbit", {crazy: true}, function(e,h,r){ | ||
var alice = nano.use("alice"); | ||
alice.insert("rabbit", {crazy: true}, function(e,h,r){ | ||
if(e) { throw e; } | ||
@@ -41,7 +41,7 @@ console.log("you have inserted the rabbit.") | ||
// 5: var alicedb = nano.use("alice"); | ||
// 5: var alice = nano.use("alice"); | ||
in `nano` a callback has always three arguments | ||
// 6: alicedb.insert("rabbit", {crazy: true}, function(e,h,r){ | ||
// 6: alice.insert("rabbit", {crazy: true}, function(e,h,r){ | ||
// 7: if(e) { throw e; } | ||
@@ -64,2 +64,3 @@ // 8: console.log("you have inserted the rabbit.") | ||
`*` marks optional | ||
`params` are additional querystring parameters | ||
@@ -89,7 +90,8 @@ ### databases (nano) | ||
`db.insert(doc,doc_name*,callback*)` | ||
`db.update(doc_name,rev,doc,callback*)` | ||
`db.destroy(doc_name,rev,callback*)` | ||
`db.get(doc_name,params*,callback*)` | ||
`db.list(params*,callback*)` | ||
`doc.insert(doc,doc_name*,callback*)` | ||
`doc.update(doc_name,rev,doc,callback*)` | ||
`doc.destroy(doc_name,rev,callback*)` | ||
`doc.get(doc_name,params*,callback*)` | ||
`doc.bulk(docs,callback*)` | ||
`doc.list(params*,callback*)` | ||
@@ -100,5 +102,5 @@ #### aliases | ||
`nano.db.get: [db.info(callback*)]` | ||
`nano.db.replicate: [db.replicate(target,continuous*,callback*)]` | ||
`nano.db.compact: [db.compact(callback*)]` | ||
`nano.db.get: [doc.info(callback*)]` | ||
`nano.db.replicate: [doc.replicate(target,continuous*,callback*)]` | ||
`nano.db.compact: [doc.compact(callback*)]` | ||
@@ -121,6 +123,6 @@ ### advanced | ||
this is the same as (assuming `db = nano.use("alice");`): | ||
this is the same as (assuming `alice = nano.use("alice");`): | ||
nano.get("rabbit", {rev: "1-967a00dff5e02add41819138abb3284d"}, | ||
function (_,_,b) { console.log(b) | ||
alice.get("rabbit", {rev: "1-967a00dff5e02add41819138abb3284d"}, | ||
function (_,_,b) { console.log(b) } | ||
); | ||
@@ -132,5 +134,4 @@ | ||
2. explore adding `_changes` feed | ||
3. convenience functions for attachments | ||
4. support views | ||
5. support bulk load | ||
3. `attachments` | ||
4. `views` | ||
@@ -137,0 +138,0 @@ ## contribute |
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
0
170
21253
6
448
- Removedb64@1.0.0
- Removedrequest@>=1.9.8
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedb64@1.0.0(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.10.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)