Skip to content

Commit 37cc70e

Browse files
maltheelprans
authored andcommitted
Add 'ts-postgres' to Node.js driver tests
1 parent 26a68ee commit 37cc70e

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

_nodejs/index.js

+39-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const process = require('process');
1616
const argparse = require('argparse');
1717
const pg = require('pg');
1818
const pgcopy = require('pg-copy-streams').from;
19+
const tspostgres = require('ts-postgres');
1920
const csvwriter = require('csv-write-stream')
2021

2122

@@ -26,6 +27,33 @@ function _connect(driverName, args, callback) {
2627
driver = pg;
2728
} else if (driverName == 'pg-native') {
2829
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+
};
2957
} else {
3058
throw new Error('unexected driver: ' + driverName)
3159
}
@@ -135,8 +163,9 @@ function runner(args, querydata) {
135163
};
136164
}
137165

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;
140169
}
141170

142171
if (use_prepared_stmt) {
@@ -283,8 +312,12 @@ function runner(args, querydata) {
283312

284313
function _setup(cb) {
285314
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(';'));
288321
} else {
289322
if (cb) {
290323
cb();
@@ -301,7 +334,7 @@ function runner(args, querydata) {
301334

302335
function _teardown(cb) {
303336
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);
305338
} else {
306339
if (cb) {
307340
cb();
@@ -371,7 +404,7 @@ function main() {
371404
parser.addArgument(
372405
'driver',
373406
{type: String, help: 'driver implementation to use',
374-
choices: ['pg-js', 'pg-native']})
407+
choices: ['pg-js', 'pg-native', 'ts-postgres']})
375408
parser.addArgument(
376409
'queryfile',
377410
{type: String,

_nodejs/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"csv-write-stream": "2.0.0",
1010
"pg": "~7.4.3",
1111
"pg-copy-streams": "1.2.0",
12-
"pg-native": "~3.0.0"
12+
"pg-native": "~3.0.0",
13+
"ts-postgres": "~1.0.0-rc2"
1314
}
1415
}

pgbench

+2
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ BENCHMARKS = [
361361
'python-aiopg-tuples',
362362
'python-asyncpg',
363363
'nodejs-pg-js',
364+
'nodejs-pg-native',
365+
'nodejs-ts-postgres'
364366
]
365367

366368

0 commit comments

Comments
 (0)