parse int8[] (#1152)
* parse int8[] * missing semicolon * test * test fixed * test fixed * test fixed. again.
This commit is contained in:
parent
2c636c750f
commit
f6c40b9331
@ -62,7 +62,13 @@ var defaults = module.exports = {
|
|||||||
parseInputDatesAsUTC: false
|
parseInputDatesAsUTC: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var pgTypes = require('pg-types');
|
||||||
|
// save default parsers
|
||||||
|
var parseBigInteger = pgTypes.getTypeParser(20, 'text');
|
||||||
|
var parseBigIntegerArray = pgTypes.getTypeParser(1016, 'text');
|
||||||
|
|
||||||
//parse int8 so you can get your count values as actual numbers
|
//parse int8 so you can get your count values as actual numbers
|
||||||
module.exports.__defineSetter__("parseInt8", function(val) {
|
module.exports.__defineSetter__("parseInt8", function(val) {
|
||||||
require('pg-types').setTypeParser(20, 'text', val ? parseInt : function(val) { return val; });
|
pgTypes.setTypeParser(20, 'text', val ? pgTypes.getTypeParser(23, 'text') : parseBigInteger);
|
||||||
|
pgTypes.setTypeParser(1016, 'text', val ? pgTypes.getTypeParser(1007, 'text') : parseBigIntegerArray);
|
||||||
});
|
});
|
||||||
|
@ -6,11 +6,18 @@ test('ability to turn on and off parser', function() {
|
|||||||
pg.connect(helper.config, assert.success(function(client, done) {
|
pg.connect(helper.config, assert.success(function(client, done) {
|
||||||
pg.defaults.parseInt8 = true;
|
pg.defaults.parseInt8 = true;
|
||||||
client.query('CREATE TEMP TABLE asdf(id SERIAL PRIMARY KEY)');
|
client.query('CREATE TEMP TABLE asdf(id SERIAL PRIMARY KEY)');
|
||||||
client.query('SELECT COUNT(*) as "count" FROM asdf', assert.success(function(res) {
|
client.query('SELECT COUNT(*) as "count", \'{1,2,3}\'::bigint[] as array FROM asdf', assert.success(function(res) {
|
||||||
|
assert.strictEqual(0, res.rows[0].count);
|
||||||
|
assert.strictEqual(1, res.rows[0].array[0]);
|
||||||
|
assert.strictEqual(2, res.rows[0].array[1]);
|
||||||
|
assert.strictEqual(3, res.rows[0].array[2]);
|
||||||
pg.defaults.parseInt8 = false;
|
pg.defaults.parseInt8 = false;
|
||||||
client.query('SELECT COUNT(*) as "count" FROM asdf', assert.success(function(res) {
|
client.query('SELECT COUNT(*) as "count", \'{1,2,3}\'::bigint[] as array FROM asdf', assert.success(function(res) {
|
||||||
done();
|
done();
|
||||||
assert.strictEqual("0", res.rows[0].count);
|
assert.strictEqual('0', res.rows[0].count);
|
||||||
|
assert.strictEqual('1', res.rows[0].array[0]);
|
||||||
|
assert.strictEqual('2', res.rows[0].array[1]);
|
||||||
|
assert.strictEqual('3', res.rows[0].array[2]);
|
||||||
pg.end();
|
pg.end();
|
||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user