@@ -16,6 +16,7 @@ const process = require('process');
16
16
const argparse = require ( 'argparse' ) ;
17
17
const pg = require ( 'pg' ) ;
18
18
const pgcopy = require ( 'pg-copy-streams' ) . from ;
19
+ const tspostgres = require ( 'ts-postgres' ) ;
19
20
const csvwriter = require ( 'csv-write-stream' )
20
21
21
22
@@ -26,6 +27,33 @@ function _connect(driverName, args, callback) {
26
27
driver = pg ;
27
28
} else if ( driverName == 'pg-native' ) {
28
29
driver = pg . native ;
30
+ } else if ( driverName == 'ts-postgres' ) {
31
+ driver = {
32
+ 'Client' : function ( config ) {
33
+ var client = new tspostgres . Client ( config ) ;
34
+ return {
35
+ connect : function ( callback ) {
36
+ client . connect ( )
37
+ . then ( function ( ) { callback ( null ) ; } )
38
+ . catch ( function ( err ) { callback ( err ) ; } ) ;
39
+ } ,
40
+ end : function ( ) {
41
+ client . end ( ) ;
42
+ } ,
43
+ query : function ( stmt , cb ) {
44
+ client . query ( stmt )
45
+ . then (
46
+ function ( result ) { cb ( null , result ) ; }
47
+ )
48
+ . catch (
49
+ function ( err ) {
50
+ cb ( err , null ) ;
51
+ }
52
+ ) ;
53
+ }
54
+ }
55
+ }
56
+ } ;
29
57
} else {
30
58
throw new Error ( 'unexected driver: ' + driverName )
31
59
}
@@ -135,8 +163,9 @@ function runner(args, querydata) {
135
163
} ;
136
164
}
137
165
138
- if ( copy != null && driver == 'pg-native' ) {
139
- cb ( { code : 3 , msg : "pg-native does not support COPY" } ) ;
166
+ if ( copy != null && driver !== 'pg-js' ) {
167
+ cb ( { code : 3 , msg : driver + " does not support COPY" } ) ;
168
+ return ;
140
169
}
141
170
142
171
if ( use_prepared_stmt ) {
@@ -283,8 +312,12 @@ function runner(args, querydata) {
283
312
284
313
function _setup ( cb ) {
285
314
if ( setup_query ) {
286
- // pg-native does not like multiple statements in queries
287
- _do_run ( 'pg-js' , setup_query , [ ] , 1 , 0 , false , false , cb ) ;
315
+ function go ( queries ) {
316
+ var query = queries . shift ( ) ;
317
+ var next = ( query ) ? function ( ) { go ( queries ) } : cb ;
318
+ _do_run ( args . driver , query , [ ] , 1 , 0 , false , false , next ) ;
319
+ }
320
+ go ( setup_query . split ( ';' ) ) ;
288
321
} else {
289
322
if ( cb ) {
290
323
cb ( ) ;
@@ -301,7 +334,7 @@ function runner(args, querydata) {
301
334
302
335
function _teardown ( cb ) {
303
336
if ( teardown_query ) {
304
- _do_run ( 'pg-js' , teardown_query , [ ] , 1 , 0 , false , false , cb ) ;
337
+ _do_run ( args . driver , teardown_query , [ ] , 1 , 0 , false , false , cb ) ;
305
338
} else {
306
339
if ( cb ) {
307
340
cb ( ) ;
@@ -371,7 +404,7 @@ function main() {
371
404
parser . addArgument (
372
405
'driver' ,
373
406
{ type : String , help : 'driver implementation to use' ,
374
- choices : [ 'pg-js' , 'pg-native' ] } )
407
+ choices : [ 'pg-js' , 'pg-native' , 'ts-postgres' ] } )
375
408
parser . addArgument (
376
409
'queryfile' ,
377
410
{ type : String ,
0 commit comments