diff --git a/core/server/config/index.js b/core/server/config/index.js index 5f721f6d36..54399821a5 100644 --- a/core/server/config/index.js +++ b/core/server/config/index.js @@ -65,6 +65,25 @@ ConfigManager.prototype.init = function (rawConfig) { }); }; +function configureDriver(client) { + var pg; + + if (client === 'pg' || client === 'postgres' || client === 'postgresql') { + try { + pg = require('pg'); + } catch (e) { + pg = require('pg.js'); + } + + // By default PostgreSQL returns data as strings along with an OID that identifies + // its type. We're setting the parser to convert OID 20 (int8) into a javascript + // integer. + pg.types.setTypeParser(20, function (val) { + return val === null ? null : parseInt(val, 10); + }); + } +} + /** * Allows you to set the config object. * @param {Object} config Only accepts an object at the moment. @@ -105,6 +124,7 @@ ConfigManager.prototype.set = function (config) { (crypto.createHash('md5').update(packageInfo.version + Date.now()).digest('hex')).substring(0, 10); if (!knexInstance && this._config.database && this._config.database.client) { + configureDriver(this._config.database.client); knexInstance = knex(this._config.database); } diff --git a/package.json b/package.json index 005aa0f145..c3552e6f66 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ }, "optionalDependencies": { "mysql": "2.1.1", - "pg.js": "3.6.2" + "pg": "4.1.1" }, "devDependencies": { "blanket": "~1.1.6",