-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
26 lines (22 loc) · 849 Bytes
/
index.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
//you need to pass in the pg module
//to have this module initialize the type parsers
//technically you can just have this globally initialize
//when its required but I think this is more explicit & cleaner.
var pgParseFloats = module.exports = function(pg) {
//the type & OID match for the float types
var types = {
FLOAT4: 700,
FLOAT8: 701,
NUMERIC: 1700,
FLOAT4_ARRAY: 1021,
FLOAT8_ARRAY: 1022,
NUMERIC_ARRAY: 1231
};
//just use the built-in V8 parseFloat implementation
pg.types.setTypeParser(types.FLOAT4, 'text', parseFloat);
pg.types.setTypeParser(types.FLOAT8, 'text', parseFloat);
pg.types.setTypeParser(types.NUMERIC, 'text', parseFloat);
//TODO array parsers
};
//you can find the OID -> TYPE map like this:
//client.query('select oid, typname from pg_type where typtype = \'b\' order by oid')