source: node_modules/pg-types/index.js

main
Last change on this file was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 13 days ago

Project Handcraft Marketplace

  • Property mode set to 100644
File size: 1.2 KB
Line 
1var textParsers = require('./lib/textParsers');
2var binaryParsers = require('./lib/binaryParsers');
3var arrayParser = require('./lib/arrayParser');
4var builtinTypes = require('./lib/builtins');
5
6exports.getTypeParser = getTypeParser;
7exports.setTypeParser = setTypeParser;
8exports.arrayParser = arrayParser;
9exports.builtins = builtinTypes;
10
11var typeParsers = {
12 text: {},
13 binary: {}
14};
15
16//the empty parse function
17function noParse (val) {
18 return String(val);
19};
20
21//returns a function used to convert a specific type (specified by
22//oid) into a result javascript type
23//note: the oid can be obtained via the following sql query:
24//SELECT oid FROM pg_type WHERE typname = 'TYPE_NAME_HERE';
25function getTypeParser (oid, format) {
26 format = format || 'text';
27 if (!typeParsers[format]) {
28 return noParse;
29 }
30 return typeParsers[format][oid] || noParse;
31};
32
33function setTypeParser (oid, format, parseFn) {
34 if(typeof format == 'function') {
35 parseFn = format;
36 format = 'text';
37 }
38 typeParsers[format][oid] = parseFn;
39};
40
41textParsers.init(function(oid, converter) {
42 typeParsers.text[oid] = converter;
43});
44
45binaryParsers.init(function(oid, converter) {
46 typeParsers.binary[oid] = converter;
47});
Note: See TracBrowser for help on using the repository browser.