@@ -2,7 +2,7 @@ var crypto = require('crypto');
22var EventEmitter = require ( 'events' ) . EventEmitter ;
33var util = require ( 'util' ) ;
44var pgPass = require ( 'pgpass' ) ;
5- var types = require ( 'pg-types ' ) ;
5+ var TypeOverrides = require ( './type-overrides ' ) ;
66
77var ConnectionParameters = require ( __dirname + '/connection-parameters' ) ;
88var Query = require ( __dirname + '/query' ) ;
@@ -21,6 +21,8 @@ var Client = function(config) {
2121
2222 var c = config || { } ;
2323
24+ this . _types = new TypeOverrides ( c . types ) ;
25+
2426 this . connection = c . connection || new Connection ( {
2527 stream : c . stream ,
2628 ssl : this . connectionParameters . ssl
@@ -31,12 +33,6 @@ var Client = function(config) {
3133 this . processID = null ;
3234 this . secretKey = null ;
3335 this . ssl = this . connectionParameters . ssl || false ;
34-
35- this . _types = c . types || types ;
36- this . _parserOverrides = {
37- text : { } ,
38- binary : { }
39- } ;
4036} ;
4137
4238util . inherits ( Client , EventEmitter ) ;
@@ -235,17 +231,11 @@ Client.prototype.cancel = function(client, query) {
235231} ;
236232
237233Client . prototype . setTypeParser = function ( oid , format , parseFn ) {
238- if ( typeof format == 'function' ) {
239- parseFn = format ;
240- format = 'text' ;
241- }
242- this . _parserOverrides [ format ] [ oid ] = parseFn ;
234+ return this . _types . setTypeParser ( oid , format , parseFn ) ;
243235} ;
244236
245237Client . prototype . getTypeParser = function ( oid , format ) {
246- format = format || 'text' ;
247- var formatParserOverrides = this . _parserOverrides [ format ] || { } ;
248- return formatParserOverrides [ oid ] || this . _types . getTypeParser ( oid , format ) ;
238+ return this . _types . getTypeParser ( oid , format ) ;
249239} ;
250240
251241// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
@@ -323,7 +313,7 @@ Client.prototype.query = function(config, values, callback) {
323313 if ( this . binary && ! query . binary ) {
324314 query . binary = true ;
325315 }
326- query . _result . _getTypeParser = this . getTypeParser . bind ( this ) ;
316+ query . _result . _getTypeParser = this . _types . getTypeParser . bind ( this . _types ) ;
327317
328318 this . queryQueue . push ( query ) ;
329319 this . _pulseQueryQueue ( ) ;
0 commit comments