Comparing version 0.6.5 to 0.6.6
@@ -24,2 +24,4 @@ var crypto = require('crypto'); | ||
this.encoding = 'utf8'; | ||
this.processID = null; | ||
this.secretKey = null; | ||
var self = this; | ||
@@ -63,2 +65,7 @@ }; | ||
con.once('backendKeyData', function(msg) { | ||
self.processID = msg.processID; | ||
self.secretKey = msg.secretKey; | ||
}); | ||
//hook up query handling events to connection | ||
@@ -135,2 +142,21 @@ //after the connection initially becomes ready for queries | ||
p.cancel = function(client, query) { | ||
if (client.activeQuery == query) { | ||
var con = this.connection; | ||
if(this.host && this.host.indexOf('/') === 0) { | ||
con.connect(this.host + '/.s.PGSQL.' + this.port); | ||
} else { | ||
con.connect(this.port, this.host); | ||
} | ||
//once connection is established send cancel message | ||
con.on('connect', function() { | ||
con.cancel(client.processID, client.secretKey); | ||
}); | ||
} | ||
else if (client.queryQueue.indexOf(query) != -1) | ||
client.queryQueue.splice(client.queryQueue.indexOf(query), 1); | ||
}; | ||
p._pulseQueryQueue = function() { | ||
@@ -137,0 +163,0 @@ if(this.readyForQuery===true) { |
@@ -76,2 +76,19 @@ var net = require('net'); | ||
p.cancel = function(processID, secretKey) { | ||
var bodyBuffer = this.writer | ||
.addInt16(1234) | ||
.addInt16(5678) | ||
.addInt32(processID) | ||
.addInt32(secretKey) | ||
.addCString('').flush(); | ||
var length = bodyBuffer.length + 4; | ||
var buffer = new Writer() | ||
.addInt32(length) | ||
.add(bodyBuffer) | ||
.join(); | ||
this.stream.write(buffer); | ||
}; | ||
p.password = function(password) { | ||
@@ -78,0 +95,0 @@ //0x70 = 'p' |
@@ -84,2 +84,12 @@ var EventEmitter = require('events').EventEmitter; | ||
// cancel the query runned by the given client | ||
PG.prototype.cancel = function(config, client, query) { | ||
var c = config; | ||
//allow for no config to be passed | ||
if(typeof c === 'function') | ||
c = defaults; | ||
var cancellingClient = new this.Client(c); | ||
cancellingClient.cancel(client, query); | ||
} | ||
module.exports = new PG(Client); | ||
@@ -86,0 +96,0 @@ |
@@ -59,2 +59,11 @@ //require the c++ bindings & export to javascript | ||
var nativeCancel = p.cancel; | ||
p.cancel = function(client, query) { | ||
if (client._activeQuery == query) | ||
this.connect(nativeCancel.bind(client)); | ||
else if (client._queryQueue.indexOf(query) != -1) | ||
client._queryQueue.splice(client._queryQueue.indexOf(query), 1); | ||
}; | ||
p._pulseQueryQueue = function(initialConnection) { | ||
@@ -98,4 +107,4 @@ if(!this._connected) { | ||
p.resumeDrain = function() { | ||
if(this._drainPaused > 1) { | ||
this.emit('drain') | ||
if(this._drainPaused > 1) { | ||
this.emit('drain') | ||
}; | ||
@@ -102,0 +111,0 @@ this._drainPaused = 0; |
{ "name": "pg", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"description": "PostgreSQL client - pure javascript & libpq with the same API", | ||
@@ -4,0 +4,0 @@ "keywords" : ["postgres", "pg", "libpq", "postgre", "database", "rdbms"], |
@@ -122,2 +122,3 @@ #node-postgres | ||
* [shtylman](https://github.com/shtylman) | ||
* [cricri](https://github.com/cricri) | ||
@@ -124,0 +125,0 @@ ## Documentation |
@@ -1,2 +0,1 @@ | ||
var sys = require('utils'); | ||
var args = require(__dirname + '/../test/cli'); | ||
@@ -3,0 +2,0 @@ var pg = require(__dirname + '/../lib'); |
Sorry, the diff of this file is not supported yet
201886
85
5370
167
135