[![By](https://img.shields.io/badge/made%20by-yld!-32bbee.svg?style=flat-square)](http://yld.io/contact?source=github-nano)[![Chat](https://img.shields.io/badge/help-gitter-eb9348.svg?style=flat-square)](https://gitter.im/dscape/nano)[![Tests](http://img.shields.io/travis/dscape/nano.svg?style=flat-square)](https://travis-ci.org/dscape/nano)![Coverage](https://img.shields.io/badge/coverage-100%-ff69b4.svg?style=flat-square)[![Dependencies](https://img.shields.io/david/dscape/nano.svg?style=flat-square)](https://david-dm.org/dscape/nano)[![NPM](http://img.shields.io/npm/v/nano.svg?style=flat-square)](http://browsenpm.org/package/nano)
# nano
minimalistic couchdb driver for node.js
`nano` features:
* **minimalistic** - there is only a minimum of abstraction between you and
couchdb
* **pipes** - proxy requests from couchdb directly to your end user
* **errors** - errors are proxied directly from couchdb: if you know couchdb
you already know `nano`.
## installation
1. install [npm][1]
2. `npm install nano`
## table of contents
- [getting started](#getting-started)
- [tutorials & screencasts](#tutorials-examples-in-the-wild--screencasts)
- [configuration](#configuration)
- [database functions](#database-functions)
- [nano.db.create(name, [callback])](#nanodbcreatename-callback)
- [nano.db.get(name, [callback])](#nanodbgetname-callback)
- [nano.db.destroy(name, [callback])](#nanodbdestroyname-callback)
- [nano.db.list([callback])](#nanodblistcallback)
- [nano.db.compact(name, [designname], [callback])](#nanodbcompactname-designname-callback)
- [nano.db.replicate(source, target, [opts], [callback])](#nanodbreplicatesource-target-opts-callback)
- [nano.db.changes(name, [params], [callback])](#nanodbchangesname-params-callback)
- [nano.db.follow(name, [params], [callback])](#nanodbfollowname-params-callback)
- [nano.use(name)](#nanousename)
- [nano.request(opts, [callback])](#nanorequestopts-callback)
- [nano.config](#nanoconfig)
- [nano.updates([params], [callback])](#nanoupdatesparams-callback)
- [nano.followUpdates([params], [callback])](#nanofollowupdatesparams-callback)
- [document functions](#document-functions)
- [db.insert(doc, [params], [callback])](#dbinsertdoc-params-callback)
- [db.destroy(docname, rev, [callback])](#dbdestroydocname-rev-callback)
- [db.get(docname, [params], [callback])](#dbgetdocname-params-callback)
- [db.head(docname, [callback])](#dbheaddocname-callback)
- [db.copy(src_doc, dest_doc, opts, [callback])](#dbcopysrc_doc-dest_doc-opts-callback)
- [db.bulk(docs, [params], [callback])](#dbbulkdocs-params-callback)
- [db.list([params], [callback])](#dblistparams-callback)
- [db.fetch(docnames, [params], [callback])](#dbfetchdocnames-params-callback)
- [db.fetchRevs(docnames, [params], [callback])](#dbfetchRevsdocnames-params-callback)
- [multipart functions](#multipart-functions)
- [db.multipart.insert(doc, attachments, [params], [callback])](#dbmultipartinsertdoc-attachments-params-callback)
- [db.multipart.get(docname, [params], [callback])](#dbmultipartgetdocname-params-callback)
- [attachments functions](#attachments-functions)
- [db.attachment.insert(docname, attname, att, contenttype, [params], [callback])](#dbattachmentinsertdocname-attname-att-contenttype-params-callback)
- [db.attachment.get(docname, attname, [params], [callback])](#dbattachmentgetdocname-attname-params-callback)
- [db.attachment.destroy(docname, attname, [params], [callback])](#dbattachmentdestroydocname-attname-rev-callback)
- [views and design functions](#views-and-design-functions)
- [db.view(designname, viewname, [params], [callback])](#dbviewdesignname-viewname-params-callback)
- [db.show(designname, showname, doc_id, [params], [callback])](#dbshowdesignname-showname-doc_id-params-callback)
- [db.atomic(designname, updatename, docname, [body], [callback])](#dbatomicdesignname-updatename-docname-body-callback)
- [db.search(designname, viewname, [params], [callback])](#dbsearchdesignname-searchname-params-callback)
- [using cookie authentication](#using-cookie-authentication)
- [advanced features](#advanced-features)
- [extending nano](#extending-nano)
- [pipes](#pipes)
- [tests](#tests)
## getting started
to use `nano` you need to connect it to your couchdb install, to do that:
``` js
var nano = require('nano')('http://localhost:5984');
```
to create a new database:
``` js
nano.db.create('alice');
```
and to use it:
``` js
var alice = nano.db.use('alice');
```
in this examples we didn't specify a `callback` function, the absence of a
callback means _"do this, ignore what happens"_.
in `nano` the callback function receives always three arguments:
* `err` - the error, if any
* `body` - the http _response body_ from couchdb, if no error.
json parsed body, binary for non json responses
* `header` - the http _response header_ from couchdb, if no error
a simple but complete example using callbacks is:
``` js
var nano = require('nano')('http://localhost:5984');
// clean up the database we created previously
nano.db.destroy('alice', function() {
// create a new database
nano.db.create('alice', function() {
// specify the database we are going to use
var alice = nano.use('alice');
// and insert a document in it
alice.insert({ crazy: true }, 'rabbit', function(err, body, header) {
if (err) {
console.log('[alice.insert] ', err.message);
return;
}
console.log('you have inserted the rabbit.')
console.log(body);
});
});
});
```
if you run this example(after starting couchdb) you will see:
you have inserted the rabbit.
{ ok: true,
id: 'rabbit',
rev: '1-6e4cb465d49c0368ac3946506d26335d' }
you can also see your document in [futon](http://localhost:5984/_utils).
## configuration
configuring nano to use your database server is as simple as:
``` js
var nano = require('nano')('http://localhost:5984')
, db = nano.use('foo')
;
```
however if you don't need to instrument database objects you can simply:
``` js
// nano parses the url and knows this is a database
var db = require('nano')('http://localhost:5984/foo');
```
you can also pass options to the require:
``` js
// nano parses the url and knows this is a database
var db = require('nano')('http://localhost:5984/foo');
```
to specify further configuration options you can pass an object literal instead:
``` js
// nano parses the url and knows this is a database
var db = require('nano')(
{ "url" : "http://localhost:5984/foo"
, "requestDefaults" : { "proxy" : "http://someproxy" }
, "log" : function (id, args) {
console.log(id, args);
}
});
```
Please check [request] for more information on the defaults. They support features like cookie jar, proxies, ssl, etc.
You can tell nano to not parse the url (maybe the server is behind a proxy, is accessed through a rewrite rule or other):
```js
// nano does not parse the url and return the server api
// "http://localhost:5984/prefix" is the CouchDB server root
var couch = require('nano')(
{ "url" : "http://localhost:5984/prefix"
"parseUrl" : false
});
var db = couch.use('foo');
```
### pool size and open sockets
a very important configuration parameter if you have a high traffic website and are using nano is setting up the `pool.size`. by default, the node.js http global agent (client) has a certain size of active connections that can run simultaneously, while others are kept in a queue. pooling can be disabled by setting the `agent` property in `requestDefaults` to false, or adjust the global pool size using:
``` js
http.globalAgent.maxSockets = 20;
```
you can also increase the size in your calling context using `requestDefaults` if this is problematic. refer to the [request] documentation and examples for further clarification.
here's an example explicitly using the keep alive agent (installed using `npm install agentkeepa
没有合适的资源?快使用搜索试试~ 我知道了~
Node.js-Nano是一个简约CouchDB客户端
共123个文件
js:74个
json:40个
md:5个
需积分: 9 2 下载量 21 浏览量
2019-08-10
03:58:29
上传
评论
收藏 108KB ZIP 举报
温馨提示
Nano是一个简约CouchDB客户端
资源推荐
资源详情
资源评论
收起资源包目录
Node.js-Nano是一个简约CouchDB客户端 (123个子文件)
.gitignore 47B
nano.js 19KB
integration.js 5KB
lazy_creation_of_views.js 4KB
config.js 4KB
unit.js 4KB
show.js 3KB
insert.js 3KB
replicate.js 2KB
insert.js 2KB
cookie.js 2KB
lazy_db_creation_and_replication.js 2KB
atomic.js 2KB
copy.js 2KB
compact.js 2KB
fetch_revs.js 2KB
compact.js 2KB
pipe.js 2KB
list.js 2KB
get.js 2KB
error.js 2KB
updates.js 2KB
update.js 2KB
fetch.js 2KB
get.js 2KB
search.js 2KB
headers.js 2KB
multiple.js 2KB
follow.js 2KB
error.js 2KB
destroy.js 2KB
bulk_transform.js 1KB
create-and-destroy.js 1KB
get.js 1KB
query.js 1KB
index.js 1KB
insert.js 1KB
update.js 1KB
destroy.js 1KB
bulk.js 1KB
bulk.js 1KB
list.js 1KB
replicate.js 1KB
insert.js 1KB
get.js 1KB
changes.js 1KB
list.js 1KB
insert.js 1KB
jar.js 1KB
head.js 1KB
copy.js 1KB
express.js 1KB
changes.js 1016B
log.js 1003B
list.js 993B
updates.js 990B
logger.js 989B
get.js 980B
create.js 978B
view.js 966B
atomic.js 943B
destroy.js 899B
search.js 885B
nano.js 881B
pipe.js 870B
spatial.js 863B
show.js 862B
get.js 848B
compact.js 820B
compact.js 819B
destroy.js 813B
get.js 800B
list.js 799B
follow-updates.js 757B
follow.js 698B
.jshintrc 230B
replicate.json 3KB
fetch.json 2KB
fetch_revs.json 2KB
search.json 2KB
query.json 2KB
list.json 2KB
multiple.json 2KB
insert.json 2KB
insert.json 1KB
show.json 1KB
package.json 1KB
get.json 1KB
update.json 1KB
cookie.json 1KB
copy.json 1KB
atomic.json 1KB
compact.json 1KB
list.json 1KB
changes.json 1KB
compact.json 1KB
pipe.json 896B
follow.json 847B
get.json 841B
destroy.json 826B
共 123 条
- 1
- 2
资源评论
weixin_39841848
- 粉丝: 509
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- base.apk
- Vue 结合 D3.js 进行数据可视化开发的练手案例.zip
- 语音模块使用说明_jr6001调试工具.html
- 毕业设计-reat18货物运输后台管理系统
- Qt tcp通信(exe)
- tensorflow-gpu-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.8.0-cp37-cp37m-manylinux2010-x86-64.whl
- tensorflow-2.7.4-cp39-cp39-manylinux2010-x86-64.whl
- HTML后台管理系统源49套合集 H5模板源码下载 总有一款适合你 静态页面
- DDColor-PDF文献
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功