node-postgres/lib/types.js
Alexander Sulfrian e9838cc5bb fix textParsers
some textParsers requires the input value to be a string, so convert
it before calling the textParsers
the same problem exists in test/integration/connection/query-test
so that there also need to be a String call
2011-11-22 04:52:26 +01:00

36 lines
767 B
JavaScript

var textParsers = require(__dirname + "/textParsers"),
binaryParsers = require(__dirname + "/binaryParsers");
var typeParsers = {
text: {},
binary: {}
};
//the empty parse function
var noParse = function(val) {
return String(val);
}
//returns a function used to convert a specific type (specified by
//oid) into a result javascript type
var getTypeParser = function(oid, format) {
if (!typeParsers[format])
return noParse;
return typeParsers[format][oid] || noParse;
};
textParsers.init(function(oid, converter) {
typeParsers.text[oid] = function(value) {
return converter(String(value));
};
});
binaryParsers.init(function(oid, converter) {
typeParsers.binary[oid] = converter;
});
module.exports = {
getTypeParser: getTypeParser,
}