forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype-parser-override-tests.js
34 lines (30 loc) · 1.11 KB
/
type-parser-override-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var helper = require(__dirname + '/test-helper');
function testTypeParser(client, expectedResult, done) {
var boolValue = true;
client.query('CREATE TEMP TABLE parserOverrideTest(id bool)');
client.query('INSERT INTO parserOverrideTest(id) VALUES ($1)', [boolValue]);
client.query('SELECT * FROM parserOverrideTest', assert.success(function(result) {
assert.equal(result.rows[0].id, expectedResult);
helper.pg.end();
done();
}));
}
helper.pg.connect(helper.config, assert.success(function(client1, done1) {
helper.pg.connect(helper.config, assert.success(function(client2, done2) {
var boolTypeOID = 16;
client1.setTypeParser(boolTypeOID, function(){
return 'first client';
});
client2.setTypeParser(boolTypeOID, function(){
return 'second client';
});
client1.setTypeParser(boolTypeOID, 'binary', function(){
return 'first client binary';
});
client2.setTypeParser(boolTypeOID, 'binary', function(){
return 'second client binary';
});
testTypeParser(client1, 'first client', done1);
testTypeParser(client2, 'second client', done2);
}));
}));