1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var types = require('pg-types')
|
11 |
|
12 | function TypeOverrides(userTypes) {
|
13 | this._types = userTypes || types
|
14 | this.text = {}
|
15 | this.binary = {}
|
16 | }
|
17 |
|
18 | TypeOverrides.prototype.getOverrides = function (format) {
|
19 | switch (format) {
|
20 | case 'text':
|
21 | return this.text
|
22 | case 'binary':
|
23 | return this.binary
|
24 | default:
|
25 | return {}
|
26 | }
|
27 | }
|
28 |
|
29 | TypeOverrides.prototype.setTypeParser = function (oid, format, parseFn) {
|
30 | if (typeof format === 'function') {
|
31 | parseFn = format
|
32 | format = 'text'
|
33 | }
|
34 | this.getOverrides(format)[oid] = parseFn
|
35 | }
|
36 |
|
37 | TypeOverrides.prototype.getTypeParser = function (oid, format) {
|
38 | format = format || 'text'
|
39 | return this.getOverrides(format)[oid] || this._types.getTypeParser(oid, format)
|
40 | }
|
41 |
|
42 | module.exports = TypeOverrides
|