This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
repaired the ability of nano to be able to output DEBUG messages #286
Open
glynnbird
wants to merge
21
commits into
apache:master
Choose a base branch
from
glynnbird:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 04386c1
version bump for dependencies
glynnbird d1c7554
fix mocked tests
glynnbird 45d58bf
modified tests to work with latest dependencies and CouchDB 2.0
glynnbird 225f151
Test with 4.2 (LTS) and 5.5 (Stable)
revington 3a5a758
removed the osx target since it is not supported by travis
revington 4aac563
Update README.md
briandela 93db52d
Add db.info doc.
satazor 118e209
Ensure fetch params is optional, fixes #319.
satazor f757cdd
ct: Test for optional body in db.atomic
cttttt 6b5d723
ct: Allow body to be optional in db.atomic.
cttttt a255f68
ct: Fix mocks.
cttttt 3db2d95
Validate docName parameter to avoid db delete
KangTheTerrible 6be3aec
Update express.js example for nano 6 and express 4
pmanijak cb870b8
modify tests to work mocked and unmocked with CouchDB 2.0 from Docker
glynnbird 939c980
ensure CouchDB 2.0 Docker is stopped after each test run
glynnbird 4e38f22
add reference to server in doc scope
dominicbarnes 29bc803
Nano improvements
glynnbird 32cc15c
Ensure 'qs' is real whenever qs will be manipulated.
idearat a20fb95
Adding replication using the "_replicator" database
carlosduclos e7f532c
Merge remote-tracking branch 'upstream/master'
glynnbird File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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`. | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
||
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs. always great 👍