UNPKG

1 kBJavaScriptView Raw
1'use strict'
2/**
3 * Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com)
4 * All rights reserved.
5 *
6 * This source code is licensed under the MIT license found in the
7 * README.md file in the root directory of this source tree.
8 */
9
10var types = require('pg-types')
11
12function TypeOverrides(userTypes) {
13 this._types = userTypes || types
14 this.text = {}
15 this.binary = {}
16}
17
18TypeOverrides.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
29TypeOverrides.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
37TypeOverrides.prototype.getTypeParser = function (oid, format) {
38 format = format || 'text'
39 return this.getOverrides(format)[oid] || this._types.getTypeParser(oid, format)
40}
41
42module.exports = TypeOverrides