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

repaired the ability of nano to be able to output DEBUG messages #286

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5dbfaa6
repaired the ability of nano to be able to log its messages when a us…
glynnbird Jun 25, 2015
04386c1
version bump for dependencies
glynnbird Oct 26, 2016
d1c7554
fix mocked tests
glynnbird Oct 26, 2016
45d58bf
modified tests to work with latest dependencies and CouchDB 2.0
glynnbird Oct 26, 2016
225f151
Test with 4.2 (LTS) and 5.5 (Stable)
revington Jan 25, 2016
3a5a758
removed the osx target since it is not supported by travis
revington Jan 28, 2016
4aac563
Update README.md
briandela Feb 9, 2016
93db52d
Add db.info doc.
satazor Feb 26, 2016
118e209
Ensure fetch params is optional, fixes #319.
satazor Mar 26, 2016
f757cdd
ct: Test for optional body in db.atomic
cttttt Apr 23, 2016
6b5d723
ct: Allow body to be optional in db.atomic.
cttttt Apr 23, 2016
a255f68
ct: Fix mocks.
cttttt Apr 23, 2016
3db2d95
Validate docName parameter to avoid db delete
KangTheTerrible Apr 25, 2016
6be3aec
Update express.js example for nano 6 and express 4
pmanijak May 9, 2016
cb870b8
modify tests to work mocked and unmocked with CouchDB 2.0 from Docker
glynnbird Oct 26, 2016
939c980
ensure CouchDB 2.0 Docker is stopped after each test run
glynnbird Oct 27, 2016
4e38f22
add reference to server in doc scope
dominicbarnes Jan 10, 2017
29bc803
Nano improvements
glynnbird Nov 3, 2016
32cc15c
Ensure 'qs' is real whenever qs will be manipulated.
idearat Feb 11, 2017
a20fb95
Adding replication using the "_replicator" database
carlosduclos Feb 2, 2017
e7f532c
Merge remote-tracking branch 'upstream/master'
glynnbird Mar 28, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ branches:
- next
- rewrite
node_js:
- "0.8"
- "0.10"
- "0.11"
- "0.12"
- "iojs"
- "4.2"
- "node"
services:
- couchdb
- docker
os:
- linux
- osx
before_script:
- ./scripts/run_couchdb_on_travis.sh
before_install:
- npm update -g npm
109 changes: 107 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ minimalistic couchdb driver for node.js
- [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.replication.enable(source, target, [opts], [callback])](#nanodbreplicatorenablesource-target-opts-callback)
- [nano.db.replication.query(id, [opts], [callback])](#nanodbreplicatorquery-id-opts-callback)
- [nano.db.replication.disable(id, [opts], [callback])](#nanodbreplicatordisable-id-opts-callback)
- [nano.db.changes(name, [params], [callback])](#nanodbchangesname-params-callback)
- [nano.db.follow(name, [params], [callback])](#nanodbfollowname-params-callback)
- [nano.db.info([callback])](#nanodbinfocallback)
- [nano.use(name)](#nanousename)
- [nano.request(opts, [callback])](#nanorequestopts-callback)
- [nano.config](#nanoconfig)
Expand Down Expand Up @@ -60,6 +64,7 @@ minimalistic couchdb driver for node.js
- [db.search(designname, viewname, [params], [callback])](#dbsearchdesignname-searchname-params-callback)
- [using cookie authentication](#using-cookie-authentication)
- [advanced features](#advanced-features)
- [getting uuids](#getting-uuids)
- [extending nano](#extending-nano)
- [pipes](#pipes)
- [tests](#tests)
Expand Down Expand Up @@ -272,6 +277,55 @@ nano.db.replicate('alice', 'http://admin:[email protected]:5984/alice',
});
```

### nano.db.replication.enable(source, target, [opts], [callback])

enables replication using the new couchdb api from `source` to `target`
with options `opts`. `target` has to exist, add `create_target:true` to
`opts` to create it prior to replication.
replication will survive server restarts.

``` js
nano.db.replication.enable('alice', 'http://admin:[email protected]:5984/alice',
{ create_target:true }, function(err, body) {
if (!err)
console.log(body);
});
```

### nano.db.replication.query(id, [opts], [callback])

queries the state of replication using the new couchdb api. `id` comes from the response
given by the call to enable.

``` js
nano.db.replication.enable('alice', 'http://admin:[email protected]:5984/alice',
{ create_target:true }, function(err, body) {
if (!err) {
nano.db.replication.query(body.id, function(error, reply) {
if (!err)
console.log(reply);
}
}
});
```

### nano.db.replication.disable(id, [opts], [callback])

disables replication using the new couchdb api. `id` comes from the response given
by the call to enable.

``` js
nano.db.replication.enable('alice', 'http://admin:[email protected]:5984/alice',
{ create_target:true }, function(err, body) {
if (!err) {
nano.db.replication.disable(body.id, function(error, reply) {
if (!err)
console.log(reply);
}
}
});
```

### nano.db.changes(name, [params], [callback])

asks for the changes feed of `name`, `params` contains additions
Expand Down Expand Up @@ -300,6 +354,16 @@ process.nextTick(function () {
});
```

### nano.db.info([callback])

gets database information.

nano.db.info(function(err, body) {
if (!err) {
console.log('got database info'', body);
}
});

### nano.use(name)

creates a scope where you operate inside `name`.
Expand Down Expand Up @@ -411,7 +475,7 @@ alice.insert({ crazy: true }, 'rabbit', function(err, body) {
The `insert` function can also be used with the method signature `db.insert(doc,[callback])`, where the `doc` contains the `_id` field e.g.

~~~ js
var alice = cloudant.use('alice')
var alice = nano.use('alice')
alice.insert({ _id: 'myid', crazy: true }, function(err, body) {
if (!err)
console.log(body)
Expand All @@ -421,7 +485,7 @@ alice.insert({ _id: 'myid', crazy: true }, function(err, body) {
and also used to update an existing document, by including the `_rev` token in the document being saved:

~~~ js
var alice = cloudant.use('alice')
var alice = nano.use('alice')
alice.insert({ _id: 'myid', _rev: '1-23202479633c2b380f79507a776743d5', crazy: false }, function(err, body) {
if (!err)
console.log(body)
Expand Down Expand Up @@ -765,6 +829,21 @@ nano.session(function(err, session) {

## advanced features

### getting uuids

if your application needs to generate UUIDs, then CouchDB can provide some for you

```js
nano.uuids(3, callback);
// { uuid: [
// '5d1b3ef2bc7eea51f660c091e3dffa23',
// '5d1b3ef2bc7eea51f660c091e3e006ff',
// '5d1b3ef2bc7eea51f660c091e3e007f0',
//]}
```

The first parameter is the number of uuids to generate. If omitted, it defaults to 1.

### extending nano

nano is minimalistic but you can add your own features with
Expand Down Expand Up @@ -804,6 +883,32 @@ alice.attachment.get('rabbit', 'picture.png').pipe(fs.createWriteStream('/tmp/ra

then open `/tmp/rabbit.png` and you will see the rabbit picture.

### debugging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs. always great 👍


debugging messages can be enabled in Nano by


#### setting the DEBUG environment variable

Either in the shell

export DEBUG=nano
# then run your Node.js script

or on the same line as you execute your Node.js script:

DEBUG=nano node myscript.js

#### providing your own debugging function

when initialising Nano, pass in a `log` function:

``` js
nano = require('nano')({ url: 'http://127.0.0.1:5984/', log: function(d) { console.log("!!!",d)}} );
```

* setting an environment variable `DEBUG` with value of 'nano'
* or, providing

## tutorials, examples in the wild & screencasts

Expand Down
19 changes: 11 additions & 8 deletions examples/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@

var express = require('express')
, db = require('nano')('http://localhost:5984/my_couch')
, app = module.exports = express.createServer()
, app = module.exports = express()
;

app.get('/', function(request,response) {
db.get('foo', function (error, body, headers) {
if(error) { return response.send(error.message, error['status-code']); }
response.send(body, 200);
});
});
app.get('/', function(req, res) {
db.get('foo', function (error, body, headers) {
if(error) {
res.status(error.statusCode);
return res.send(error.message);
}
res.status(200);
res.send(body);
});
});

app.listen(3333);
console.log('server is running. check expressjs.org for more cool tricks');
console.log('server is running. check expressjs.com for more cool tricks');
18 changes: 6 additions & 12 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@
// the License.

'use strict';
var prefix = 'nano';
var debug = require('debug')(prefix);

var debug = require('debug')('nano/logger');

module.exports = function logging(cfg) {
var log = cfg && cfg.log;
var logStrategy = typeof log === 'function' ? log : debug;

return function logEvent(prefix) {
var eventId = (prefix ? prefix + '-' : '') +
(~~(Math.random() * 1e9)).toString(36);
return function log() {
logStrategy.call(this, eventId, [].slice.call(arguments, 0));
};
module.exports = function logging() {
return function log() {
var eventId = prefix + (~~(Math.random() * 1e9)).toString(36);
debug.call(this, eventId, [].slice.call(arguments, 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the pull request. however i'm confused by this.

the log function is normally used to log, and during development can be overridden by debug. seems like this just makes it be a debug message all the time no?

};
};
Loading