mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Update pg package and convert data to correct type
No Issue - Switch 'pg.js' package for 'pg' as the native bindings are now an optional add-on to pg and pg.js has been deprecated. - pg@4.1.1 - Set the driver's parser to automatically convert integer data returned from postgres into a javascript integer.
This commit is contained in:
parent
4b6c2bff51
commit
3ad68526cb
2 changed files with 21 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
},
|
||||
"optionalDependencies": {
|
||||
"mysql": "2.1.1",
|
||||
"pg.js": "3.6.2"
|
||||
"pg": "4.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"blanket": "~1.1.6",
|
||||
|
|
Loading…
Add table
Reference in a new issue