@@ -2,7 +2,7 @@ var crypto = require('crypto');
2
2
var EventEmitter = require ( 'events' ) . EventEmitter ;
3
3
var util = require ( 'util' ) ;
4
4
var pgPass = require ( 'pgpass' ) ;
5
- var types = require ( 'pg-types ' ) ;
5
+ var TypeOverrides = require ( './type-overrides ' ) ;
6
6
7
7
var ConnectionParameters = require ( __dirname + '/connection-parameters' ) ;
8
8
var Query = require ( __dirname + '/query' ) ;
@@ -21,6 +21,8 @@ var Client = function(config) {
21
21
22
22
var c = config || { } ;
23
23
24
+ this . _types = new TypeOverrides ( c . types ) ;
25
+
24
26
this . connection = c . connection || new Connection ( {
25
27
stream : c . stream ,
26
28
ssl : this . connectionParameters . ssl
@@ -31,12 +33,6 @@ var Client = function(config) {
31
33
this . processID = null ;
32
34
this . secretKey = null ;
33
35
this . ssl = this . connectionParameters . ssl || false ;
34
-
35
- this . _types = c . types || types ;
36
- this . _parserOverrides = {
37
- text : { } ,
38
- binary : { }
39
- } ;
40
36
} ;
41
37
42
38
util . inherits ( Client , EventEmitter ) ;
@@ -235,17 +231,11 @@ Client.prototype.cancel = function(client, query) {
235
231
} ;
236
232
237
233
Client . 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 ) ;
243
235
} ;
244
236
245
237
Client . 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 ) ;
249
239
} ;
250
240
251
241
// 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) {
323
313
if ( this . binary && ! query . binary ) {
324
314
query . binary = true ;
325
315
}
326
- query . _result . _getTypeParser = this . getTypeParser . bind ( this ) ;
316
+ query . _result . _getTypeParser = this . _types . getTypeParser . bind ( this . _types ) ;
327
317
328
318
this . queryQueue . push ( query ) ;
329
319
this . _pulseQueryQueue ( ) ;
0 commit comments