Skip to content

Commit

Permalink
Docs for: toJSON, toQuery, toAttachment
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Feb 5, 2010
1 parent d7d3d46 commit bd7d0e4
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,47 @@ To use the library, create a new file called `my-couch-adventure.js`:
sys.p(doc);
});

If you are wondering if there is a race-condition in the above example, the answer is no. Each `couchdb.Client` uses an internal queue for its requests, just like `http.Client`. This guarantees ordering. If you want to perform multiple requests at once, use multiple `couchdb.Client` instances.

## API Documentation

### couchdb.toJSON(data)

Identical to `JSON.stringify()`, except that function value will be converted to strings like this:

couchdb.toJSON({
foo: 'bar',
fn: function(a, b) {
p(a, b);
}
})
// => {"foo":"bar","fn":"function (a, b) {\n p(a, b);\n }"}

node-couchdb uses this function everywhere for JSON serialization, this makes it convenient to embed functions.

### couchdb.toQuery(query)

Identical to `querystring.stringify()`, except that boolean values will be converted to `"true"` / `"false"` strings like this:

couchdb.toQuery({
include_docs: true
})
// => include_docs=true

node-couchdb uses this function everywhere for query serialization, this helps since couchdb expects boolean values in this format.

### couchdb.toAttachment(file)

Takes the path of a `file` and creates an JS object suitable for inline document attachment out of it:

couchdb
.toAttachment(__filename)
.addCallback(function(r) {
// r => {"content_type":"text/javascript","data":"dmFyCiAgs...="}
});

Check `dep/mime.js` for a list of recognized file types.

## Todo

* Authentication
Expand Down

0 comments on commit bd7d0e4

Please sign in to comment.