Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated compiled js files

  • Loading branch information...
commit 2bda0f37f1637de0a28243b08a42348bd88940e1 1 parent ba5e819
@wvanbergen authored
View
33 lib/authentication.js
@@ -1,21 +1,18 @@
// Generated by CoffeeScript 1.6.2
-(function() {
- var Authentication;
+var Authentication;
- Authentication = {
- methods: {
- OK: 0,
- KERBEROS_V5: 2,
- CLEARTEXT_PASSWORD: 3,
- CRYPT_PASSWORD: 4,
- MD5_PASSWORD: 5,
- SCM_CREDENTIAL: 6,
- GSS: 7,
- GSS_CONTINUE: 8,
- SSPI: 9
- }
- };
+Authentication = {
+ methods: {
+ OK: 0,
+ KERBEROS_V5: 2,
+ CLEARTEXT_PASSWORD: 3,
+ CRYPT_PASSWORD: 4,
+ MD5_PASSWORD: 5,
+ SCM_CREDENTIAL: 6,
+ GSS: 7,
+ GSS_CONTINUE: 8,
+ SSPI: 9
+ }
+};
- module.exports = Authentication;
-
-}).call(this);
+module.exports = Authentication;
View
617 lib/backend_message.js
@@ -1,411 +1,408 @@
// Generated by CoffeeScript 1.6.2
-(function() {
- var AuthenticationMethods, BackendMessage, messageClass, name, typeOIDs, _ref, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9,
- __hasProp = {}.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+var AuthenticationMethods, BackendMessage, messageClass, name, typeOIDs, _ref, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9,
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
- AuthenticationMethods = require('./authentication').methods;
+AuthenticationMethods = require('./authentication').methods;
- typeOIDs = require('./types').typeOIDs;
+typeOIDs = require('./types').typeOIDs;
- BackendMessage = (function() {
- BackendMessage.prototype.typeId = null;
+BackendMessage = (function() {
+ BackendMessage.prototype.typeId = null;
- function BackendMessage(buffer) {
- this.read(buffer);
- }
-
- BackendMessage.prototype.read = function(buffer) {};
-
- return BackendMessage;
-
- })();
-
- BackendMessage.Authentication = (function(_super) {
- __extends(Authentication, _super);
+ function BackendMessage(buffer) {
+ this.read(buffer);
+ }
- function Authentication() {
- _ref = Authentication.__super__.constructor.apply(this, arguments);
- return _ref;
- }
+ BackendMessage.prototype.read = function(buffer) {};
- Authentication.prototype.typeId = 82;
+ return BackendMessage;
- Authentication.prototype.read = function(buffer) {
- this.method = buffer.readUInt32(0);
- if (this.method === AuthenticationMethods.MD5_PASSWORD) {
- return this.salt = buffer.readUInt32(4);
- } else if (this.method === AuthenticationMethods.CRYPT_PASSWORD) {
- return this.salt = buffer.readUInt16(4);
- }
- };
+})();
- return Authentication;
+BackendMessage.Authentication = (function(_super) {
+ __extends(Authentication, _super);
- })(BackendMessage);
+ function Authentication() {
+ _ref = Authentication.__super__.constructor.apply(this, arguments);
+ return _ref;
+ }
- BackendMessage.BackendKeyData = (function(_super) {
- __extends(BackendKeyData, _super);
+ Authentication.prototype.typeId = 82;
- function BackendKeyData() {
- _ref1 = BackendKeyData.__super__.constructor.apply(this, arguments);
- return _ref1;
+ Authentication.prototype.read = function(buffer) {
+ this.method = buffer.readUInt32(0);
+ if (this.method === AuthenticationMethods.MD5_PASSWORD) {
+ return this.salt = buffer.readUInt32(4);
+ } else if (this.method === AuthenticationMethods.CRYPT_PASSWORD) {
+ return this.salt = buffer.readUInt16(4);
}
+ };
- BackendKeyData.prototype.typeId = 75;
-
- BackendKeyData.prototype.read = function(buffer) {
- this.pid = buffer.readUInt32(0);
- return this.key = buffer.readUInt32(4);
- };
-
- return BackendKeyData;
+ return Authentication;
- })(BackendMessage);
+})(BackendMessage);
- BackendMessage.ParameterStatus = (function(_super) {
- __extends(ParameterStatus, _super);
+BackendMessage.BackendKeyData = (function(_super) {
+ __extends(BackendKeyData, _super);
- function ParameterStatus() {
- _ref2 = ParameterStatus.__super__.constructor.apply(this, arguments);
- return _ref2;
- }
+ function BackendKeyData() {
+ _ref1 = BackendKeyData.__super__.constructor.apply(this, arguments);
+ return _ref1;
+ }
- ParameterStatus.prototype.typeId = 83;
+ BackendKeyData.prototype.typeId = 75;
- ParameterStatus.prototype.read = function(buffer) {
- this.name = buffer.readZeroTerminatedString(0);
- return this.value = buffer.readZeroTerminatedString(this.name.length + 1);
- };
+ BackendKeyData.prototype.read = function(buffer) {
+ this.pid = buffer.readUInt32(0);
+ return this.key = buffer.readUInt32(4);
+ };
- return ParameterStatus;
+ return BackendKeyData;
- })(BackendMessage);
+})(BackendMessage);
- BackendMessage.NotificationResponse = (function(_super) {
- __extends(NotificationResponse, _super);
+BackendMessage.ParameterStatus = (function(_super) {
+ __extends(ParameterStatus, _super);
- function NotificationResponse() {
- _ref3 = NotificationResponse.__super__.constructor.apply(this, arguments);
- return _ref3;
- }
+ function ParameterStatus() {
+ _ref2 = ParameterStatus.__super__.constructor.apply(this, arguments);
+ return _ref2;
+ }
- NotificationResponse.prototype.typeId = 65;
+ ParameterStatus.prototype.typeId = 83;
- NotificationResponse.prototype.read = function(buffer) {
- this.pid = buffer.readUInt32(4);
- this.channel = buffer.readZeroTerminatedString(4);
- return this.payload = buffer.readZeroTerminatedString(this.channel.length + 5);
- };
+ ParameterStatus.prototype.read = function(buffer) {
+ this.name = buffer.readZeroTerminatedString(0);
+ return this.value = buffer.readZeroTerminatedString(this.name.length + 1);
+ };
- return NotificationResponse;
+ return ParameterStatus;
- })(BackendMessage);
+})(BackendMessage);
- BackendMessage.EmptyQueryResponse = (function(_super) {
- __extends(EmptyQueryResponse, _super);
+BackendMessage.NotificationResponse = (function(_super) {
+ __extends(NotificationResponse, _super);
- function EmptyQueryResponse() {
- _ref4 = EmptyQueryResponse.__super__.constructor.apply(this, arguments);
- return _ref4;
- }
+ function NotificationResponse() {
+ _ref3 = NotificationResponse.__super__.constructor.apply(this, arguments);
+ return _ref3;
+ }
- EmptyQueryResponse.prototype.typeId = 73;
+ NotificationResponse.prototype.typeId = 65;
- return EmptyQueryResponse;
+ NotificationResponse.prototype.read = function(buffer) {
+ this.pid = buffer.readUInt32(4);
+ this.channel = buffer.readZeroTerminatedString(4);
+ return this.payload = buffer.readZeroTerminatedString(this.channel.length + 5);
+ };
- })(BackendMessage);
+ return NotificationResponse;
- BackendMessage.RowDescription = (function(_super) {
- __extends(RowDescription, _super);
+})(BackendMessage);
- function RowDescription() {
- _ref5 = RowDescription.__super__.constructor.apply(this, arguments);
- return _ref5;
- }
+BackendMessage.EmptyQueryResponse = (function(_super) {
+ __extends(EmptyQueryResponse, _super);
- RowDescription.prototype.typeId = 84;
+ function EmptyQueryResponse() {
+ _ref4 = EmptyQueryResponse.__super__.constructor.apply(this, arguments);
+ return _ref4;
+ }
- RowDescription.prototype.read = function(buffer) {
- var fieldDescriptor, formatCode, i, modifier, name, numberOfFields, pos, size, tableFieldIndex, tableOID, typeOID, _i, _results;
+ EmptyQueryResponse.prototype.typeId = 73;
- numberOfFields = buffer.readUInt16(0);
- pos = 2;
- this.columns = [];
- _results = [];
- for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
- name = buffer.readZeroTerminatedString(pos);
- pos += Buffer.byteLength(name) + 1;
- tableOID = buffer.readUInt32(pos);
- pos += 4;
- tableFieldIndex = buffer.readUInt16(pos);
- pos += 2;
- typeOID = buffer.readUInt32(pos);
- pos += 4;
- size = buffer.readUInt16(pos);
- pos += 2;
- modifier = buffer.readUInt32(pos);
- pos += 4;
- formatCode = buffer.readUInt16(pos);
- pos += 2;
- fieldDescriptor = {
- name: name,
- tableOID: tableOID,
- tableFieldIndex: tableFieldIndex,
- typeOID: typeOID,
- type: typeOIDs[typeOID],
- size: size,
- modifier: modifier,
- formatCode: formatCode
- };
- _results.push(this.columns.push(fieldDescriptor));
- }
- return _results;
- };
+ return EmptyQueryResponse;
- return RowDescription;
+})(BackendMessage);
- })(BackendMessage);
+BackendMessage.RowDescription = (function(_super) {
+ __extends(RowDescription, _super);
- BackendMessage.DataRow = (function(_super) {
- __extends(DataRow, _super);
+ function RowDescription() {
+ _ref5 = RowDescription.__super__.constructor.apply(this, arguments);
+ return _ref5;
+ }
- function DataRow() {
- _ref6 = DataRow.__super__.constructor.apply(this, arguments);
- return _ref6;
+ RowDescription.prototype.typeId = 84;
+
+ RowDescription.prototype.read = function(buffer) {
+ var fieldDescriptor, formatCode, i, modifier, name, numberOfFields, pos, size, tableFieldIndex, tableOID, typeOID, _i, _results;
+
+ numberOfFields = buffer.readUInt16(0);
+ pos = 2;
+ this.columns = [];
+ _results = [];
+ for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
+ name = buffer.readZeroTerminatedString(pos);
+ pos += Buffer.byteLength(name) + 1;
+ tableOID = buffer.readUInt32(pos);
+ pos += 4;
+ tableFieldIndex = buffer.readUInt16(pos);
+ pos += 2;
+ typeOID = buffer.readUInt32(pos);
+ pos += 4;
+ size = buffer.readUInt16(pos);
+ pos += 2;
+ modifier = buffer.readUInt32(pos);
+ pos += 4;
+ formatCode = buffer.readUInt16(pos);
+ pos += 2;
+ fieldDescriptor = {
+ name: name,
+ tableOID: tableOID,
+ tableFieldIndex: tableFieldIndex,
+ typeOID: typeOID,
+ type: typeOIDs[typeOID],
+ size: size,
+ modifier: modifier,
+ formatCode: formatCode
+ };
+ _results.push(this.columns.push(fieldDescriptor));
}
+ return _results;
+ };
- DataRow.prototype.typeId = 68;
-
- DataRow.prototype.read = function(buffer) {
- var data, i, length, numberOfFields, pos, _i, _results;
-
- numberOfFields = buffer.readUInt16(0);
- pos = 2;
- this.values = [];
- _results = [];
- for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
- length = buffer.readUInt32(pos);
- pos += 4;
- if (length === -1) {
- data = null;
- } else {
- data = buffer.slice(pos, pos + length);
- pos += length;
- }
- _results.push(this.values.push(data));
- }
- return _results;
- };
+ return RowDescription;
- return DataRow;
+})(BackendMessage);
- })(BackendMessage);
+BackendMessage.DataRow = (function(_super) {
+ __extends(DataRow, _super);
- BackendMessage.CommandComplete = (function(_super) {
- __extends(CommandComplete, _super);
+ function DataRow() {
+ _ref6 = DataRow.__super__.constructor.apply(this, arguments);
+ return _ref6;
+ }
- function CommandComplete() {
- _ref7 = CommandComplete.__super__.constructor.apply(this, arguments);
- return _ref7;
+ DataRow.prototype.typeId = 68;
+
+ DataRow.prototype.read = function(buffer) {
+ var data, i, length, numberOfFields, pos, _i, _results;
+
+ numberOfFields = buffer.readUInt16(0);
+ pos = 2;
+ this.values = [];
+ _results = [];
+ for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
+ length = buffer.readUInt32(pos);
+ pos += 4;
+ if (length === -1) {
+ data = null;
+ } else {
+ data = buffer.slice(pos, pos + length);
+ pos += length;
+ }
+ _results.push(this.values.push(data));
}
+ return _results;
+ };
- CommandComplete.prototype.typeId = 67;
+ return DataRow;
- CommandComplete.prototype.read = function(buffer) {
- return this.status = buffer.readZeroTerminatedString(0);
- };
+})(BackendMessage);
- return CommandComplete;
+BackendMessage.CommandComplete = (function(_super) {
+ __extends(CommandComplete, _super);
- })(BackendMessage);
+ function CommandComplete() {
+ _ref7 = CommandComplete.__super__.constructor.apply(this, arguments);
+ return _ref7;
+ }
- BackendMessage.CloseComplete = (function(_super) {
- __extends(CloseComplete, _super);
+ CommandComplete.prototype.typeId = 67;
- function CloseComplete() {
- _ref8 = CloseComplete.__super__.constructor.apply(this, arguments);
- return _ref8;
- }
+ CommandComplete.prototype.read = function(buffer) {
+ return this.status = buffer.readZeroTerminatedString(0);
+ };
- CloseComplete.prototype.typeId = 51;
+ return CommandComplete;
- return CloseComplete;
+})(BackendMessage);
- })(BackendMessage);
+BackendMessage.CloseComplete = (function(_super) {
+ __extends(CloseComplete, _super);
- BackendMessage.ParameterDescription = (function(_super) {
- __extends(ParameterDescription, _super);
+ function CloseComplete() {
+ _ref8 = CloseComplete.__super__.constructor.apply(this, arguments);
+ return _ref8;
+ }
- function ParameterDescription() {
- _ref9 = ParameterDescription.__super__.constructor.apply(this, arguments);
- return _ref9;
- }
+ CloseComplete.prototype.typeId = 51;
- ParameterDescription.prototype.typeId = 116;
+ return CloseComplete;
- ParameterDescription.prototype.read = function(buffer) {
- var count, i;
+})(BackendMessage);
- count = buffer.readUInt16(0);
- return this.parameterTypes = (function() {
- var _i, _results;
+BackendMessage.ParameterDescription = (function(_super) {
+ __extends(ParameterDescription, _super);
- _results = [];
- for (i = _i = 0; 0 <= count ? _i < count : _i > count; i = 0 <= count ? ++_i : --_i) {
- _results.push(buffer.readUInt32(2 + i * 4));
- }
- return _results;
- })();
- };
+ function ParameterDescription() {
+ _ref9 = ParameterDescription.__super__.constructor.apply(this, arguments);
+ return _ref9;
+ }
- return ParameterDescription;
+ ParameterDescription.prototype.typeId = 116;
- })(BackendMessage);
+ ParameterDescription.prototype.read = function(buffer) {
+ var count, i;
- BackendMessage.ParseComplete = (function(_super) {
- __extends(ParseComplete, _super);
+ count = buffer.readUInt16(0);
+ return this.parameterTypes = (function() {
+ var _i, _results;
- function ParseComplete() {
- _ref10 = ParseComplete.__super__.constructor.apply(this, arguments);
- return _ref10;
- }
+ _results = [];
+ for (i = _i = 0; 0 <= count ? _i < count : _i > count; i = 0 <= count ? ++_i : --_i) {
+ _results.push(buffer.readUInt32(2 + i * 4));
+ }
+ return _results;
+ })();
+ };
- ParseComplete.prototype.typeId = 49;
+ return ParameterDescription;
- return ParseComplete;
+})(BackendMessage);
- })(BackendMessage);
+BackendMessage.ParseComplete = (function(_super) {
+ __extends(ParseComplete, _super);
- BackendMessage.ErrorResponse = (function(_super) {
- __extends(ErrorResponse, _super);
+ function ParseComplete() {
+ _ref10 = ParseComplete.__super__.constructor.apply(this, arguments);
+ return _ref10;
+ }
- function ErrorResponse() {
- _ref11 = ErrorResponse.__super__.constructor.apply(this, arguments);
- return _ref11;
- }
+ ParseComplete.prototype.typeId = 49;
- ErrorResponse.prototype.typeId = 69;
-
- ErrorResponse.prototype.fieldNames = {
- 83: 'Severity',
- 67: 'Code',
- 77: 'Message',
- 68: 'Detail',
- 72: 'Hint',
- 80: 'Position',
- 112: 'Internal position',
- 113: 'Internal query',
- 87: 'Where',
- 70: 'File',
- 76: 'Line',
- 82: 'Routine'
- };
-
- ErrorResponse.prototype.read = function(buffer) {
- var fieldCode, pos, value;
-
- this.information = {};
- fieldCode = buffer.readUInt8(0);
- pos = 1;
- while (fieldCode !== 0x00) {
- value = buffer.readZeroTerminatedString(pos);
- this.information[this.fieldNames[fieldCode] || fieldCode] = value;
- pos += Buffer.byteLength(value) + 1;
- fieldCode = buffer.readUInt8(pos);
- pos += 1;
- }
- return this.message = this.information['Message'];
- };
+ return ParseComplete;
+
+})(BackendMessage);
- return ErrorResponse;
+BackendMessage.ErrorResponse = (function(_super) {
+ __extends(ErrorResponse, _super);
- })(BackendMessage);
+ function ErrorResponse() {
+ _ref11 = ErrorResponse.__super__.constructor.apply(this, arguments);
+ return _ref11;
+ }
- BackendMessage.NoticeResponse = (function(_super) {
- __extends(NoticeResponse, _super);
+ ErrorResponse.prototype.typeId = 69;
+
+ ErrorResponse.prototype.fieldNames = {
+ 83: 'Severity',
+ 67: 'Code',
+ 77: 'Message',
+ 68: 'Detail',
+ 72: 'Hint',
+ 80: 'Position',
+ 112: 'Internal position',
+ 113: 'Internal query',
+ 87: 'Where',
+ 70: 'File',
+ 76: 'Line',
+ 82: 'Routine'
+ };
- function NoticeResponse() {
- _ref12 = NoticeResponse.__super__.constructor.apply(this, arguments);
- return _ref12;
+ ErrorResponse.prototype.read = function(buffer) {
+ var fieldCode, pos, value;
+
+ this.information = {};
+ fieldCode = buffer.readUInt8(0);
+ pos = 1;
+ while (fieldCode !== 0x00) {
+ value = buffer.readZeroTerminatedString(pos);
+ this.information[this.fieldNames[fieldCode] || fieldCode] = value;
+ pos += Buffer.byteLength(value) + 1;
+ fieldCode = buffer.readUInt8(pos);
+ pos += 1;
}
+ return this.message = this.information['Message'];
+ };
- NoticeResponse.prototype.typeId = 78;
+ return ErrorResponse;
- return NoticeResponse;
+})(BackendMessage);
- })(BackendMessage.ErrorResponse);
+BackendMessage.NoticeResponse = (function(_super) {
+ __extends(NoticeResponse, _super);
- BackendMessage.ReadyForQuery = (function(_super) {
- __extends(ReadyForQuery, _super);
+ function NoticeResponse() {
+ _ref12 = NoticeResponse.__super__.constructor.apply(this, arguments);
+ return _ref12;
+ }
- function ReadyForQuery() {
- _ref13 = ReadyForQuery.__super__.constructor.apply(this, arguments);
- return _ref13;
- }
+ NoticeResponse.prototype.typeId = 78;
- ReadyForQuery.prototype.typeId = 90;
+ return NoticeResponse;
- ReadyForQuery.prototype.read = function(buffer) {
- return this.transactionStatus = buffer.readUInt8(0);
- };
+})(BackendMessage.ErrorResponse);
- return ReadyForQuery;
+BackendMessage.ReadyForQuery = (function(_super) {
+ __extends(ReadyForQuery, _super);
- })(BackendMessage);
+ function ReadyForQuery() {
+ _ref13 = ReadyForQuery.__super__.constructor.apply(this, arguments);
+ return _ref13;
+ }
- BackendMessage.CopyInResponse = (function(_super) {
- __extends(CopyInResponse, _super);
+ ReadyForQuery.prototype.typeId = 90;
- function CopyInResponse() {
- _ref14 = CopyInResponse.__super__.constructor.apply(this, arguments);
- return _ref14;
- }
+ ReadyForQuery.prototype.read = function(buffer) {
+ return this.transactionStatus = buffer.readUInt8(0);
+ };
- CopyInResponse.prototype.typeId = 71;
+ return ReadyForQuery;
- CopyInResponse.prototype.read = function(buffer) {
- var i, numberOfFields, pos, _i, _results;
+})(BackendMessage);
- this.globalFormatType = buffer.readUInt8(0);
- this.fieldFormatTypes = [];
- numberOfFields = buffer.readUInt16(1);
- pos = 3;
- _results = [];
- for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
- this.fieldFormatTypes.push(buffer.readUInt8(pos));
- _results.push(pos += 1);
- }
- return _results;
- };
+BackendMessage.CopyInResponse = (function(_super) {
+ __extends(CopyInResponse, _super);
- return CopyInResponse;
+ function CopyInResponse() {
+ _ref14 = CopyInResponse.__super__.constructor.apply(this, arguments);
+ return _ref14;
+ }
- })(BackendMessage);
+ CopyInResponse.prototype.typeId = 71;
- BackendMessage.types = {};
+ CopyInResponse.prototype.read = function(buffer) {
+ var i, numberOfFields, pos, _i, _results;
- for (name in BackendMessage) {
- messageClass = BackendMessage[name];
- if (messageClass.prototype && (messageClass.prototype.typeId != null)) {
- messageClass.prototype.event = name;
- BackendMessage.types[messageClass.prototype.typeId] = messageClass;
+ this.globalFormatType = buffer.readUInt8(0);
+ this.fieldFormatTypes = [];
+ numberOfFields = buffer.readUInt16(1);
+ pos = 3;
+ _results = [];
+ for (i = _i = 0; 0 <= numberOfFields ? _i < numberOfFields : _i > numberOfFields; i = 0 <= numberOfFields ? ++_i : --_i) {
+ this.fieldFormatTypes.push(buffer.readUInt8(pos));
+ _results.push(pos += 1);
}
- }
+ return _results;
+ };
- BackendMessage.fromBuffer = function(buffer) {
- var message, typeId;
+ return CopyInResponse;
- typeId = buffer.readUInt8(0);
- messageClass = BackendMessage.types[typeId];
- if (messageClass != null) {
- message = new messageClass(buffer.slice(5));
- return message;
- } else {
- throw new Error("Unknown message type: " + typeId);
- }
- };
+})(BackendMessage);
+
+BackendMessage.types = {};
- module.exports = BackendMessage;
+for (name in BackendMessage) {
+ messageClass = BackendMessage[name];
+ if (messageClass.prototype && (messageClass.prototype.typeId != null)) {
+ messageClass.prototype.event = name;
+ BackendMessage.types[messageClass.prototype.typeId] = messageClass;
+ }
+}
+
+BackendMessage.fromBuffer = function(buffer) {
+ var message, typeId;
+
+ typeId = buffer.readUInt8(0);
+ messageClass = BackendMessage.types[typeId];
+ if (messageClass != null) {
+ message = new messageClass(buffer.slice(5));
+ return message;
+ } else {
+ throw new Error("Unknown message type: " + typeId);
+ }
+};
-}).call(this);
+module.exports = BackendMessage;
View
217 lib/buffer.js
@@ -1,111 +1,108 @@
// Generated by CoffeeScript 1.6.2
-(function() {
- var Buffer, _base, _base1, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
-
- Buffer = require('buffer').Buffer;
-
- if ((_ref = (_base = Buffer.prototype).writeUInt8) == null) {
- _base.writeUInt8 = function(number, offset) {
- this[offset] = number & 0xff;
- return void 0;
- };
- }
-
- if ((_ref1 = (_base1 = Buffer.prototype).writeUInt16) == null) {
- _base1.writeUInt16 = function(number, offset, endian) {
- return this._writeUInt(2, number, offset, endian);
- };
- }
-
- if ((_ref2 = (_base2 = Buffer.prototype).writeUInt32) == null) {
- _base2.writeUInt32 = function(number, offset, endian) {
- return this._writeUInt(4, number, offset, endian);
- };
- }
-
- if ((_ref3 = (_base3 = Buffer.prototype)._writeUInt) == null) {
- _base3._writeUInt = function(bytes, number, offset, endian) {
- var currentOffset, encodingPositions, index, _i, _j, _k, _len, _ref4, _ref5, _results, _results1;
-
- encodingPositions = endian === 'little' ? (function() {
- _results = [];
- for (var _i = offset, _ref4 = offset + bytes - 1; offset <= _ref4 ? _i <= _ref4 : _i >= _ref4; offset <= _ref4 ? _i++ : _i--){ _results.push(_i); }
- return _results;
- }).apply(this) : (function() {
- _results1 = [];
- for (var _j = _ref5 = offset + bytes - 1; _ref5 <= offset ? _j <= offset : _j >= offset; _ref5 <= offset ? _j++ : _j--){ _results1.push(_j); }
- return _results1;
- }).apply(this);
- for (index = _k = 0, _len = encodingPositions.length; _k < _len; index = ++_k) {
- currentOffset = encodingPositions[index];
- this[currentOffset] = (number >> (8 * index)) & 0xff;
- }
- return void 0;
- };
- }
-
- if ((_ref4 = (_base4 = Buffer.prototype).writeZeroTerminatedString) == null) {
- _base4.writeZeroTerminatedString = function(str, offset, encoding) {
- var written;
-
- written = this.write(str, offset, null, encoding);
- this.writeUInt8(0, offset + written);
- return written + 1;
- };
- }
-
- if ((_ref5 = (_base5 = Buffer.prototype).readUInt8) == null) {
- _base5.readUInt8 = function(offset) {
- return this[offset];
- };
- }
-
- if ((_ref6 = (_base6 = Buffer.prototype).readUInt16) == null) {
- _base6.readUInt16 = function(offset, endian) {
- return this._readUInt(2, offset, endian);
- };
- }
-
- if ((_ref7 = (_base7 = Buffer.prototype).readUInt32) == null) {
- _base7.readUInt32 = function(offset, endian) {
- return this._readUInt(4, offset, endian);
- };
- }
-
- if ((_ref8 = (_base8 = Buffer.prototype)._readUInt) == null) {
- _base8._readUInt = function(bytes, offset, endian) {
- var currentOffset, encodingPositions, index, number, _i, _j, _k, _len, _ref10, _ref9, _results, _results1;
-
- encodingPositions = endian === 'little' ? (function() {
- _results = [];
- for (var _i = offset, _ref9 = offset + bytes - 1; offset <= _ref9 ? _i <= _ref9 : _i >= _ref9; offset <= _ref9 ? _i++ : _i--){ _results.push(_i); }
- return _results;
- }).apply(this) : (function() {
- _results1 = [];
- for (var _j = _ref10 = offset + bytes - 1; _ref10 <= offset ? _j <= offset : _j >= offset; _ref10 <= offset ? _j++ : _j--){ _results1.push(_j); }
- return _results1;
- }).apply(this);
- number = 0;
- for (index = _k = 0, _len = encodingPositions.length; _k < _len; index = ++_k) {
- currentOffset = encodingPositions[index];
- number = (this[currentOffset] << (index * 8)) | number;
- }
- return number;
- };
- }
-
- if ((_ref9 = (_base9 = Buffer.prototype).readZeroTerminatedString) == null) {
- _base9.readZeroTerminatedString = function(offset, encoding) {
- var endIndex;
-
- endIndex = offset;
- while (endIndex < this.length && this[endIndex] !== 0x00) {
- endIndex++;
- }
- return this.toString('ascii', offset, endIndex);
- };
- }
-
- exports.Buffer = Buffer;
-
-}).call(this);
+var Buffer, _base, _base1, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
+
+Buffer = require('buffer').Buffer;
+
+if ((_ref = (_base = Buffer.prototype).writeUInt8) == null) {
+ _base.writeUInt8 = function(number, offset) {
+ this[offset] = number & 0xff;
+ return void 0;
+ };
+}
+
+if ((_ref1 = (_base1 = Buffer.prototype).writeUInt16) == null) {
+ _base1.writeUInt16 = function(number, offset, endian) {
+ return this._writeUInt(2, number, offset, endian);
+ };
+}
+
+if ((_ref2 = (_base2 = Buffer.prototype).writeUInt32) == null) {
+ _base2.writeUInt32 = function(number, offset, endian) {
+ return this._writeUInt(4, number, offset, endian);
+ };
+}
+
+if ((_ref3 = (_base3 = Buffer.prototype)._writeUInt) == null) {
+ _base3._writeUInt = function(bytes, number, offset, endian) {
+ var currentOffset, encodingPositions, index, _i, _j, _k, _len, _ref4, _ref5, _results, _results1;
+
+ encodingPositions = endian === 'little' ? (function() {
+ _results = [];
+ for (var _i = offset, _ref4 = offset + bytes - 1; offset <= _ref4 ? _i <= _ref4 : _i >= _ref4; offset <= _ref4 ? _i++ : _i--){ _results.push(_i); }
+ return _results;
+ }).apply(this) : (function() {
+ _results1 = [];
+ for (var _j = _ref5 = offset + bytes - 1; _ref5 <= offset ? _j <= offset : _j >= offset; _ref5 <= offset ? _j++ : _j--){ _results1.push(_j); }
+ return _results1;
+ }).apply(this);
+ for (index = _k = 0, _len = encodingPositions.length; _k < _len; index = ++_k) {
+ currentOffset = encodingPositions[index];
+ this[currentOffset] = (number >> (8 * index)) & 0xff;
+ }
+ return void 0;
+ };
+}
+
+if ((_ref4 = (_base4 = Buffer.prototype).writeZeroTerminatedString) == null) {
+ _base4.writeZeroTerminatedString = function(str, offset, encoding) {
+ var written;
+
+ written = this.write(str, offset, null, encoding);
+ this.writeUInt8(0, offset + written);
+ return written + 1;
+ };
+}
+
+if ((_ref5 = (_base5 = Buffer.prototype).readUInt8) == null) {
+ _base5.readUInt8 = function(offset) {
+ return this[offset];
+ };
+}
+
+if ((_ref6 = (_base6 = Buffer.prototype).readUInt16) == null) {
+ _base6.readUInt16 = function(offset, endian) {
+ return this._readUInt(2, offset, endian);
+ };
+}
+
+if ((_ref7 = (_base7 = Buffer.prototype).readUInt32) == null) {
+ _base7.readUInt32 = function(offset, endian) {
+ return this._readUInt(4, offset, endian);
+ };
+}
+
+if ((_ref8 = (_base8 = Buffer.prototype)._readUInt) == null) {
+ _base8._readUInt = function(bytes, offset, endian) {
+ var currentOffset, encodingPositions, index, number, _i, _j, _k, _len, _ref10, _ref9, _results, _results1;
+
+ encodingPositions = endian === 'little' ? (function() {
+ _results = [];
+ for (var _i = offset, _ref9 = offset + bytes - 1; offset <= _ref9 ? _i <= _ref9 : _i >= _ref9; offset <= _ref9 ? _i++ : _i--){ _results.push(_i); }
+ return _results;
+ }).apply(this) : (function() {
+ _results1 = [];
+ for (var _j = _ref10 = offset + bytes - 1; _ref10 <= offset ? _j <= offset : _j >= offset; _ref10 <= offset ? _j++ : _j--){ _results1.push(_j); }
+ return _results1;
+ }).apply(this);
+ number = 0;
+ for (index = _k = 0, _len = encodingPositions.length; _k < _len; index = ++_k) {
+ currentOffset = encodingPositions[index];
+ number = (this[currentOffset] << (index * 8)) | number;
+ }
+ return number;
+ };
+}
+
+if ((_ref9 = (_base9 = Buffer.prototype).readZeroTerminatedString) == null) {
+ _base9.readZeroTerminatedString = function(offset, encoding) {
+ var endIndex;
+
+ endIndex = offset;
+ while (endIndex < this.length && this[endIndex] !== 0x00) {
+ endIndex++;
+ }
+ return this.toString('ascii', offset, endIndex);
+ };
+}
+
+exports.Buffer = Buffer;
View
783 lib/connection.js
@@ -1,452 +1,449 @@
// Generated by CoffeeScript 1.6.2
-(function() {
- var Authentication, BackendMessage, Connection, EventEmitter, FrontendMessage, Query, net, util,
- __hasProp = {}.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+var Authentication, BackendMessage, Connection, EventEmitter, FrontendMessage, Query, net, util,
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
- util = require('util');
+util = require('util');
- net = require('net');
+net = require('net');
- EventEmitter = require('events').EventEmitter;
+EventEmitter = require('events').EventEmitter;
- FrontendMessage = require('./frontend_message');
+FrontendMessage = require('./frontend_message');
- BackendMessage = require('./backend_message');
+BackendMessage = require('./backend_message');
- Authentication = require('./authentication');
+Authentication = require('./authentication');
- Query = require('./query');
+Query = require('./query');
- Connection = (function(_super) {
- __extends(Connection, _super);
+Connection = (function(_super) {
+ __extends(Connection, _super);
- function Connection(connectionOptions) {
- var _base, _base1, _base2, _ref, _ref1, _ref2;
+ function Connection(connectionOptions) {
+ var _base, _base1, _base2, _ref, _ref1, _ref2;
- this.connectionOptions = connectionOptions;
- if ((_ref = (_base = this.connectionOptions).host) == null) {
- _base.host = 'localhost';
- }
- if ((_ref1 = (_base1 = this.connectionOptions).port) == null) {
- _base1.port = 5433;
- }
- if ((_ref2 = (_base2 = this.connectionOptions).ssl) == null) {
- _base2.ssl = 'optional';
- }
- this.connected = false;
- this.busy = true;
- this.queue = [];
- this.parameters = {};
- this.key = null;
- this.pid = null;
- this.transactionStatus = null;
- this.incomingData = new Buffer(0);
+ this.connectionOptions = connectionOptions;
+ if ((_ref = (_base = this.connectionOptions).host) == null) {
+ _base.host = 'localhost';
}
-
- Connection.prototype.connect = function(callback) {
- var initialErrorHandler,
- _this = this;
-
- this.connectedCallback = callback;
- this.connection = net.createConnection(this.connectionOptions.port, this.connectionOptions.host);
- initialErrorHandler = function(err) {
- if (_this.connectedCallback) {
- return _this.connectedCallback(err.message);
- } else {
- return _this.emit('error', err);
- }
- };
- this.connection.on('error', initialErrorHandler);
- return this.connection.on('connect', function() {
- _this.connection.removeListener('error', initialErrorHandler);
- _this.connected = true;
- _this._bindEventListeners();
- if (_this.connectionOptions.ssl) {
- _this._writeMessage(new FrontendMessage.SSLRequest);
- return _this.connection.once('data', function(buffer) {
- var conn, err, sslOptions;
-
- if ('S' === buffer.toString('utf-8')) {
- sslOptions = {
- key: _this.connectionOptions.sslKey,
- cert: _this.connectionOptions.sslCert,
- ca: _this.connectionOptions.sslCA
- };
- return conn = require('./starttls')(_this.connection, sslOptions, function() {
- var err;
-
- if (!conn.authorized && _this.connectionOptions.ssl === 'verified') {
- conn.end();
- _this.disconnect();
- err = new Error(conn.authorizationError);
- if (_this.connectedCallback) {
- return _this.connectedCallback(err.message);
- } else {
- return _this.emit('error', err);
- }
+ if ((_ref1 = (_base1 = this.connectionOptions).port) == null) {
+ _base1.port = 5433;
+ }
+ if ((_ref2 = (_base2 = this.connectionOptions).ssl) == null) {
+ _base2.ssl = 'optional';
+ }
+ this.connected = false;
+ this.busy = true;
+ this.queue = [];
+ this.parameters = {};
+ this.key = null;
+ this.pid = null;
+ this.transactionStatus = null;
+ this.incomingData = new Buffer(0);
+ }
+
+ Connection.prototype.connect = function(callback) {
+ var initialErrorHandler,
+ _this = this;
+
+ this.connectedCallback = callback;
+ this.connection = net.createConnection(this.connectionOptions.port, this.connectionOptions.host);
+ initialErrorHandler = function(err) {
+ if (_this.connectedCallback) {
+ return _this.connectedCallback(err.message);
+ } else {
+ return _this.emit('error', err);
+ }
+ };
+ this.connection.on('error', initialErrorHandler);
+ return this.connection.on('connect', function() {
+ _this.connection.removeListener('error', initialErrorHandler);
+ _this.connected = true;
+ _this._bindEventListeners();
+ if (_this.connectionOptions.ssl) {
+ _this._writeMessage(new FrontendMessage.SSLRequest);
+ return _this.connection.once('data', function(buffer) {
+ var conn, err, sslOptions;
+
+ if ('S' === buffer.toString('utf-8')) {
+ sslOptions = {
+ key: _this.connectionOptions.sslKey,
+ cert: _this.connectionOptions.sslCert,
+ ca: _this.connectionOptions.sslCA
+ };
+ return conn = require('./starttls')(_this.connection, sslOptions, function() {
+ var err;
+
+ if (!conn.authorized && _this.connectionOptions.ssl === 'verified') {
+ conn.end();
+ _this.disconnect();
+ err = new Error(conn.authorizationError);
+ if (_this.connectedCallback) {
+ return _this.connectedCallback(err.message);
} else {
- if (!conn.authorized) {
- _this.emit('warn', conn.authorizationError);
- }
- _this.connection = conn;
- _this._bindEventListeners();
- return _this._handshake();
+ return _this.emit('error', err);
}
- });
- } else if (_this.connectionOptions.ssl === "optional") {
- return _this._handshake();
- } else {
- err = new Error("The server does not support SSL connection");
- if (_this.connectedCallback) {
- return _this.connectedCallback(err.message);
} else {
- return _this.emit('error', err);
+ if (!conn.authorized) {
+ _this.emit('warn', conn.authorizationError);
+ }
+ _this.connection = conn;
+ _this._bindEventListeners();
+ return _this._handshake();
}
+ });
+ } else if (_this.connectionOptions.ssl === "optional") {
+ return _this._handshake();
+ } else {
+ err = new Error("The server does not support SSL connection");
+ if (_this.connectedCallback) {
+ return _this.connectedCallback(err.message);
+ } else {
+ return _this.emit('error', err);
}
- });
- } else {
- return _this._handshake();
- }
- });
- };
-
- Connection.prototype._bindEventListeners = function() {
- this.connection.on('close', this._onClose.bind(this));
- this.connection.on('error', this._onError.bind(this));
- return this.connection.on('timeout', this._onTimeout.bind(this));
- };
-
- Connection.prototype.disconnect = function() {
- this._writeMessage(new FrontendMessage.Terminate());
- return this.connection.end();
- };
-
- Connection.prototype.isSSL = function() {
- return (this.connection.pair != null) && (this.connection.encrypted != null);
- };
-
- Connection.prototype._scheduleJob = function(job) {
- if (this.busy) {
- this.queue.push(job);
- this.emit('queuejob', job);
- } else {
- this._runJob(job);
- }
- return job;
- };
-
- Connection.prototype._runJob = function(job) {
- if (!this.connected) {
- throw "Connection is closed";
- }
- if (this.busy) {
- throw "Connection is busy";
- }
- this.busy = true;
- this.currentJob = job;
- job.run();
- return job;
- };
-
- Connection.prototype._processJobQueue = function() {
- if (this.queue.length > 0) {
- return this._runJob(this.queue.shift());
+ }
+ });
} else {
- return this.emit('ready', this);
+ return _this._handshake();
}
- };
+ });
+ };
+
+ Connection.prototype._bindEventListeners = function() {
+ this.connection.on('close', this._onClose.bind(this));
+ this.connection.on('error', this._onError.bind(this));
+ return this.connection.on('timeout', this._onTimeout.bind(this));
+ };
+
+ Connection.prototype.disconnect = function() {
+ this._writeMessage(new FrontendMessage.Terminate());
+ return this.connection.end();
+ };
+
+ Connection.prototype.isSSL = function() {
+ return (this.connection.pair != null) && (this.connection.encrypted != null);
+ };
+
+ Connection.prototype._scheduleJob = function(job) {
+ if (this.busy) {
+ this.queue.push(job);
+ this.emit('queuejob', job);
+ } else {
+ this._runJob(job);
+ }
+ return job;
+ };
- Connection.prototype.query = function(sql, callback) {
- return this._scheduleJob(new Query(this, sql, callback));
- };
+ Connection.prototype._runJob = function(job) {
+ if (!this.connected) {
+ throw "Connection is closed";
+ }
+ if (this.busy) {
+ throw "Connection is busy";
+ }
+ this.busy = true;
+ this.currentJob = job;
+ job.run();
+ return job;
+ };
+
+ Connection.prototype._processJobQueue = function() {
+ if (this.queue.length > 0) {
+ return this._runJob(this.queue.shift());
+ } else {
+ return this.emit('ready', this);
+ }
+ };
- Connection.prototype._queryDirect = function(sql, callback) {
- return this._runJob(new Query(this, sql, callback));
- };
+ Connection.prototype.query = function(sql, callback) {
+ return this._scheduleJob(new Query(this, sql, callback));
+ };
- Connection.prototype.copy = function(sql, source, callback) {
- var q;
+ Connection.prototype._queryDirect = function(sql, callback) {
+ return this._runJob(new Query(this, sql, callback));
+ };
- q = new Query(this, sql, callback);
- q.copyInSource = source;
- return this._scheduleJob(q);
- };
+ Connection.prototype.copy = function(sql, source, callback) {
+ var q;
- Connection.prototype._handshake = function() {
- var authenticationFailureHandler, authenticationHandler,
- _this = this;
+ q = new Query(this, sql, callback);
+ q.copyInSource = source;
+ return this._scheduleJob(q);
+ };
- authenticationFailureHandler = function(err) {
- if (_this.connectedCallback) {
- return _this.connectedCallback(err.message);
- } else {
- return _this.emit('error', err);
- }
- };
- authenticationHandler = function(msg) {
- switch (msg.method) {
- case Authentication.methods.OK:
- return _this.once('ReadyForQuery', function(msg) {
- _this.removeListener('ErrorResponse', authenticationFailureHandler);
- return _this._initializeConnection();
- });
- case Authentication.methods.CLEARTEXT_PASSWORD:
- case Authentication.methods.MD5_PASSWORD:
- _this._writeMessage(new FrontendMessage.Password(_this.connectionOptions.password, msg.method, {
- salt: msg.salt,
- user: _this.connectionOptions.user
- }));
- return _this.once('Authentication', authenticationHandler);
- default:
- throw new Error("Autentication method " + msg.method + " not supported.");
- }
- };
- this.connection.on('data', this._onData.bind(this));
- this._writeMessage(new FrontendMessage.Startup(this.connectionOptions.user, this.connectionOptions.database));
- this.once('ErrorResponse', authenticationFailureHandler);
- this.once('Authentication', authenticationHandler);
- this.on('ParameterStatus', function(msg) {
- return _this.parameters[msg.name] = msg.value;
- });
- this.on('BackendKeyData', function(msg) {
- var _ref;
-
- return _ref = [msg.pid, msg.key], _this.pid = _ref[0], _this.key = _ref[1], _ref;
- });
- return this.on('ReadyForQuery', function(msg) {
- _this.busy = false;
- _this.currentJob = false;
- return _this.transactionStatus = msg.transactionStatus;
- });
- };
+ Connection.prototype._handshake = function() {
+ var authenticationFailureHandler, authenticationHandler,
+ _this = this;
- Connection.prototype._initializeConnection = function() {
- var chain, initializer, initializers, _i, _len;
-
- initializers = [];
- if (!this.connectionOptions.skipInitialization) {
- if (this.connectionOptions.interruptible) {
- initializers.push(this._initializeInterrupt);
- }
- if (this.connectionOptions.role != null) {
- initializers.push(this._initializeRoles);
- }
- if (this.connectionOptions.searchPath != null) {
- initializers.push(this._initializeSearchPath);
- }
- if (this.connectionOptions.timezone != null) {
- initializers.push(this._initializeTimezone);
- }
- if (this.connectionOptions.initializer != null) {
- initializers.push(this.connectionOptions.initializer);
- }
- }
- chain = this._initializationSuccess.bind(this);
- for (_i = 0, _len = initializers.length; _i < _len; _i++) {
- initializer = initializers[_i];
- chain = initializer.bind(this, chain, this._initializationFailure.bind(this));
+ authenticationFailureHandler = function(err) {
+ if (_this.connectedCallback) {
+ return _this.connectedCallback(err.message);
+ } else {
+ return _this.emit('error', err);
}
- return chain();
- };
-
- Connection.prototype._initializeRoles = function(next, fail) {
- var roles,
- _this = this;
-
- roles = this.connectionOptions.role instanceof Array ? this.connectionOptions.role : [this.connectionOptions.role];
- return this._queryDirect("SET ROLE " + (roles.join(', ')), function(err, result) {
- if (err != null) {
- return fail(err);
- } else {
- return next();
- }
- });
};
-
- Connection.prototype._initializeSearchPath = function(next, fail) {
- var searchPath,
- _this = this;
-
- searchPath = this.connectionOptions.searchPath instanceof Array ? this.connectionOptions.searchPath : [this.connectionOptions.searchPath];
- return this._queryDirect("SET SEARCH_PATH TO " + (searchPath.join(', ')), function(err, result) {
- if (err != null) {
- return fail(err);
- } else {
- return next();
- }
- });
- };
-
- Connection.prototype._initializeTimezone = function(next, fail) {
- var _this = this;
-
- return this._queryDirect("SET TIMEZONE TO '" + this.connectionOptions.timezone + "'", function(err, result) {
- if (err != null) {
- return fail(err);
- } else {
- return next();
- }
- });
+ authenticationHandler = function(msg) {
+ switch (msg.method) {
+ case Authentication.methods.OK:
+ return _this.once('ReadyForQuery', function(msg) {
+ _this.removeListener('ErrorResponse', authenticationFailureHandler);
+ return _this._initializeConnection();
+ });
+ case Authentication.methods.CLEARTEXT_PASSWORD:
+ case Authentication.methods.MD5_PASSWORD:
+ _this._writeMessage(new FrontendMessage.Password(_this.connectionOptions.password, msg.method, {
+ salt: msg.salt,
+ user: _this.connectionOptions.user
+ }));
+ return _this.once('Authentication', authenticationHandler);
+ default:
+ throw new Error("Autentication method " + msg.method + " not supported.");
+ }
};
+ this.connection.on('data', this._onData.bind(this));
+ this._writeMessage(new FrontendMessage.Startup(this.connectionOptions.user, this.connectionOptions.database));
+ this.once('ErrorResponse', authenticationFailureHandler);
+ this.once('Authentication', authenticationHandler);
+ this.on('ParameterStatus', function(msg) {
+ return _this.parameters[msg.name] = msg.value;
+ });
+ this.on('BackendKeyData', function(msg) {
+ var _ref;
+
+ return _ref = [msg.pid, msg.key], _this.pid = _ref[0], _this.key = _ref[1], _ref;
+ });
+ return this.on('ReadyForQuery', function(msg) {
+ _this.busy = false;
+ _this.currentJob = false;
+ return _this.transactionStatus = msg.transactionStatus;
+ });
+ };
+
+ Connection.prototype._initializeConnection = function() {
+ var chain, initializer, initializers, _i, _len;
+
+ initializers = [];
+ if (!this.connectionOptions.skipInitialization) {
+ if (this.connectionOptions.interruptible) {
+ initializers.push(this._initializeInterrupt);
+ }
+ if (this.connectionOptions.role != null) {
+ initializers.push(this._initializeRoles);
+ }
+ if (this.connectionOptions.searchPath != null) {
+ initializers.push(this._initializeSearchPath);
+ }
+ if (this.connectionOptions.timezone != null) {
+ initializers.push(this._initializeTimezone);
+ }
+ if (this.connectionOptions.initializer != null) {
+ initializers.push(this.connectionOptions.initializer);
+ }
+ }
+ chain = this._initializationSuccess.bind(this);
+ for (_i = 0, _len = initializers.length; _i < _len; _i++) {
+ initializer = initializers[_i];
+ chain = initializer.bind(this, chain, this._initializationFailure.bind(this));
+ }
+ return chain();
+ };
- Connection.prototype._initializeInterrupt = function(next, fail) {
- var _this = this;
+ Connection.prototype._initializeRoles = function(next, fail) {
+ var roles,
+ _this = this;
- return this._queryDirect("SELECT session_id FROM v_monitor.current_session", function(err, result) {
- if (err != null) {
- fail(err);
- }
- _this.sessionID = result.theValue();
+ roles = this.connectionOptions.role instanceof Array ? this.connectionOptions.role : [this.connectionOptions.role];
+ return this._queryDirect("SET ROLE " + (roles.join(', ')), function(err, result) {
+ if (err != null) {
+ return fail(err);
+ } else {
return next();
- });
- };
-
- Connection.prototype._initializationSuccess = function() {
- this.on('ReadyForQuery', this._processJobQueue.bind(this));
- this._processJobQueue();
- if (this.connectedCallback) {
- return this.connectedCallback(null, this);
}
- };
+ });
+ };
+
+ Connection.prototype._initializeSearchPath = function(next, fail) {
+ var searchPath,
+ _this = this;
- Connection.prototype._initializationFailure = function(err) {
- if (this.connectedCallback) {
- return this.connectedCallback(err);
+ searchPath = this.connectionOptions.searchPath instanceof Array ? this.connectionOptions.searchPath : [this.connectionOptions.searchPath];
+ return this._queryDirect("SET SEARCH_PATH TO " + (searchPath.join(', ')), function(err, result) {
+ if (err != null) {
+ return fail(err);
} else {
- return this.emit('error', err);
+ return next();
}
- };
+ });
+ };
- Connection.prototype._onData = function(buffer) {
- var bufferedData, message, size, _results;
+ Connection.prototype._initializeTimezone = function(next, fail) {
+ var _this = this;
- if (this.incomingData.length === 0) {
- this.incomingData = buffer;
+ return this._queryDirect("SET TIMEZONE TO '" + this.connectionOptions.timezone + "'", function(err, result) {
+ if (err != null) {
+ return fail(err);
} else {
- bufferedData = new Buffer(this.incomingData.length + buffer.length);
- this.incomingData.copy(bufferedData);
- buffer.copy(bufferedData, this.incomingData.length);
- this.incomingData = bufferedData;
- }
- size = this.incomingData.readUInt32(1);
- _results = [];
- while (this.incomingData.length >= 5 && size + 1 <= this.incomingData.length) {
- message = BackendMessage.fromBuffer(this.incomingData.slice(0, size + 1));
- if (this.debug) {
- console.log('<=', message.event, message);
- }
- this.emit('message', message);
- this.emit(message.event, message);
- this.incomingData = this.incomingData.slice(size + 1);
- _results.push(size = this.incomingData.readUInt32(1));
+ return next();
}
- return _results;
- };
+ });
+ };
- Connection.prototype._onClose = function(error) {
- if (this.currentJob) {
- this.currentJob.onConnectionError("The connection was closed.");
- }
- this.connected = false;
- return this.emit('close', error);
- };
+ Connection.prototype._initializeInterrupt = function(next, fail) {
+ var _this = this;
- Connection.prototype._onTimeout = function() {
- if (this.currentJob) {
- this.currentJob.onConnectionError("The connection timed out closed.");
+ return this._queryDirect("SELECT session_id FROM v_monitor.current_session", function(err, result) {
+ if (err != null) {
+ fail(err);
}
- return this.emit('timeout');
- };
-
- Connection.prototype._onError = function(exception) {
- return this.emit('error', exception);
- };
+ _this.sessionID = result.theValue();
+ return next();
+ });
+ };
+
+ Connection.prototype._initializationSuccess = function() {
+ this.on('ReadyForQuery', this._processJobQueue.bind(this));
+ this._processJobQueue();
+ if (this.connectedCallback) {
+ return this.connectedCallback(null, this);
+ }
+ };
- Connection.prototype._writeMessage = function(msg, callback) {
+ Connection.prototype._initializationFailure = function(err) {
+ if (this.connectedCallback) {
+ return this.connectedCallback(err);
+ } else {
+ return this.emit('error', err);
+ }
+ };
+
+ Connection.prototype._onData = function(buffer) {
+ var bufferedData, message, size, _results;
+
+ if (this.incomingData.length === 0) {
+ this.incomingData = buffer;
+ } else {
+ bufferedData = new Buffer(this.incomingData.length + buffer.length);
+ this.incomingData.copy(bufferedData);
+ buffer.copy(bufferedData, this.incomingData.length);
+ this.incomingData = bufferedData;
+ }
+ size = this.incomingData.readUInt32(1);
+ _results = [];
+ while (this.incomingData.length >= 5 && size + 1 <= this.incomingData.length) {
+ message = BackendMessage.fromBuffer(this.incomingData.slice(0, size + 1));
if (this.debug) {
- console.log('=>', msg.__proto__.constructor.name, msg);
+ console.log('<=', message.event, message);
}
- return this.connection.write(msg.toBuffer(), null, callback);
- };
+ this.emit('message', message);
+ this.emit(message.event, message);
+ this.incomingData = this.incomingData.slice(size + 1);
+ _results.push(size = this.incomingData.readUInt32(1));
+ }
+ return _results;
+ };
- Connection.prototype.isInterruptible = function() {
- return this.sessionID != null;
- };
+ Connection.prototype._onClose = function(error) {
+ if (this.currentJob) {
+ this.currentJob.onConnectionError("The connection was closed.");
+ }
+ this.connected = false;
+ return this.emit('close', error);
+ };
- Connection.prototype._interruptConnection = function(cb) {
- var bareClient, bareConnectionOptions;
+ Connection.prototype._onTimeout = function() {
+ if (this.currentJob) {
+ this.currentJob.onConnectionError("The connection timed out closed.");
+ }
+ return this.emit('timeout');
+ };
- if (this.sessionID != null) {
- bareConnectionOptions = {
- skipInitialization: true
- };
- bareConnectionOptions.__proto__ = this.connectionOptions;
- bareClient = new Connection(bareConnectionOptions);
- return bareClient.connect(cb);
- } else {
- return cb("Cannot interrupt connection! It's not initialized as interruptible.", null);
- }
- };
+ Connection.prototype._onError = function(exception) {
+ return this.emit('error', exception);
+ };
- Connection.prototype._success = function(err, cb) {
- if (err != null) {
- if (cb != null) {
- cb(err);
- } else {
- this.emit('error', new Error(err));
- }
- return false;
+ Connection.prototype._writeMessage = function(msg, callback) {
+ if (this.debug) {
+ console.log('=>', msg.__proto__.constructor.name, msg);
+ }
+ return this.connection.write(msg.toBuffer(), null, callback);
+ };
+
+ Connection.prototype.isInterruptible = function() {
+ return this.sessionID != null;
+ };
+
+ Connection.prototype._interruptConnection = function(cb) {
+ var bareClient, bareConnectionOptions;
+
+ if (this.sessionID != null) {
+ bareConnectionOptions = {
+ skipInitialization: true
+ };
+ bareConnectionOptions.__proto__ = this.connectionOptions;
+ bareClient = new Connection(bareConnectionOptions);
+ return bareClient.connect(cb);
+ } else {
+ return cb("Cannot interrupt connection! It's not initialized as interruptible.", null);
+ }
+ };
+
+ Connection.prototype._success = function(err, cb) {
+ if (err != null) {
+ if (cb != null) {
+ cb(err);
} else {
- return true;
+ this.emit('error', new Error(err));
}
- };
+ return false;
+ } else {
+ return true;
+ }
+ };
+
+ Connection.prototype.interruptSession = function(cb) {
+ var _this = this;
+
+ return this._interruptConnection(function(err, conn) {
+ if (_this._success(err, cb)) {
+ return conn.query("SELECT CLOSE_SESSION('" + _this.sessionID + "')", function(err, rs) {
+ conn.disconnect();
+ if (_this._success(err, cb) && (cb != null)) {
+ return cb(null, rs.theValue());
+ }
+ });
+ }
+ });
+ };
- Connection.prototype.interruptSession = function(cb) {
- var _this = this;
+ Connection.prototype.interruptStatement = function(cb) {
+ var _this = this;
- return this._interruptConnection(function(err, conn) {
- if (_this._success(err, cb)) {
- return conn.query("SELECT CLOSE_SESSION('" + _this.sessionID + "')", function(err, rs) {
- conn.disconnect();
- if (_this._success(err, cb) && (cb != null)) {
- return cb(null, rs.theValue());
- }
- });
- }
- });
- };
+ return this._interruptConnection(function(err, conn) {
+ if (_this._success(err, cb)) {
+ return conn.query("SELECT statement_id FROM v_monitor.sessions WHERE session_id = '" + _this.sessionID + "'", function(err, rs) {
+ var statementID;
- Connection.prototype.interruptStatement = function(cb) {
- var _this = this;
-
- return this._interruptConnection(function(err, conn) {
- if (_this._success(err, cb)) {
- return conn.query("SELECT statement_id FROM v_monitor.sessions WHERE session_id = '" + _this.sessionID + "'", function(err, rs) {
- var statementID;
-
- if (!_this._success(err, cb)) {
- return conn.disconnect();
- } else if (rs.getLength() === 1 && (statementID = rs.theValue())) {
- return bareClient.query("SELECT INTERRUPT_STATEMENT('" + _this.sessionID + "', statementID)", function(err, rs) {
- conn.disconnect();
- if (_this._success(err, cb) && (cb != null)) {
- return cb(null, rs.theValue());
- }
- });
- } else {
+ if (!_this._success(err, cb)) {
+ return conn.disconnect();
+ } else if (rs.getLength() === 1 && (statementID = rs.theValue())) {
+ return bareClient.query("SELECT INTERRUPT_STATEMENT('" + _this.sessionID + "', statementID)", function(err, rs) {
conn.disconnect();
- return _this._success("Session " + _this.sessionID + " is not running a statement at the moment.", cb);
- }
- });
- }
- });
- };
-
- return Connection;
+ if (_this._success(err, cb) && (cb != null)) {
+ return cb(null, rs.theValue());
+ }
+ });
+ } else {
+ conn.disconnect();
+ return _this._success("Session " + _this.sessionID + " is not running a statement at the moment.", cb);
+ }
+ });
+ }
+ });
+ };
- })(EventEmitter);
+ return Connection;
- module.exports = Connection;
+})(EventEmitter);
-}).call(this);
+module.exports = Connection;
View
741 lib/frontend_message.js
@@ -1,494 +1,491 @@
// Generated by CoffeeScript 1.6.2
-(function() {
- var Authentication, Buffer, FrontendMessage, _ref, _ref1, _ref2, _ref3, _ref4,
- __hasProp = {}.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+var Authentication, Buffer, FrontendMessage, _ref, _ref1, _ref2, _ref3, _ref4,
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
- Authentication = require('./authentication');
+Authentication = require('./authentication');
- Buffer = require('./buffer').Buffer;
+Buffer = require('./buffer').Buffer;
- FrontendMessage = (function() {
- function FrontendMessage() {}
+FrontendMessage = (function() {
+ function FrontendMessage() {}
- FrontendMessage.prototype.typeId = null;
+ FrontendMessage.prototype.typeId = null;
- FrontendMessage.prototype.payload = function() {
- return new Buffer(0);
- };
+ FrontendMessage.prototype.payload = function() {
+ return new Buffer(0);
+ };
- FrontendMessage.prototype.toBuffer = function() {
- var b, bLength, headerLength, messageBuffer, payloadBuffer, pos;
+ FrontendMessage.prototype.toBuffer = function() {
+ var b, bLength, headerLength, messageBuffer, payloadBuffer, pos;
- payloadBuffer = this.payload();
- if (typeof payloadBuffer === 'string') {
- bLength = Buffer.byteLength(payloadBuffer);
- b = new Buffer(bLength + 1);
- b.writeZeroTerminatedString(payloadBuffer, 0);
- payloadBuffer = b;
- }
- headerLength = this.typeId != null ? 5 : 4;
- messageBuffer = new Buffer(headerLength + payloadBuffer.length);
- if (this.typeId) {
- messageBuffer.writeUInt8(this.typeId, 0);
- pos = 1;
- } else {
- pos = 0;
- }
- messageBuffer.writeUInt32(payloadBuffer.length + 4, pos);
- payloadBuffer.copy(messageBuffer, pos + 4);
- return messageBuffer;
- };
+ payloadBuffer = this.payload();
+ if (typeof payloadBuffer === 'string') {
+ bLength = Buffer.byteLength(payloadBuffer);
+ b = new Buffer(bLength + 1);
+ b.writeZeroTerminatedString(payloadBuffer, 0);
+ payloadBuffer = b;
+ }
+ headerLength = this.typeId != null ? 5 : 4;
+ messageBuffer = new Buffer(headerLength + payloadBuffer.length);
+ if (this.typeId) {
+ messageBuffer.writeUInt8(this.typeId, 0);
+ pos = 1;
+ } else {
+ pos = 0;
+ }
+ messageBuffer.writeUInt32(payloadBuffer.length + 4, pos);
+ payloadBuffer.copy(messageBuffer, pos + 4);
+ return messageBuffer;
+ };
- return FrontendMessage;
+ return FrontendMessage;
- })();
+})();
- FrontendMessage.Startup = (function(_super) {
- __extends(Startup, _super);
+FrontendMessage.Startup = (function(_super) {
+ __extends(Startup, _super);
- Startup.prototype.typeId = null;
+ Startup.prototype.typeId = null;
- Startup.prototype.protocol = 3 << 16;
+ Startup.prototype.protocol = 3 << 16;
- function Startup(user, database, options) {
- this.user = user;
- this.database = database;
- this.options = options;
- }
+ function Startup(user, database, options) {
+ this.user = user;
+ this.database = database;
+ this.options = options;
+ }
- Startup.prototype.payload = function() {
- var pl, pos;
+ Startup.prototype.payload = function() {
+ var pl, pos;
- pos = 0;
- pl = new Buffer(8192);
- pl.writeUInt32(this.protocol, pos);
- pos += 4;
- if (this.user) {
- pos += pl.writeZeroTerminatedString('user', pos);
- pos += pl.writeZeroTerminatedString(this.user, pos);
- }
- if (this.database) {
- pos += pl.writeZeroTerminatedString('database', pos);
- pos += pl.writeZeroTerminatedString(this.database, pos);
- }
- if (this.options) {
- pos += pl.writeZeroTerminatedString('options', pos);
- pos += pl.writeZeroTerminatedString(this.options, pos);
- }
- pl.writeUInt8(0, pos);
- pos += 1;
- return pl.slice(0, pos);
- };
+ pos = 0;
+ pl = new Buffer(8192);
+ pl.writeUInt32(this.protocol, pos);
+ pos += 4;
+ if (this.user) {
+ pos += pl.writeZeroTerminatedString('user', pos);
+ pos += pl.writeZeroTerminatedString(this.user, pos);
+ }
+ if (this.database) {
+ pos += pl.writeZeroTerminatedString('database', pos);
+ pos += pl.writeZeroTerminatedString(this.database, pos);
+ }
+ if (this.options) {
+ pos += pl.writeZeroTerminatedString('options', pos);
+ pos += pl.writeZeroTerminatedString(this.options, pos);
+ }
+ pl.writeUInt8(0, pos);
+ pos += 1;
+ return pl.slice(0, pos);
+ };
- return Startup;
+ return Startup;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.SSLRequest = (function(_super) {
- __extends(SSLRequest, _super);
+FrontendMessage.SSLRequest = (function(_super) {
+ __extends(SSLRequest, _super);
- function SSLRequest() {
- _ref = SSLRequest.__super__.constructor.apply(this, arguments);
- return _ref;
- }
+ function SSLRequest() {
+ _ref = SSLRequest.__super__.constructor.apply(this, arguments);
+ return _ref;
+ }
- SSLRequest.prototype.typeId = null;
+ SSLRequest.prototype.typeId = null;
- SSLRequest.prototype.sslMagicNumber = 80877103;
+ SSLRequest.prototype.sslMagicNumber = 80877103;
- SSLRequest.prototype.payload = function() {
- var pl;
+ SSLRequest.prototype.payload = function() {
+ var pl;
- pl = new Buffer(4);
- pl.writeUInt32(this.sslMagicNumber, 0);
- return pl;
- };
+ pl = new Buffer(4);
+ pl.writeUInt32(this.sslMagicNumber, 0);
+ return pl;
+ };
- return SSLRequest;
+ return SSLRequest;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.Password = (function(_super) {
- __extends(Password, _super);
+FrontendMessage.Password = (function(_super) {
+ __extends(Password, _super);
- Password.prototype.typeId = 112;
+ Password.prototype.typeId = 112;
- function Password(password, authMethod, options) {
- var _ref1, _ref2, _ref3;
+ function Password(password, authMethod, options) {
+ var _ref1, _ref2, _ref3;
- this.password = password;
- this.authMethod = authMethod;
- this.options = options;
- if ((_ref1 = this.password) == null) {
- this.password = '';
- }
- if ((_ref2 = this.authMethod) == null) {
- this.authMethod = Authentication.methods.CLEARTEXT_PASSWORD;
- }
- if ((_ref3 = this.options) == null) {
- this.options = {};
- }
+ this.password = password;
+ this.authMethod = authMethod;
+ this.options = options;
+ if ((_ref1 = this.password) == null) {
+ this.password = '';
}
+ if ((_ref2 = this.authMethod) == null) {
+ this.authMethod = Authentication.methods.CLEARTEXT_PASSWORD;
+ }
+ if ((_ref3 = this.options) == null) {
+ this.options = {};
+ }
+ }
+
+ Password.prototype.md5 = function(str) {
+ var hash;
+
+ hash = require('crypto').createHash('md5');
+ hash.update(str);
+ return hash.digest('hex');
+ };
+
+ Password.prototype.encodedPassword = function() {
+ switch (this.authMethod) {
+ case Authentication.methods.CLEARTEXT_PASSWORD:
+ return this.password;
+ case Authentication.methods.MD5_PASSWORD:
+ return "md5" + this.md5(this.md5(this.password + this.options.user) + this.options.salt);
+ default:
+ throw new Error("Authentication method " + this.authMethod + " not implemented.");
+ }
+ };
- Password.prototype.md5 = function(str) {
- var hash;
-
- hash = require('crypto').createHash('md5');
- hash.update(str);
- return hash.digest('hex');
- };
-
- Password.prototype.encodedPassword = function() {
- switch (this.authMethod) {
- case Authentication.methods.CLEARTEXT_PASSWORD:
- return this.password;
- case Authentication.methods.MD5_PASSWORD:
- return "md5" + this.md5(this.md5(this.password + this.options.user) + this.options.salt);
- default:
- throw new Error("Authentication method " + this.authMethod + " not implemented.");
- }
- };
-
- Password.prototype.payload = function() {
- return this.encodedPassword();
- };
+ Password.prototype.payload = function() {
+ return this.encodedPassword();
+ };
- return Password;
+ return Password;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.CancelRequest = (function(_super) {
- __extends(CancelRequest, _super);
+FrontendMessage.CancelRequest = (function(_super) {
+ __extends(CancelRequest, _super);
- CancelRequest.prototype.cancelRequestMagicNumber = 80877102;
+ CancelRequest.prototype.cancelRequestMagicNumber = 80877102;
- function CancelRequest(backendPid, backendKey) {
- this.backendPid = backendPid;
- this.backendKey = backendKey;
- }
+ function CancelRequest(backendPid, backendKey) {
+ this.backendPid = backendPid;
+ this.backendKey = backendKey;
+ }
- CancelRequest.prototype.payload = function() {
- var b;
+ CancelRequest.prototype.payload = function() {
+ var b;
- b = new Buffer(12);
- b.writeUInt32(this.cancelRequestMagicNumber, 0);
- b.writeUInt32(this.backendPid, 4);
- b.writeUInt32(this.backendKey, 8);
- return b;
- };
+ b = new Buffer(12);
+ b.writeUInt32(this.cancelRequestMagicNumber, 0);
+ b.writeUInt32(this.backendPid, 4);
+ b.writeUInt32(this.backendKey, 8);
+ return b;
+ };
- return CancelRequest;
+ return CancelRequest;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.Close = (function(_super) {
- __extends(Close, _super);
+FrontendMessage.Close = (function(_super) {
+ __extends(Close, _super);
- Close.prototype.typeId = 67;
+ Close.prototype.typeId = 67;
- function Close(type, name) {
- var _ref1;
+ function Close(type, name) {
+ var _ref1;
- this.name = name;
- if ((_ref1 = this.name) == null) {
- this.name = "";
- }
- this.type = (function() {
- switch (type) {
- case 'portal':
- case 'p':
- case 'P':
- case 80:
- return 80;
- case 'prepared_statement':
- case 'prepared':
- case 'statement':
- case 's':
- case 'S':
- case 83:
- return 83;
- default:
- throw new Error("" + type + " not a valid type to describe");
- }
- })();
+ this.name = name;
+ if ((_ref1 = this.name) == null) {
+ this.name = "";
}
+ this.type = (function() {
+ switch (type) {
+ case 'portal':
+ case 'p':
+ case 'P':
+ case 80:
+ return 80;
+ case 'prepared_statement':
+ case 'prepared':
+ case 'statement':
+ case 's':
+ case 'S':
+ case 83:
+ return 83;
+ default:
+ throw new Error("" + type + " not a valid type to describe");
+ }
+ })();
+ }
- Close.prototype.payload = function() {
- var b;
+ Close.prototype.payload = function() {
+ var b;
- b = new Buffer(this.name.length + 2);
- b.writeUInt8(this.type, 0);
- b.writeZeroTerminatedString(this.name, 1);
- return b;
- };
+ b = new Buffer(this.name.length + 2);
+ b.writeUInt8(this.type, 0);
+ b.writeZeroTerminatedString(this.name, 1);
+ return b;
+ };
- return Close;
+ return Close;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.Describe = (function(_super) {
- __extends(Describe, _super);
+FrontendMessage.Describe = (function(_super) {
+ __extends(Describe, _super);
- Describe.prototype.typeId = 68;
+ Describe.prototype.typeId = 68;
- function Describe(type, name) {
- var _ref1;
+ function Describe(type, name) {
+ var _ref1;
- this.name = name;
- if ((_ref1 = this.name) == null) {
- this.name = "";
- }
- this.type = (function() {
- switch (type) {
- case 'portal':
- case 'P':
- case 80:
- return 80;
- case 'prepared_statement':
- case 'prepared':
- case 'statement':
- case 'S':
- case 83:
- return 83;
- default:
- throw new Error("" + type + " not a valid type to describe");
- }
- })();
+ this.name = name;
+ if ((_ref1 = this.name) == null) {
+ this.name = "";
}
+ this.type = (function() {
+ switch (type) {
+ case 'portal':
+ case 'P':
+ case 80:
+ return 80;
+ case 'prepared_statement':
+ case 'prepared':
+ case 'statement':
+ case 'S':
+ case 83:
+ return 83;
+ default:
+ throw new Error("" + type + " not a valid type to describe");
+ }
+ })();
+ }
- Describe.prototype.payload = function() {
- var b;
+ Describe.prototype.payload = function() {
+ var b;
- b = new Buffer(this.name.length + 2);
- b.writeUInt8(this.type, 0);
- b.writeZeroTerminatedString(this.name, 1);
- return b;
- };
+ b = new Buffer(this.name.length + 2);
+ b.writeUInt8(this.type, 0);
+ b.writeZeroTerminatedString(this.name, 1);
+ return b;
+ };
- return Describe;
+ return Describe;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.Execute = (function(_super) {
- __extends(Execute, _super);
+FrontendMessage.Execute = (function(_super) {
+ __extends(Execute, _super);
- Execute.prototype.typeId = 69;
+ Execute.prototype.typeId = 69;
- function Execute(portal, maxRows) {
- var _ref1, _ref2;
+ function Execute(portal, maxRows) {
+ var _ref1, _ref2;
- this.portal = portal;
- this.maxRows = maxRows;
- if ((_ref1 = this.portal) == null) {
- this.portal = "";
- }
- if ((_ref2 = this.maxRows) == null) {
- this.maxRows = 0;
- }
+ this.portal = portal;
+ this.maxRows = maxRows;
+ if ((_ref1 = this.portal) == null) {
+ this.portal = "";
+ }
+ if ((_ref2 = this.maxRows) == null) {
+ this.maxRows = 0;
}
+ }
- Execute.prototype.payload = function() {
- var b, pos;
+ Execute.prototype.payload = function() {
+ var b, pos;
- b = new Buffer(5 + this.portal.length);
- pos = b.writeZeroTerminatedString(this.portal, 0);
- b.writeUInt32(this.maxRows, pos);
- return b;
- };
+ b = new Buffer(5 + this.portal.length);
+ pos = b.writeZeroTerminatedString(this.portal, 0);
+ b.writeUInt32(this.maxRows, pos);
+ return b;
+ };
- return Execute;
+ return Execute;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.Query = (function(_super) {
- __extends(Query, _super);
+FrontendMessage.Query = (function(_super) {
+ __extends(Query, _super);
- Query.prototype.typeId = 81;
+ Query.prototype.typeId = 81;
- function Query(sql) {
- this.sql = sql;
- }
+ function Query(sql) {
+ this.sql = sql;
+ }
- Query.prototype.payload = function() {
- return this.sql;
- };
+ Query.prototype.payload = function() {
+ return this.sql;
+ };
- return Query;
+ return Query;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.Parse = (function(_super) {
- __extends(Parse, _super);
+FrontendMessage.Parse = (function(_super) {
+ __extends(Parse, _super);
- Parse.prototype.typeId = 80;
+ Parse.prototype.typeId = 80;
- function Parse(name, sql, parameterTypes) {
- var _ref1, _ref2;
+ function Parse(name, sql, parameterTypes) {
+ var _ref1, _ref2;
- this.name = name;
- this.sql = sql;
- this.parameterTypes = parameterTypes;
- if ((_ref1 = this.name) == null) {
- this.name = "";
- }
- if ((_ref2 = this.parameterTypes) == null) {
- this.parameterTypes = [];
- }
+ this.name = name;
+ this.sql = sql;
+ this.parameterTypes = parameterTypes;
+ if ((_ref1 = this.name) == null) {
+ this.name = "";
}
+ if ((_ref2 = this.parameterTypes) == null) {
+ this.parameterTypes = [];
+ }
+ }
+
+ Parse.prototype.payload = function() {
+ var b, paramType, pos, _i, _len, _ref1;
+
+ b = new Buffer(8192);
+ pos = b.writeZeroTerminatedString(this.name, 0);
+ pos += b.writeZeroTerminatedString(this.sql, pos);
+ b.writeUInt16(this.parameterTypes.length, pos);
+ pos += 2;
+ _ref1 = this.parameterTypes;
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+ paramType = _ref1[_i];
+ b.writeUInt32(paramType, pos);
+ pos += 4;
+ }
+ return b.slice(0, pos);
+ };
- Parse.prototype.payload = function() {
- var b, paramType, pos, _i, _len, _ref1;
-
- b = new Buffer(8192);
- pos = b.writeZeroTerminatedString(this.name, 0);
- pos += b.writeZeroTerminatedString(this.sql, pos);
- b.writeUInt16(this.parameterTypes.length, pos);
- pos += 2;
- _ref1 = this.parameterTypes;
- for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
- paramType = _ref1[_i];
- b.writeUInt32(paramType, pos);
- pos += 4;
- }
- return b.slice(0, pos);
- };
-
- return Parse;
+ return Parse;
- })(FrontendMessage);
+})(FrontendMessage);
- FrontendMessage.Bind = (function(_super) {
- __extends(Bind, _super);
+FrontendMessage.Bind = (function(_super) {
+ __extends(Bind, _super);
- Bind.prototype.typeId = 66;
+ Bind.prototype.typeId = 66;
- function Bind(portal, preparedStatement, parameterValues) {
- var parameterValue, _i, _len;
+ function Bind(portal, preparedStatement, parameterValues) {
+ var parameterValue, _i, _len;
- this.portal = portal;
- this.preparedStatement = preparedStatement;
- this.parameterValues = [];
- for (_i = 0, _len = parameterValues.length; _i < _len; _i++) {
- parameterValue = parameterValues[_i];
- this.parameterValues.push(parameterValue.toString());
- }
+ this.portal = portal;
+ this.preparedStatement = preparedStatement;
+ this.parameterValues = [];
+ for (_i = 0, _len = parameterValues.length; _i < _len; _i++) {
+ parameterValue = parameterValues[_i];
+ this.parameterValues.push(parameterValue.toString());