Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- 0.8
- 0.9
before_script:
- node script/create-test-tables.js pg://postgres@127.0.0.1:5432/postgres
14 changes: 14 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var Connection = require(__dirname + '/connection');
var CopyFromStream = require(__dirname + '/copystream').CopyFromStream;
var CopyToStream = require(__dirname + '/copystream').CopyToStream;

var deprecate = require('deprecate');

var Client = function(config) {
EventEmitter.call(this);

Expand Down Expand Up @@ -256,11 +258,23 @@ Client.prototype.query = function(config, values, callback) {
//prevents client from otherwise emitting 'drain' event until 'resumeDrain' is
//called
Client.prototype.pauseDrain = function() {
deprecate('Client.prototype.pauseDrain is deprecated and will be removed it v1.0.0 (very soon)',
'please see the following for more details:',
'https://github.com/brianc/node-postgres/wiki/pg',
'https://github.com/brianc/node-postgres/issues/227',
'https://github.com/brianc/node-postgres/pull/274',
'feel free to get in touch via github if you have questions');
this._drainPaused = 1;
};

//resume raising 'drain' event
Client.prototype.resumeDrain = function() {
deprecate('Client.prototype.resumeDrain is deprecated and will be removed it v1.0.0 (very soon)',
'please see the following for more details:',
'https://github.com/brianc/node-postgres/wiki/pg',
'https://github.com/brianc/node-postgres/issues/227',
'https://github.com/brianc/node-postgres/pull/274',
'feel free to get in touch via github if you have questions');
if(this._drainPaused > 1) {
this.emit('drain');
}
Expand Down
9 changes: 9 additions & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ module.exports = {
//pool log function / boolean
poolLog: false
};

var deprecate = require('deprecate');
//getter/setter to disable deprecation warnings
module.exports.__defineGetter__("hideDeprecationWarnings", function() {
return deprecate.silent;
});
module.exports.__defineSetter__("hideDeprecationWarnings", function(val) {
deprecate.silence = val;
});
25 changes: 25 additions & 0 deletions lib/deprecate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var os = require('os');
var defaults = require(__dirname + '/defaults');

var hits = {
};
var deprecate = module.exports = function(methodName, message) {
if(defaults.hideDeprecationWarnings) return;
if(hits[deprecate.caller]) return;
hits[deprecate.caller] = true;
process.stderr.write(os.EOL);
process.stderr.write('\x1b[31;1m');
process.stderr.write('WARNING!!');
process.stderr.write(os.EOL);
process.stderr.write(methodName);
process.stderr.write(os.EOL);
for(var i = 1; i < arguments.length; i++) {
process.stderr.write(arguments[i]);
process.stderr.write(os.EOL);
}
process.stderr.write('\x1b[0m');
process.stderr.write(os.EOL);
process.stderr.write("You can silence these warnings with `require('pg').defaults.hideDeprecationWarnings = true`");
process.stderr.write(os.EOL);
process.stderr.write(os.EOL);
};
10 changes: 10 additions & 0 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var EventEmitter = require('events').EventEmitter;
var defaults = require(__dirname + '/defaults');
var genericPool = require('generic-pool');

var deprecate = require('deprecate');

var pools = {
//dictionary of all key:pool pairs
all: {},
Expand Down Expand Up @@ -77,6 +79,14 @@ var errorMessage = [
].join(require('os').EOL);

var oldConnect = function(pool, client, cb) {
deprecate('pg.connect(function(err, client) { ...}) is deprecated and will be removed it v1.0.0 (very soon)',
'instead, use pg.connect(function(err, client, done) { ... })',
'automatic releasing of clients back to the pool was a mistake and will be removed',
'please see the following for more details:',
'https://github.com/brianc/node-postgres/wiki/pg',
'https://github.com/brianc/node-postgres/issues/227',
'https://github.com/brianc/node-postgres/pull/274',
'feel free to get in touch via github if you have questions');
var tid = setTimeout(function() {
console.error(errorMessage);
}, alarmDuration);
Expand Down
8 changes: 8 additions & 0 deletions lib/types/binaryParsers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var deprecate = require('deprecate');

var parseBits = function(data, bits, offset, invert, callback) {
offset = offset || 0;
invert = invert || false;
Expand Down Expand Up @@ -45,6 +47,12 @@ var parseBits = function(data, bits, offset, invert, callback) {
};

var parseFloatFromBits = function(data, precisionBits, exponentBits) {
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
'JavaScript has a hard time with floats and there is precision loss which can cause',
'unexpected, hard to trace, potentially bad bugs in your program',
'for more information see the following:',
'https://github.com/brianc/node-postgres/pull/271',
'in node-postgres v1.0.0 all floats & decimals will be returned as strings');
var bias = Math.pow(2, exponentBits - 1) - 1;
var sign = parseBits(data, 1);
var exponent = parseBits(data, exponentBits, 1);
Expand Down
32 changes: 22 additions & 10 deletions lib/types/textParsers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var deprecate = require('deprecate');

var arrayParser = require(__dirname + "/arrayParser.js");

//parses PostgreSQL server formatted date strings into javascript date objects
Expand Down Expand Up @@ -76,6 +78,13 @@ var parseIntegerArray = function(val) {
};

var parseFloatArray = function(val) {
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
'JavaScript has a hard time with floats and there is precision loss which can cause',
'unexpected, hard to trace, potentially bad bugs in your program',
'for more information see the following:',
'https://github.com/brianc/node-postgres/pull/271',
'in node-postgres v1.0.0 all floats & decimals will be returned as strings',
'feel free to get in touch via a github issue if you have any questions');
if(!val) { return null; }
var p = arrayParser.create(val, function(entry){
if(entry !== null) {
Expand Down Expand Up @@ -162,24 +171,27 @@ var parseInteger = function(val) {
return parseInt(val, 10);
};

var parseFloatAndWarn = function(val) {
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
'JavaScript has a hard time with floats and there is precision loss which can cause',
'unexpected, hard to trace, potentially bad bugs in your program',
'for more information see the following:',
'https://github.com/brianc/node-postgres/pull/271',
'in node-postgres v1.0.0 all floats & decimals will be returned as strings');
return parseFloat(val);
};

var init = function(register) {
register(20, parseInteger);
register(21, parseInteger);
register(23, parseInteger);
register(26, parseInteger);
//TODO remove for v1.0
register(1700, function(val){
if(val.length > maxLen) {
console.warn(
'WARNING: value %s is longer than max supported numeric value in ' +
'javascript. Possible data loss', val);
}
return parseFloat(val);
});
register(1700, parseFloatAndWarn);
//TODO remove for v1.0
register(700, parseFloat);
register(700, parseFloatAndWarn);
//TODO remove for v1.0
register(701, parseFloat);
register(701, parseFloatAndWarn);
register(16, parseBool);
register(1082, parseDate); // date
register(1114, parseDate); // timestamp without timezone
Expand Down
41 changes: 26 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
{ "name": "pg",
{
"name": "pg",
"version": "0.13.3",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords" : ["postgres", "pg", "libpq", "postgre", "database", "rdbms"],
"keywords": [
"postgres",
"pg",
"libpq",
"postgre",
"database",
"rdbms"
],
"homepage": "http://github.com/brianc/node-postgres",
"repository" : {
"type" : "git",
"url" : "git://github.com/brianc/node-postgres.git"
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git"
},
"author" : "Brian Carlson <brian.m.carlson@gmail.com>",
"main" : "./lib",
"dependencies" : {
"generic-pool" : "2.0.2"
"author": "Brian Carlson <brian.m.carlson@gmail.com>",
"main": "./lib",
"dependencies": {
"generic-pool": "2.0.2",
"deprecate": "~0.1.0"
},
"devDependencies" : {
"jshint" : "git://github.com/jshint/jshint.git"
"devDependencies": {
"jshint": "git://github.com/jshint/jshint.git"
},
"scripts" : {
"test" : "make test-all connectionString=pg://postgres@localhost:5432/postgres",
"scripts": {
"test": "make test-all connectionString=pg://postgres@localhost:5432/postgres",
"prepublish": "rm -r build || (exit 0)",
"install" : "node-gyp rebuild || (exit 0)"
"install": "node-gyp rebuild || (exit 0)"
},
"engines" : { "node": ">= 0.8.0" }
"engines": {
"node": ">= 0.8.0"
}
}
34 changes: 26 additions & 8 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,17 @@ class Connection : public ObjectWrap {
bool ioInitialized_;
bool copyOutMode_;
bool copyInMode_;
bool reading_;
bool writing_;
Connection () : ObjectWrap ()
{
connection_ = NULL;
connecting_ = false;
ioInitialized_ = false;
copyOutMode_ = false;
copyInMode_ = false;
reading_ = false;
writing_ = false;
TRACE("Initializing ev watchers");
read_watcher_.data = this;
write_watcher_.data = this;
Expand Down Expand Up @@ -304,20 +308,23 @@ class Connection : public ObjectWrap {

int Send(const char *queryText)
{
TRACE("js::Send")
int rv = PQsendQuery(connection_, queryText);
StartWrite();
return rv;
}

int SendQueryParams(const char *command, const int nParams, const char * const *paramValues)
{
TRACE("js::SendQueryParams")
int rv = PQsendQueryParams(connection_, command, nParams, NULL, paramValues, NULL, NULL, 0);
StartWrite();
return rv;
}

int SendPrepare(const char *name, const char *command, const int nParams)
{
TRACE("js::SendPrepare")
int rv = PQsendPrepare(connection_, name, command, nParams, NULL);
StartWrite();
return rv;
Expand Down Expand Up @@ -430,7 +437,7 @@ class Connection : public ObjectWrap {
if(PQconsumeInput(connection_) == 0) {
End();
EmitLastError();
LOG("Something happened, consume input is 0");
//LOG("Something happened, consume input is 0");
return;
}

Expand Down Expand Up @@ -476,7 +483,8 @@ class Connection : public ObjectWrap {
if(revents & UV_WRITABLE) {
TRACE("revents & UV_WRITABLE");
if (PQflush(connection_) == 0) {
StopWrite();
//nothing left to write, poll the socket for more to read
StartRead();
}
}
}
Expand Down Expand Up @@ -669,12 +677,10 @@ class Connection : public ObjectWrap {
switch(status) {
case PGRES_POLLING_READING:
TRACE("Polled: PGRES_POLLING_READING");
StopWrite();
StartRead();
break;
case PGRES_POLLING_WRITING:
TRACE("Polled: PGRES_POLLING_WRITING");
StopRead();
StartWrite();
break;
case PGRES_POLLING_FAILED:
Expand Down Expand Up @@ -712,30 +718,42 @@ class Connection : public ObjectWrap {

void StopWrite()
{
TRACE("Stoping write watcher");
TRACE("write STOP");
if(ioInitialized_) {
uv_poll_stop(&write_watcher_);
writing_ = false;
}
}

void StartWrite()
{
TRACE("Starting write watcher");
TRACE("write START");
if(reading_) {
TRACE("stop READ to start WRITE");
StopRead();
}
uv_poll_start(&write_watcher_, UV_WRITABLE, io_event);
writing_ = true;
}

void StopRead()
{
TRACE("Stoping read watcher");
TRACE("read STOP");
if(ioInitialized_) {
uv_poll_stop(&read_watcher_);
reading_ = false;
}
}

void StartRead()
{
TRACE("Starting read watcher");
TRACE("read START");
if(writing_) {
TRACE("stop WRITE to start READ");
StopWrite();
}
uv_poll_start(&read_watcher_, UV_READABLE, io_event);
reading_ = true;
}
//Converts a v8 array to an array of cstrings
//the result char** array must be free() when it is no longer needed
Expand Down
2 changes: 2 additions & 0 deletions test/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var BufferList = require(__dirname+'/buffer-list')

var Connection = require(__dirname + '/../lib/connection');

require(__dirname + '/../lib').defaults.hideDeprecationWarnings = true;

Client = require(__dirname + '/../lib').Client;

process.on('uncaughtException', function(d) {
Expand Down