mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
15d9a77092
* moved `server/config` to `shared/config` * updated config import paths in server to use shared * updated config import paths in frontend to use shared * updated config import paths in test to use shared * updated config import paths in root to use shared * trigger regression tests * of course the rebase broke tests
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
const knex = require('knex');
|
|
const config = require('../../../shared/config');
|
|
const {logging} = require('../../lib/common');
|
|
const errors = require('@tryghost/errors');
|
|
let knexInstance;
|
|
|
|
// @TODO:
|
|
// - if you require this file before config file was loaded,
|
|
// - then this file is cached and you have no chance to connect to the db anymore
|
|
// - bring dynamic into this file (db.connect())
|
|
function configure(dbConfig) {
|
|
const client = dbConfig.client;
|
|
|
|
if (client === 'sqlite3') {
|
|
dbConfig.useNullAsDefault = Object.prototype.hasOwnProperty.call(dbConfig, 'useNullAsDefault') ? dbConfig.useNullAsDefault : true;
|
|
}
|
|
|
|
if (client === 'mysql') {
|
|
dbConfig.connection.timezone = 'UTC';
|
|
dbConfig.connection.charset = 'utf8mb4';
|
|
|
|
dbConfig.connection.loggingHook = function loggingHook(err) {
|
|
logging.error(new errors.InternalServerError({
|
|
code: 'MYSQL_LOGGING_HOOK',
|
|
err: err
|
|
}));
|
|
};
|
|
}
|
|
|
|
return dbConfig;
|
|
}
|
|
|
|
if (!knexInstance && config.get('database') && config.get('database').client) {
|
|
knexInstance = knex(configure(config.get('database')));
|
|
}
|
|
|
|
module.exports = knexInstance;
|