Permalink
Browse files

Merge pull request #36 from hsch/master

update to node v6.x
  • Loading branch information...
2 parents 533bd4b + 5feb65c commit a57981d18810d69c39eb71a27236428bd1aa44ff @felixge committed Jan 9, 2012
Showing with 19 additions and 23 deletions.
  1. +4 −4 README.md
  2. +12 −15 lib/couchdb.js
  3. +3 −3 test/common.js
  4. +0 −1 test/test-attachment.js
View
@@ -20,22 +20,22 @@ Installation is simple from [NPM](http://npmjs.org/):
To use the library, create a new file called `my-couch-adventure.js`:
var
- sys = require('util'),
+ util = require('util'),
couchdb = require('felix-couchdb'),
client = couchdb.createClient(5984, 'localhost'),
db = client.db('my-db');
db
.saveDoc('my-doc', {awesome: 'couch fun'}, function(er, ok) {
if (er) throw new Error(JSON.stringify(er));
- sys.puts('Saved my first doc to the couch!');
+ util.puts('Saved my first doc to the couch!');
});
db
.getDoc('my-doc', function(er, doc) {
if (er) throw new Error(JSON.stringify(er));
- sys.puts('Fetched my new doc from couch:');
- sys.p(doc);
+ util.puts('Fetched my new doc from couch:');
+ util.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.
View
@@ -150,12 +150,15 @@ exports.createClient = function(port, host, user, pass, maxListeners) {
options.headers
),
cbFired = false,
- onClose = function(hadError, reason) {
- if (hadError && !cbFired) cb && cb(new Error(reason));
- httpClient.removeListener('close', onClose);
+ onError = function(reason) {
+ if (!cbFired) cb && cb(new Error(reason));
+ },
+ onClose = function() {
+ if (!cbFired) cb && cb();
};
- httpClient.addListener('close', onClose);
+ request.addListener('error', onError);
+ request.addListener('close', onClose);
if (options.data && typeof options.data != 'string') {
options.data = exports.toJSON(options.data);
@@ -596,7 +599,7 @@ Db.prototype.changesStream = function(query, options) {
request = client.request('GET', path, headers),
buffer = '';
- client.setTimeout(options.timeout);
+ request.setTimeout(options.timeout);
request.addListener("response", function(res) {
res.addListener('data', function(chunk) {
buffer += (chunk || '');
@@ -620,20 +623,14 @@ Db.prototype.changesStream = function(query, options) {
stream.emit('data', change);
}
})
+ res.addListener('close', function(hadError) {
+ stream.emit('end', hadError);
+ });
});
request.end();
- client.addListener('close', function(hadError) {
- stream.emit('end', hadError);
- });
-
stream.close = function() {
- if (request.abort) {
- return request.abort();
- }
- else {
- return client.destroy();
- }
+ return request.abort();
};
return stream;
View
@@ -1,6 +1,6 @@
-var sys = require('sys');
-global.p = sys.p;
-global.puts = sys.puts;
+var util = require('util');
+global.p = util.p;
+global.puts = util.puts;
global.couchdb = require('../lib/couchdb');
global.assert = require('assert');
View
@@ -1,7 +1,6 @@
require('./common');
var
- sys = require("sys"),
DB_NAME = 'node-couchdb-test',
callbacks = {

1 comment on commit a57981d

azul commented on a57981d Feb 12, 2012

Could you publish this as a new version so it's easier to use via npm?
Thanks!

Please sign in to comment.