Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Commit

Permalink
[readme] syntax highlight
Browse files Browse the repository at this point in the history
* added syntax highlighting
* removed applications from tutorials (will be re-factored to the wiki)
* changed `nano` for `server` in the api part to simplify life of people reading this file
  • Loading branch information
dscape committed Sep 9, 2011
1 parent 1f111a5 commit 05b8eb5
Showing 1 changed file with 63 additions and 44 deletions.
107 changes: 63 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,48 @@ a quick example using `nano`

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");
```

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,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: });
```

meaning:

Expand All @@ -54,13 +64,14 @@ meaning:

that's it. don't forget to delete the database you created:

nano.db.destroy("alice");
``` js
nano.db.destroy("alice");
```

# tutorials

* [nano - a minimalistic couchdb client for nodejs](http://writings.nunojob.com/2011/08/nano-minimalistic-couchdb-client-for-nodejs.html)
* [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)

# interfaces

Expand All @@ -71,23 +82,23 @@ that's it. don't forget to delete the database you created:

### functions

`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`

### aliases

`nano.use: [nano.db.use, nano.db.scope, nano.scope]`
`nano.request: [nano.relax, nano.dinosaur]`

## documents, attachments, et al
## documents, attachments, views, et al

### functions

Expand All @@ -114,30 +125,36 @@ that's it. don't forget to delete the database you created:

`nano` is minimalistic so it provides advanced users with a way to code their own extension 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) });
```

### pipe

you can pipe in `nano` just like you do in any other stream. this is available in all methods:

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"));
```

# roadmap

Expand All @@ -158,7 +175,9 @@ everyone is welcome to contribute. patches, bugfixes, new features

*useful tip*: to run a single test and get verbose output you can do

NANO_ENV=testing node tests/doc/list.js list_doc_params
``` sh
NANO_ENV=testing node tests/doc/list.js list_doc_params
```

where `list_doc_params` is the test name.

Expand Down

0 comments on commit 05b8eb5

Please sign in to comment.