mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-17 05:21:36 +03:00
8c74f55b36
refs #6623 - automatically set useNullAsDefault to false for sqlite3 so that we don't get a warning - we should *not* be relying on the behaviour of interpretting undefined anywhere, so it is correct that an error should be output if this happens so that we can fix the bad behaviour
37 lines
964 B
JavaScript
37 lines
964 B
JavaScript
var knex = require('knex'),
|
|
config = require('../../config'),
|
|
dbConfig = config.database,
|
|
knexInstance;
|
|
|
|
function configure(dbConfig) {
|
|
var client = dbConfig.client,
|
|
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);
|
|
});
|
|
}
|
|
|
|
if (client === 'sqlite3') {
|
|
dbConfig.useNullAsDefault = false;
|
|
}
|
|
|
|
return dbConfig;
|
|
}
|
|
|
|
if (!knexInstance && dbConfig && dbConfig.client) {
|
|
knexInstance = knex(configure(dbConfig));
|
|
}
|
|
|
|
module.exports = knexInstance;
|