Comparing version 0.8.5 to 0.8.6
@@ -5,3 +5,3 @@ { "name": "nano" | ||
, "repository": "git://github.com/dscape/nano" | ||
, "version": "0.8.5" | ||
, "version": "0.8.6" | ||
, "author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)" | ||
@@ -8,0 +8,0 @@ , "contributors": ["Thiago Arrais <thiago.arrais@gmail.com> (http://thiagoarrais.com)"] |
109
README.md
@@ -14,9 +14,13 @@ # 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][4] for a example | ||
to use `nano` you have to either provide a) a `json` `configuration object`, b) a `url` string, or c) a `configuration file path` like `cfg/tests.js`. refer to [cfg/couch.example.js][4] for a example | ||
var nano = require('nano')('http://localhost:5984'); | ||
``` js | ||
var nano = require('nano')('http://localhost:5984'); | ||
``` | ||
within the `nano` variable you have various methods you can call. these include tasks like create, delete or list databases: | ||
nano.db.create("alice"); | ||
``` js | ||
nano.db.create("alice"); | ||
``` | ||
@@ -27,24 +31,30 @@ in this function there is not callback. in `nano` the absence of callback means "do this, ignore what happens" | ||
// clean up the database we created previously | ||
nano.db.destroy("alice", function(err,response,headers) { | ||
nano.db.create("alice", function(){ | ||
// specify the database we are going to use | ||
var alice = nano.use("alice"); | ||
alice.insert({crazy: true}, "rabbit", function(e,r,h){ | ||
if(e) { throw e; } | ||
console.log("you have inserted the rabbit.") | ||
}); | ||
}); | ||
``` js | ||
// clean up the database we created previously | ||
nano.db.destroy("alice", function(err,response,headers) { | ||
nano.db.create("alice", function() { | ||
// specify the database we are going to use | ||
var alice = nano.use("alice"); | ||
alice.insert({crazy: true}, "rabbit", function(e,r,h){ | ||
if(e) { throw e; } | ||
console.log("you have inserted the rabbit.") | ||
}); | ||
}); | ||
}); | ||
``` | ||
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 | ||
// 5: var alice = nano.use("alice"); | ||
``` js | ||
// 5: var alice = nano.use("alice"); | ||
``` | ||
in `nano` a callback has always three arguments | ||
// 6: alice.insert({crazy: true}, "rabbit", function(e,r,h){ | ||
// 7: if(e) { throw e; } | ||
// 8: console.log("you have inserted the rabbit.") | ||
// 9: }); | ||
``` js | ||
// 6: alice.insert({crazy: true}, "rabbit", function(e,r,h) { | ||
// 7: if(e) { throw e; } | ||
// 8: console.log("you have inserted the rabbit.") | ||
// 9: }); | ||
``` | ||
@@ -59,3 +69,5 @@ meaning: | ||
nano.db.destroy("alice"); | ||
``` js | ||
nano.db.destroy("alice"); | ||
``` | ||
@@ -66,3 +78,2 @@ # tutorials | ||
* [getting started with node.js and couchdb](http://writings.nunojob.com/2011/09/getting-started-with-nodejs-and-couchdb.html) | ||
* [sample coffee script application](https://github.com/thiagoarrais/imagenie) | ||
@@ -78,12 +89,12 @@ # interfaces | ||
`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,design_name*,callback*)` | ||
`nano.db.replicate(source,target,continuous*,callback*)` | ||
`nano.db.changes(db_name,params*,callback*)` | ||
`nano.use(db_name)` | ||
`nano.request(opts,callback*)` | ||
`nano.config` | ||
`server.db.create(db_name,callback*)` | ||
`server.db.get(db_name,callback*)` | ||
`server.db.destroy(db_name,callback*)` | ||
`server.db.list(callback*)` | ||
`server.db.compact(db_name,design_name*,callback*)` | ||
`server.db.replicate(source,target,continuous*,callback*)` | ||
`server.db.changes(db_name,params*,callback*)` | ||
`server.use(db_name)` | ||
`server.request(opts,callback*)` | ||
`server.config` | ||
@@ -95,3 +106,3 @@ ### aliases | ||
## documents, attachments, et al | ||
## documents, attachments, views, et al | ||
@@ -123,19 +134,23 @@ ### functions | ||
nano.request(opts,callback*) | ||
``` js | ||
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) } | ||
); | ||
``` js | ||
nano.request( { db: "alice" | ||
, doc: "rabbit" | ||
, method: "GET" | ||
, params: { rev: "1-967a00dff5e02add41819138abb3284d"} | ||
}, | ||
function (_,b) { console.log(b) }); | ||
``` | ||
this is the same as (assuming `alice = require('nano')('http://localhost:5984/alice')`): | ||
alice.get("rabbit", {rev: "1-967a00dff5e02add41819138abb3284d"}, | ||
function (_,b) { console.log(b) } | ||
); | ||
``` js | ||
alice.get("rabbit", {rev: "1-967a00dff5e02add41819138abb3284d"}, | ||
function (_,b) { console.log(b) }); | ||
``` | ||
@@ -146,4 +161,6 @@ ### pipe | ||
alice.attachment.get("breakfast", "sugar", {rev: rev}) | ||
.pipe(fs.createWriteStream("/tmp/sugar-for-rabbit")); | ||
``` js | ||
alice.attachment.get("breakfast", "sugar", {rev: rev}) | ||
.pipe(fs.createWriteStream("/tmp/sugar-for-rabbit")); | ||
``` | ||
@@ -169,3 +186,5 @@ # roadmap | ||
NANO_ENV=testing node tests/doc/list.js list_doc_params | ||
``` sh | ||
NANO_ENV=testing node tests/doc/list.js list_doc_params | ||
``` | ||
@@ -172,0 +191,0 @@ where `list_doc_params` is the test name. |
@@ -16,6 +16,6 @@ var ensure = require('ensure') | ||
function(e,b) { | ||
if(e) { callback(e); } | ||
if(e) { callback(e); nano.db.destroy(db_name("a")); } | ||
db("a").attachment.insert("new", "att", buffer, "image/bmp", {rev: b.rev}, | ||
function (e2,b2) { | ||
if(e2) { callback(e2); } | ||
if(e2) { callback(e2); nano.db.destroy(db_name("a")); } | ||
db("a").attachment.get("new", "att", {rev: b2.rev}, callback); | ||
@@ -28,4 +28,4 @@ }); | ||
tests.att_get_ok = function (e,b) { | ||
nano.db.destroy(db_name("a")); | ||
assert.isNull(e); | ||
nano.db.destroy(db_name("a")); | ||
var from_buffer = new Buffer(b, "binary").toString("base64"); | ||
@@ -32,0 +32,0 @@ assert.equal(from_buffer, pixel); |
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
51940
211