Skip to content

Commit dcd9067

Browse files
committed
Merge pull request brianc#427 from brianc/parse-big-int
Add ability to opt-in to int8 parsing
2 parents 003ee69 + e744d05 commit dcd9067

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/defaults.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
var defaults = module.exports = {
22
// database host defaults to localhost
33
host: 'localhost',
44

@@ -38,3 +38,8 @@ module.exports = {
3838

3939
client_encoding: ""
4040
};
41+
42+
//parse int8 so you can get your count values as actual numbers
43+
module.exports.__defineSetter__("parseInt8", function(val) {
44+
require('./types').setTypeParser(20, 'text', val ? parseInt : function(val) { return val; });
45+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
var helper = require(__dirname + '/../test-helper');
3+
var pg = helper.pg;
4+
test('ability to turn on and off parser', function() {
5+
if(helper.args.binary) return false;
6+
pg.connect(helper.config, assert.success(function(client, done) {
7+
pg.defaults.parseInt8 = true;
8+
client.query('CREATE TEMP TABLE asdf(id SERIAL PRIMARY KEY)');
9+
client.query('SELECT COUNT(*) as "count" FROM asdf', assert.success(function(res) {
10+
pg.defaults.parseInt8 = false;
11+
client.query('SELECT COUNT(*) as "count" FROM asdf', assert.success(function(res) {
12+
done();
13+
assert.strictEqual("0", res.rows[0].count);
14+
pg.end();
15+
}));
16+
}));
17+
}));
18+
});

0 commit comments

Comments
 (0)