Socket
Socket
Sign inDemoInstall

pg

Package Overview
Dependencies
Maintainers
1
Versions
224
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg - npm Package Compare versions

Comparing version 0.13.1 to 0.13.3

lib/types/arrayParser.js

72

lib/client.js

@@ -23,14 +23,14 @@ var crypto = require('crypto');

config = config || {};
var c = config || {};
this.connection = config.connection || new Connection({
stream: config.stream,
ssl: config.ssl
this.connection = c.connection || new Connection({
stream: c.stream,
ssl: c.ssl
});
this.queryQueue = [];
this.binary = config.binary || defaults.binary;
this.binary = c.binary || defaults.binary;
this.encoding = 'utf8';
this.processID = null;
this.secretKey = null;
this.ssl = config.ssl || false;
this.ssl = c.ssl || false;
};

@@ -40,5 +40,3 @@

var p = Client.prototype;
p.connect = function(callback) {
Client.prototype.connect = function(callback) {
var self = this;

@@ -55,3 +53,3 @@ var con = this.connection;

con.on('connect', function() {
if (self.ssl) {
if(self.ssl) {
con.requestSsl();

@@ -65,2 +63,3 @@ } else {

});
con.on('sslconnect', function() {

@@ -98,2 +97,3 @@ con.startup({

});
//delegate datarow to active query

@@ -103,2 +103,3 @@ con.on('dataRow', function(msg) {

});
//TODO should query gain access to connection?

@@ -117,7 +118,9 @@ con.on('portalSuspended', function(msg) {

});
con.on('copyInResponse', function(msg) {
self.activeQuery.streamData(self.connection);
});
con.on('copyOutResponse', function(msg) {
if (self.activeQuery.stream === undefined) {
if(self.activeQuery.stream === undefined) {
self.activeQuery._canceledDueToError =

@@ -131,5 +134,7 @@ new Error('No destination stream defined');

});
con.on('copyData', function (msg) {
self.activeQuery.handleCopyFromChunk(msg.chunk);
});
if (!callback) {

@@ -181,4 +186,4 @@ self.emit('connect');

p.cancel = function(client, query) {
if (client.activeQuery == query) {
Client.prototype.cancel = function(client, query) {
if(client.activeQuery == query) {
var con = this.connection;

@@ -196,4 +201,3 @@

});
}
else if (client.queryQueue.indexOf(query) != -1) {
} else if(client.queryQueue.indexOf(query) != -1) {
client.queryQueue.splice(client.queryQueue.indexOf(query), 1);

@@ -203,3 +207,3 @@ }

p._pulseQueryQueue = function() {
Client.prototype._pulseQueryQueue = function() {
if(this.readyForQuery===true) {

@@ -213,14 +217,19 @@ this.activeQuery = this.queryQueue.shift();

this.activeQuery = null;
if(this._drainPaused > 0) { this._drainPaused++; }
else { this.emit('drain'); }
//TODO remove pauseDrain for v1.0
if(this._drainPaused > 0) {
this._drainPaused++;
}
else {
this.emit('drain');
}
}
}
};
p._copy = function (text, stream) {
var config = {},
query;
Client.prototype._copy = function (text, stream) {
var config = {};
config.text = text;
config.stream = stream;
config.callback = function (error) {
if (error) {
if(error) {
config.stream.error(error);

@@ -231,3 +240,3 @@ } else {

};
query = new Query(config);
var query = new Query(config);
this.queryQueue.push(query);

@@ -238,13 +247,16 @@ this._pulseQueryQueue();

};
p.copyFrom = function (text) {
Client.prototype.copyFrom = function (text) {
return this._copy(text, new CopyFromStream());
};
p.copyTo = function (text) {
Client.prototype.copyTo = function (text) {
return this._copy(text, new CopyToStream());
};
p.query = function(config, values, callback) {
Client.prototype.query = function(config, values, callback) {
//can take in strings, config object or query object
var query = (config instanceof Query) ? config :
new Query(config, values, callback);
if (this.binary && !query.binary) {
if(this.binary && !query.binary) {
query.binary = true;

@@ -260,3 +272,3 @@ }

//called
p.pauseDrain = function() {
Client.prototype.pauseDrain = function() {
this._drainPaused = 1;

@@ -266,3 +278,3 @@ };

//resume raising 'drain' event
p.resumeDrain = function() {
Client.prototype.resumeDrain = function() {
if(this._drainPaused > 1) {

@@ -274,3 +286,3 @@ this.emit('drain');

p.end = function() {
Client.prototype.end = function() {
this.connection.end();

@@ -277,0 +289,0 @@ };

@@ -61,3 +61,3 @@ var dns = require('dns');

if(this.isDomainSocket) {
params.push("host=" + this.getDomainSocketName());
params.push("host=" + this.host);
return cb(null, params.join(' '));

@@ -73,12 +73,2 @@ }

ConnectionParameters.prototype.getDomainSocketName = function() {
var filename = '.s.PGSQL.' + this.port;
//if host is full path to socket fd with port number, just return it
if(this.host.indexOf(filename) > -1) return this.host;
//otherwise, build it from host + standard filename + port
return path.join(this.host, filename);
};
module.exports = ConnectionParameters;

@@ -25,9 +25,7 @@ var net = require('net');

var p = Connection.prototype;
Connection.prototype.connect = function(port, host) {
p.connect = function(port, host) {
if (this.stream.readyState === 'closed') {
if(this.stream.readyState === 'closed') {
this.stream.connect(port, host);
} else if (this.stream.readyState == 'open') {
} else if(this.stream.readyState == 'open') {
this.emit('connect');

@@ -54,3 +52,3 @@ }

this.once('sslresponse', function(msg) {
if (msg.text == 0x53) {
if(msg.text == 0x53) {
var tls = require('tls');

@@ -84,3 +82,3 @@ self.stream.removeAllListeners();

p.attachListeners = function(stream) {
Connection.prototype.attachListeners = function(stream) {
var self = this;

@@ -98,3 +96,3 @@ stream.on('data', function(buffer) {

p.requestSsl = function(config) {
Connection.prototype.requestSsl = function(config) {
this.checkSslResponse = true;

@@ -115,3 +113,3 @@

p.startup = function(config) {
Connection.prototype.startup = function(config) {
var bodyBuffer = this.writer

@@ -124,4 +122,4 @@ .addInt16(3)

.addCString(config.database)
.addCString('options')
.addCString("--client_encoding='utf-8'")
.addCString('client_encoding')
.addCString("'utf-8'")
.addCString('').flush();

@@ -139,3 +137,3 @@ //this message is sent without a code

p.cancel = function(processID, secretKey) {
Connection.prototype.cancel = function(processID, secretKey) {
var bodyBuffer = this.writer

@@ -157,3 +155,3 @@ .addInt16(1234)

p.password = function(password) {
Connection.prototype.password = function(password) {
//0x70 = 'p'

@@ -163,3 +161,3 @@ this._send(0x70, this.writer.addCString(password));

p._send = function(code, more) {
Connection.prototype._send = function(code, more) {
if(!this.stream.writable) { return false; }

@@ -173,3 +171,3 @@ if(more === true) {

p.query = function(text) {
Connection.prototype.query = function(text) {
//0x51 = Q

@@ -181,3 +179,3 @@ this.stream.write(this.writer.addCString(text).flush(0x51));

//"more" === true to buffer the message until flush() is called
p.parse = function(query, more) {
Connection.prototype.parse = function(query, more) {
//expect something like this:

@@ -207,3 +205,3 @@ // { name: 'queryName',

//"more" === true to buffer the message until flush() is called
p.bind = function(config, more) {
Connection.prototype.bind = function(config, more) {
//normalize config

@@ -231,3 +229,3 @@ config = config || {};

if (config.binary) {
if(config.binary) {
buffer.addInt16(1); // format codes to use binary

@@ -245,3 +243,3 @@ buffer.addInt16(1);

//"more" === true to buffer the message until flush() is called
p.execute = function(config, more) {
Connection.prototype.execute = function(config, more) {
config = config || {};

@@ -260,3 +258,3 @@ config.portal = config.portal || '';

p.flush = function() {
Connection.prototype.flush = function() {
//0x48 = 'H'

@@ -267,3 +265,3 @@ this.writer.add(emptyBuffer);

p.sync = function() {
Connection.prototype.sync = function() {
//clear out any pending data in the writer

@@ -276,3 +274,3 @@ this.writer.flush(0);

p.end = function() {
Connection.prototype.end = function() {
//0x58 = 'X'

@@ -283,13 +281,16 @@ this.writer.add(emptyBuffer);

p.describe = function(msg, more) {
Connection.prototype.describe = function(msg, more) {
this.writer.addCString(msg.type + (msg.name || ''));
this._send(0x44, more);
};
p.sendCopyFromChunk = function (chunk) {
Connection.prototype.sendCopyFromChunk = function (chunk) {
this.stream.write(this.writer.add(chunk).flush(0x64));
};
p.endCopyFrom = function () {
Connection.prototype.endCopyFrom = function () {
this.stream.write(this.writer.add(emptyBuffer).flush(0x63));
};
p.sendCopyFail = function (msg) {
Connection.prototype.sendCopyFail = function (msg) {
//this.stream.write(this.writer.add(emptyBuffer).flush(0x66));

@@ -299,4 +300,5 @@ this.writer.addCString(msg);

};
//parsing methods
p.setBuffer = function(buffer) {
Connection.prototype.setBuffer = function(buffer) {
if(this.lastBuffer) { //we have unfinished biznaz

@@ -314,3 +316,3 @@ //need to combine last two buffers

p.readSslResponse = function() {
Connection.prototype.readSslResponse = function() {
var remaining = this.buffer.length - (this.offset);

@@ -322,6 +324,9 @@ if(remaining < 1) {

}
return { name: 'sslresponse', text: this.buffer[this.offset++] };
return {
name: 'sslresponse',
text: this.buffer[this.offset++]
};
};
p.parseMessage = function() {
Connection.prototype.parseMessage = function() {
var remaining = this.buffer.length - (this.offset);

@@ -434,3 +439,3 @@ if(remaining < 5) {

p.parseR = function(msg) {
Connection.prototype.parseR = function(msg) {
var code = 0;

@@ -457,3 +462,3 @@ if(msg.length === 8) {

p.parseS = function(msg) {
Connection.prototype.parseS = function(msg) {
msg.parameterName = this.parseCString();

@@ -464,3 +469,3 @@ msg.parameterValue = this.parseCString();

p.parseK = function(msg) {
Connection.prototype.parseK = function(msg) {
msg.processID = this.parseInt32();

@@ -471,3 +476,3 @@ msg.secretKey = this.parseInt32();

p.parseC = function(msg) {
Connection.prototype.parseC = function(msg) {
msg.text = this.parseCString();

@@ -477,3 +482,3 @@ return msg;

p.parseZ = function(msg) {
Connection.prototype.parseZ = function(msg) {
msg.status = this.readChar();

@@ -483,3 +488,3 @@ return msg;

p.parseT = function(msg) {
Connection.prototype.parseT = function(msg) {
msg.fieldCount = this.parseInt16();

@@ -494,3 +499,3 @@ var fields = [];

p.parseField = function() {
Connection.prototype.parseField = function() {
var field = {

@@ -508,3 +513,3 @@ name: this.parseCString(),

p.parseD = function(msg) {
Connection.prototype.parseD = function(msg) {
var fieldCount = this.parseInt16();

@@ -522,3 +527,3 @@ var fields = [];

//parses error
p.parseE = function(input) {
Connection.prototype.parseE = function(input) {
var fields = {};

@@ -531,3 +536,3 @@ var msg, item;

}
if (input.name === 'error') {
if(input.name === 'error') {
// the msg is an Error instance

@@ -537,3 +542,3 @@ msg = new Error(fields.M);

// copy input properties to the error
if (input.hasOwnProperty(item)) {
if(input.hasOwnProperty(item)) {
msg[item] = input[item];

@@ -562,5 +567,5 @@ }

//same thing, different name
p.parseN = p.parseE;
Connection.prototype.parseN = Connection.prototype.parseE;
p.parseA = function(msg) {
Connection.prototype.parseA = function(msg) {
msg.processId = this.parseInt32();

@@ -571,3 +576,4 @@ msg.channel = this.parseCString();

};
p.parseGH = function (msg) {
Connection.prototype.parseGH = function (msg) {
msg.binary = Boolean(this.parseInt8());

@@ -581,3 +587,4 @@ var columnCount = this.parseInt16();

};
p.parseInt8 = function () {
Connection.prototype.parseInt8 = function () {
var value = Number(this.buffer[this.offset]);

@@ -587,7 +594,8 @@ this.offset++;

};
p.readChar = function() {
Connection.prototype.readChar = function() {
return Buffer([this.buffer[this.offset++]]).toString(this.encoding);
};
p.parseInt32 = function() {
Connection.prototype.parseInt32 = function() {
var value = this.peekInt32();

@@ -598,3 +606,3 @@ this.offset += 4;

p.peekInt32 = function(offset) {
Connection.prototype.peekInt32 = function(offset) {
offset = offset || this.offset;

@@ -609,3 +617,3 @@ var buffer = this.buffer;

p.parseInt16 = function() {
Connection.prototype.parseInt16 = function() {
return ((this.buffer[this.offset++] << 8) +

@@ -615,3 +623,3 @@ (this.buffer[this.offset++] << 0));

p.readString = function(length) {
Connection.prototype.readString = function(length) {
return this.buffer.toString(this.encoding, this.offset,

@@ -621,7 +629,7 @@ (this.offset += length));

p.readBytes = function(length) {
Connection.prototype.readBytes = function(length) {
return this.buffer.slice(this.offset, this.offset += length);
};
p.parseCString = function() {
Connection.prototype.parseCString = function() {
var start = this.offset;

@@ -631,3 +639,4 @@ while(this.buffer[this.offset++]) { }

};
p.parsed = function (msg) {
Connection.prototype.parsed = function (msg) {
//exclude length field

@@ -634,0 +643,0 @@ msg.chunk = this.readBytes(msg.length - 4);

@@ -14,8 +14,11 @@ var Stream = require('stream').Stream;

};
util.inherits(CopyFromStream, Stream);
CopyFromStream.prototype._writable = function () {
return !(this._finished || this._error);
};
CopyFromStream.prototype.startStreamingToConnection = function (connection) {
if (this._error) {
if(this._error) {
return;

@@ -27,7 +30,8 @@ }

};
CopyFromStream.prototype._handleChunk = function (string, encoding) {
var dataChunk,
tmpBuffer;
if (string !== undefined) {
if (string instanceof Buffer) {
if(string !== undefined) {
if(string instanceof Buffer) {
dataChunk = string;

@@ -37,3 +41,3 @@ } else {

}
if (this._buffer.length) {
if(this._buffer.length) {
//Buffer.concat is better, but it's missing

@@ -52,8 +56,9 @@ //in node v0.6.x

};
CopyFromStream.prototype._sendIfConnectionReady = function () {
var dataSent = false;
if (this._connection) {
if(this._connection) {
dataSent = this._connection.sendCopyFromChunk(this._buffer);
this._buffer = new Buffer(0);
if (this._dataBuffered) {
if(this._dataBuffered) {
this.emit('drain');

@@ -67,4 +72,5 @@ }

};
CopyFromStream.prototype._endIfNeedAndPossible = function () {
if (this._connection && this._finished && !this._finishedSent) {
if(this._connection && this._finished && !this._finishedSent) {
this._finishedSent = true;

@@ -74,4 +80,5 @@ this._connection.endCopyFrom();

};
CopyFromStream.prototype.write = function (string, encoding) {
if (this._error || this._finished) {
if(this._error || this._finished) {
return false;

@@ -81,8 +88,9 @@ }

};
CopyFromStream.prototype.end = function (string, encondig) {
if (this._error || this._finished) {
if(this._error || this._finished) {
return false;
}
this._finished = true;
if (string !== undefined) {
if(string !== undefined) {
this._handleChunk.apply(this, arguments);

@@ -92,4 +100,5 @@ }

};
CopyFromStream.prototype.error = function (error) {
if (this._error || this._closed) {
if(this._error || this._closed) {
return false;

@@ -100,7 +109,8 @@ }

};
CopyFromStream.prototype.close = function () {
if (this._error || this._closed) {
if(this._error || this._closed) {
return false;
}
if (!this._finishedSent) {
if(!this._finishedSent) {
throw new Error("seems to be error in code that uses CopyFromStream");

@@ -110,2 +120,3 @@ }

};
var CopyToStream = function () {

@@ -120,9 +131,11 @@ Stream.apply(this, arguments);

};
util.inherits(CopyToStream, Stream);
CopyToStream.prototype._outputDataChunk = function () {
if (this._paused) {
if(this._paused) {
return;
}
if (this.buffer.length) {
if (this._encoding) {
if(this.buffer.length) {
if(this._encoding) {
this.emit('data', this.buffer.toString(this._encoding));

@@ -135,29 +148,33 @@ } else {

};
CopyToStream.prototype._readable = function () {
return !this._finished && !this._error;
};
CopyToStream.prototype.error = function (error) {
if (!this.readable) {
if(!this.readable) {
return false;
}
this._error = error;
if (!this._paused) {
if(!this._paused) {
this.emit('error', error);
}
};
CopyToStream.prototype.close = function () {
if (!this.readable) {
if(!this.readable) {
return false;
}
this._finished = true;
if (!this._paused) {
if(!this._paused) {
this.emit("end");
}
};
CopyToStream.prototype.handleChunk = function (chunk) {
var tmpBuffer;
if (!this.readable) {
if(!this.readable) {
return;
}
if (!this.buffer.length) {
if(!this.buffer.length) {
this.buffer = chunk;

@@ -172,4 +189,5 @@ } else {

};
CopyToStream.prototype.pause = function () {
if (!this.readable) {
if(!this.readable) {
return false;

@@ -179,4 +197,5 @@ }

};
CopyToStream.prototype.resume = function () {
if (!this._paused) {
if(!this._paused) {
return false;

@@ -186,9 +205,10 @@ }

this._outputDataChunk();
if (this._error) {
if(this._error) {
return this.emit('error', this._error);
}
if (this._finished) {
if(this._finished) {
return this.emit('end');
}
};
CopyToStream.prototype.setEncoding = function (encoding) {

@@ -195,0 +215,0 @@ this._encoding = encoding;

@@ -6,3 +6,3 @@ var EventEmitter = require('events').EventEmitter;

var pool = require(__dirname + '/pool');
var types = require(__dirname + '/types');
var types = require(__dirname + '/types/');
var Connection = require(__dirname + '/connection');

@@ -9,0 +9,0 @@

@@ -5,3 +5,2 @@ //require the c++ bindings & export to javascript

var ConnectionParameters = require(__dirname + '/../connection-parameters');
var utils = require(__dirname + "/../utils");
var CopyFromStream = require(__dirname + '/../copystream').CopyFromStream;

@@ -12,2 +11,3 @@ var CopyToStream = require(__dirname + '/../copystream').CopyToStream;

//TODO remove on v1.0.0
try {

@@ -22,14 +22,11 @@ //v0.5.x

var Connection = binding.Connection;
var types = require(__dirname + "/../types");
var NativeQuery = require(__dirname + '/query');
var EventEmitter = require('events').EventEmitter;
var p = Connection.prototype;
for(var k in EventEmitter.prototype) {
p[k] = EventEmitter.prototype[k];
Connection.prototype[k] = EventEmitter.prototype[k];
}
var nativeConnect = p.connect;
var nativeConnect = Connection.prototype.connect;
p.connect = function(cb) {
Connection.prototype.connect = function(cb) {
var self = this;

@@ -58,3 +55,4 @@ this.connectionParameters.getLibpqConnectionString(function(err, conString) {

};
p._copy = function (text, stream) {
Connection.prototype._copy = function (text, stream) {
var q = new NativeQuery(text, function (error) {

@@ -72,15 +70,20 @@ if (error) {

};
p.copyFrom = function (text) {
Connection.prototype.copyFrom = function (text) {
return this._copy(text, new CopyFromStream());
};
p.copyTo = function (text) {
Connection.prototype.copyTo = function (text) {
return this._copy(text, new CopyToStream());
};
p.sendCopyFromChunk = function (chunk) {
Connection.prototype.sendCopyFromChunk = function (chunk) {
this._sendCopyFromChunk(chunk);
};
p.endCopyFrom = function (msg) {
Connection.prototype.endCopyFrom = function (msg) {
this._endCopyFrom(msg);
};
p.query = function(config, values, callback) {
Connection.prototype.query = function(config, values, callback) {
var query = (config instanceof NativeQuery) ? config :

@@ -93,12 +96,13 @@ new NativeQuery(config, values, callback);

var nativeCancel = p.cancel;
var nativeCancel = Connection.prototype.cancel;
p.cancel = function(client, query) {
if (client._activeQuery == query)
Connection.prototype.cancel = function(client, query) {
if (client._activeQuery == query) {
this.connect(nativeCancel.bind(client));
else if (client._queryQueue.indexOf(query) != -1)
} else if (client._queryQueue.indexOf(query) != -1) {
client._queryQueue.splice(client._queryQueue.indexOf(query), 1);
}
};
p._pulseQueryQueue = function(initialConnection) {
Connection.prototype._pulseQueryQueue = function(initialConnection) {
if(!this._connected) {

@@ -113,2 +117,3 @@ return;

if(!initialConnection) {
//TODO remove all the pause-drain stuff for v1.0
if(this._drainPaused) {

@@ -131,4 +136,3 @@ this._drainPaused++;

}
}
else if(query.values) {
} else if(query.values) {
//call native function

@@ -142,7 +146,9 @@ this._sendQueryWithParams(query.text, query.values);

p.pauseDrain = function() {
//TODO remove all the pause-drain stuff for v1.0
Connection.prototype.pauseDrain = function() {
this._drainPaused = 1;
};
p.resumeDrain = function() {
//TODO remove all the pause-drain stuff for v1.0
Connection.prototype.resumeDrain = function() {
if(this._drainPaused > 1) {

@@ -153,5 +159,7 @@ this.emit('drain');

};
p.sendCopyFail = function(msg) {
Connection.prototype.sendCopyFail = function(msg) {
this.endCopyFrom(msg);
};
var clientBuilder = function(config) {

@@ -222,6 +230,4 @@ config = config || {};

if (connection._activeQuery.stream === undefined) {
connection._activeQuery._canceledDueToError =
new Error('No destination stream defined');
(new clientBuilder({port: connection.port, host: connection.host}))
.cancel(connection, connection._activeQuery);
connection._activeQuery._canceledDueToError = new Error('No destination stream defined');
(new clientBuilder({port: connection.port, host: connection.host})).cancel(connection, connection._activeQuery);
}

@@ -228,0 +234,0 @@ });

var EventEmitter = require('events').EventEmitter;
var util = require('util');
var types = require(__dirname + '/../types');
var types = require(__dirname + '/../types/');
var utils = require(__dirname + '/../utils');

@@ -17,8 +17,8 @@ var Result = require(__dirname + '/../result');

config = utils.normalizeQueryConfig(config, values, callback);
var c = utils.normalizeQueryConfig(config, values, callback);
this.name = config.name;
this.text = config.text;
this.values = config.values;
this.callback = config.callback;
this.name = c.name;
this.text = c.text;
this.values = c.values;
this.callback = c.callback;

@@ -36,3 +36,2 @@ this._result = new Result();

util.inherits(NativeQuery, EventEmitter);
var p = NativeQuery.prototype;

@@ -50,3 +49,3 @@ //maps from native rowdata into api compatible row object

p.handleRow = function(rowData) {
NativeQuery.prototype.handleRow = function(rowData) {
var row = mapRowData(rowData);

@@ -59,3 +58,3 @@ if(this.callback) {

p.handleError = function(error) {
NativeQuery.prototype.handleError = function(error) {
if (this._canceledDueToError) {

@@ -73,3 +72,3 @@ error = this._canceledDueToError;

p.handleReadyForQuery = function(meta) {
NativeQuery.prototype.handleReadyForQuery = function(meta) {
if (this._canceledDueToError) {

@@ -86,8 +85,14 @@ return this.handleError(this._canceledDueToError);

};
p.streamData = function (connection) {
if ( this.stream ) this.stream.startStreamingToConnection(connection);
else connection.sendCopyFail('No source stream defined');
NativeQuery.prototype.streamData = function (connection) {
if(this.stream) {
this.stream.startStreamingToConnection(connection);
}
else {
connection.sendCopyFail('No source stream defined');
}
};
p.handleCopyFromChunk = function (chunk) {
if ( this.stream ) {
NativeQuery.prototype.handleCopyFromChunk = function (chunk) {
if(this.stream) {
this.stream.handleChunk(chunk);

@@ -99,2 +104,3 @@ }

};
module.exports = NativeQuery;

@@ -5,3 +5,3 @@ var EventEmitter = require('events').EventEmitter;

var Result = require(__dirname + '/result');
var Types = require(__dirname + '/types');
var Types = require(__dirname + '/types/');
var utils = require(__dirname + '/utils');

@@ -11,3 +11,3 @@

// use of "new" optional
if (!(this instanceof Query)) { return new Query(config, values, callback); }
if(!(this instanceof Query)) { return new Query(config, values, callback); }

@@ -35,5 +35,4 @@ config = utils.normalizeQueryConfig(config, values, callback);

util.inherits(Query, EventEmitter);
var p = Query.prototype;
p.requiresPreparation = function() {
Query.prototype.requiresPreparation = function() {
//named queries must always be prepared

@@ -61,3 +60,3 @@ if(this.name) { return true; }

//metadata used when parsing row results
p.handleRowDescription = function(msg) {
Query.prototype.handleRowDescription = function(msg) {
this._fieldNames = [];

@@ -74,3 +73,3 @@ this._fieldConverters = [];

p.handleDataRow = function(msg) {
Query.prototype.handleDataRow = function(msg) {
var self = this;

@@ -96,8 +95,8 @@ var row = {};

p.handleCommandComplete = function(msg) {
Query.prototype.handleCommandComplete = function(msg) {
this._result.addCommandComplete(msg);
};
p.handleReadyForQuery = function() {
if (this._canceledDueToError) {
Query.prototype.handleReadyForQuery = function() {
if(this._canceledDueToError) {
return this.handleError(this._canceledDueToError);

@@ -111,4 +110,4 @@ }

p.handleError = function(err) {
if (this._canceledDueToError) {
Query.prototype.handleError = function(err) {
if(this._canceledDueToError) {
err = this._canceledDueToError;

@@ -127,3 +126,3 @@ this._canceledDueToError = false;

p.submit = function(connection) {
Query.prototype.submit = function(connection) {
var self = this;

@@ -137,7 +136,7 @@ if(this.requiresPreparation()) {

p.hasBeenParsed = function(connection) {
Query.prototype.hasBeenParsed = function(connection) {
return this.name && connection.parsedStatements[this.name];
};
p.getRows = function(connection) {
Query.prototype.getRows = function(connection) {
connection.execute({

@@ -150,3 +149,3 @@ portal: this.portalName,

p.prepare = function(connection) {
Query.prototype.prepare = function(connection) {
var self = this;

@@ -190,8 +189,10 @@ //prepared statements need sync to be called after each command

};
p.streamData = function (connection) {
if ( this.stream ) this.stream.startStreamingToConnection(connection);
Query.prototype.streamData = function (connection) {
if(this.stream) this.stream.startStreamingToConnection(connection);
else connection.sendCopyFail('No source stream defined');
};
p.handleCopyFromChunk = function (chunk) {
if ( this.stream ) {
Query.prototype.handleCopyFromChunk = function (chunk) {
if(this.stream) {
this.stream.handleChunk(chunk);

@@ -198,0 +199,0 @@ }

@@ -11,8 +11,6 @@ //result object returned from query

var p = Result.prototype;
var matchRegexp = /([A-Za-z]+) (\d+ )?(\d+)?/;
//adds a command complete message
p.addCommandComplete = function(msg) {
Result.prototype.addCommandComplete = function(msg) {
var match;

@@ -39,3 +37,3 @@ if(msg.text) {

p.addRow = function(row) {
Result.prototype.addRow = function(row) {
this.rows.push(row);

@@ -42,0 +40,0 @@ };

@@ -22,6 +22,6 @@ var url = require('url');

for (var i = 0 ; i < val.length; i++) {
if (i > 0) {
if(i > 0) {
result = result + ',';
}
if (val[i] instanceof Date) {
if(val[i] instanceof Date) {
result = result + JSON.stringify(val[i]);

@@ -32,3 +32,3 @@ }

}
else if (Array.isArray(val[i])) {
else if(Array.isArray(val[i])) {
result = result + arrayString(val[i]);

@@ -57,3 +57,3 @@ }

}
if (Array.isArray(val)) {
if(Array.isArray(val)) {
return arrayString(val);

@@ -74,3 +74,3 @@ }

}
if (callback) {
if(callback) {
config.callback = callback;

@@ -77,0 +77,0 @@ }

@@ -11,6 +11,4 @@ //binary data writer tuned for creating

var p = Writer.prototype;
//resizes internal buffer if not enough size left
p._ensure = function(size) {
Writer.prototype._ensure = function(size) {
var remaining = this.buffer.length - this.offset;

@@ -24,3 +22,3 @@ if(remaining < size) {

p.addInt32 = function(num) {
Writer.prototype.addInt32 = function(num) {
this._ensure(4);

@@ -34,3 +32,3 @@ this.buffer[this.offset++] = (num >>> 24 & 0xFF);

p.addInt16 = function(num) {
Writer.prototype.addInt16 = function(num) {
this._ensure(2);

@@ -54,3 +52,3 @@ this.buffer[this.offset++] = (num >>> 8 & 0xFF);

p.addCString = function(string) {
Writer.prototype.addCString = function(string) {
//just write a 0 for empty or null strings

@@ -70,3 +68,3 @@ if(!string) {

p.addChar = function(c) {
Writer.prototype.addChar = function(c) {
this._ensure(1);

@@ -78,3 +76,3 @@ writeString(this.buffer, c, this.offset, 1);

p.addString = function(string) {
Writer.prototype.addString = function(string) {
string = string || "";

@@ -88,7 +86,7 @@ var len = Buffer.byteLength(string);

p.getByteLength = function() {
Writer.prototype.getByteLength = function() {
return this.offset - 5;
};
p.add = function(otherBuffer) {
Writer.prototype.add = function(otherBuffer) {
this._ensure(otherBuffer.length);

@@ -100,3 +98,3 @@ otherBuffer.copy(this.buffer, this.offset);

p.clear = function() {
Writer.prototype.clear = function() {
this.offset = 5;

@@ -109,3 +107,3 @@ this.headerPosition = 0;

//subsequent header or to the beginning if there is only one data block
p.addHeader = function(code, last) {
Writer.prototype.addHeader = function(code, last) {
var origOffset = this.offset;

@@ -126,3 +124,3 @@ this.offset = this.headerPosition;

p.join = function(code) {
Writer.prototype.join = function(code) {
if(code) {

@@ -134,3 +132,3 @@ this.addHeader(code, true);

p.flush = function(code) {
Writer.prototype.flush = function(code) {
var result = this.join(code);

@@ -137,0 +135,0 @@ this.clear();

{ "name": "pg",
"version": "0.13.1",
"version": "0.13.3",
"description": "PostgreSQL client - pure javascript & libpq with the same API",

@@ -4,0 +4,0 @@ "keywords" : ["postgres", "pg", "libpq", "postgre", "database", "rdbms"],

@@ -56,13 +56,2 @@ var helper = require(__dirname + '/../test-helper');

test('builds domain socket', function() {
var subject = new ConnectionParameters({
host: '/var/run/',
port: 1234
});
assert.equal(subject.getDomainSocketName(), '/var/run/.s.PGSQL.1234');
subject.host = '/tmp';
assert.equal(subject.getDomainSocketName(), '/tmp/.s.PGSQL.1234');
assert.equal(subject.getDomainSocketName(), '/tmp/.s.PGSQL.1234');
});
test('libpq connection string building', function() {

@@ -135,3 +124,3 @@ var checkForPart = function(array, part) {

checkForPart(parts, "user='brian'");
checkForPart(parts, "host=/tmp/.s.PGSQL.5432");
checkForPart(parts, "host=/tmp/");
}));

@@ -138,0 +127,0 @@ });

@@ -26,4 +26,4 @@ require(__dirname + "/test-helper");

.addCString('bang')
.addCString('options')
.addCString("--client_encoding='utf-8'")
.addCString('client_encoding')
.addCString("'utf-8'")
.addCString('').join(true))

@@ -30,0 +30,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc