Permalink
Browse files

Simple bytea support, returning buffers instead of escaped strings.

  • Loading branch information...
1 parent 6dd0157 commit f0aa7ccaea735dcd03c62ea017ebec903093c2bf @drdaeman committed Jul 19, 2011
Showing with 21 additions and 0 deletions.
  1. +7 −0 lib/types.js
  2. +14 −0 test/unit/client/typed-query-results-tests.js
View
@@ -122,6 +122,12 @@ var parseInterval = function(val) {
return i;
};
+var parseByteA = function(val) {
+ return new Buffer(val.replace(/\\([0-7]{3})/g, function (full_match, code) {
+ return String.fromCharCode(parseInt(code, 8));
+ }).replace(/\\\\/g, "\\"), "binary");
+}
+
//default string type parser registrations
registerStringTypeParser(20, parseInt);
registerStringTypeParser(21, parseInt);
@@ -136,6 +142,7 @@ registerStringTypeParser(1184, parseDate);
registerStringTypeParser(1007, parseIntegerArray);
registerStringTypeParser(1009, parseStringArray);
registerStringTypeParser(1186, parseInterval);
+registerStringTypeParser(17, parseByteA);
module.exports = {
registerStringTypeParser: registerStringTypeParser,
@@ -119,6 +119,20 @@ test('typed results', function() {
expected: function(val) {
assert.deepEqual(val, {'days':1, 'seconds':-3})
}
+ },{
+ name: 'bytea',
+ dataTypeID: 17,
+ actual: 'foo\\000\\200\\\\\\377',
+ expected: function(val) {
+ assert.deepEqual(val, new Buffer([102, 111, 111, 0, 128, 92, 255]));
+ }
+ },{
+ name: 'empty bytea',
+ dataTypeID: 17,
+ actual: '',
+ expected: function(val) {
+ assert.deepEqual(val, new Buffer(0));
+ }
}];

0 comments on commit f0aa7cc

Please sign in to comment.