@@ -2,6 +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
6
6
7
var ConnectionParameters = require ( __dirname + '/connection-parameters' ) ;
7
8
var Query = require ( __dirname + '/query' ) ;
@@ -30,6 +31,12 @@ var Client = function(config) {
30
31
this . processID = null ;
31
32
this . secretKey = null ;
32
33
this . ssl = this . connectionParameters . ssl || false ;
34
+
35
+ this . _types = config . types || types ;
36
+ this . _parserOverrides = {
37
+ text : { } ,
38
+ binary : { }
39
+ } ;
33
40
} ;
34
41
35
42
util . inherits ( Client , EventEmitter ) ;
@@ -227,6 +234,20 @@ Client.prototype.cancel = function(client, query) {
227
234
}
228
235
} ;
229
236
237
+ 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 ;
243
+ } ;
244
+
245
+ 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 ) ;
249
+ } ;
250
+
230
251
// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
231
252
Client . prototype . escapeIdentifier = function ( str ) {
232
253
@@ -302,6 +323,7 @@ Client.prototype.query = function(config, values, callback) {
302
323
if ( this . binary && ! query . binary ) {
303
324
query . binary = true ;
304
325
}
326
+ query . _result . _getTypeParser = this . getTypeParser . bind ( this ) ;
305
327
306
328
this . queryQueue . push ( query ) ;
307
329
this . _pulseQueryQueue ( ) ;
0 commit comments