mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
* Work on converting lib to standard * Finish updating lib * Finish linting lib * Format test files * Add .eslintrc with standard format * Supply full path to eslint bin * Move lint command to package.json * Add eslint as dev dependency
40 lines
983 B
JavaScript
40 lines
983 B
JavaScript
'use strict'
|
|
/**
|
|
* Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com)
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* README.md file in the root directory of this source tree.
|
|
*/
|
|
|
|
var types = require('pg-types')
|
|
|
|
function TypeOverrides (userTypes) {
|
|
this._types = userTypes || types
|
|
this.text = {}
|
|
this.binary = {}
|
|
}
|
|
|
|
TypeOverrides.prototype.getOverrides = function (format) {
|
|
switch (format) {
|
|
case 'text': return this.text
|
|
case 'binary': return this.binary
|
|
default: return {}
|
|
}
|
|
}
|
|
|
|
TypeOverrides.prototype.setTypeParser = function (oid, format, parseFn) {
|
|
if (typeof format === 'function') {
|
|
parseFn = format
|
|
format = 'text'
|
|
}
|
|
this.getOverrides(format)[oid] = parseFn
|
|
}
|
|
|
|
TypeOverrides.prototype.getTypeParser = function (oid, format) {
|
|
format = format || 'text'
|
|
return this.getOverrides(format)[oid] || this._types.getTypeParser(oid, format)
|
|
}
|
|
|
|
module.exports = TypeOverrides
|