mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
ac2578b419
refs #9178
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
var knex = require('knex'),
|
|
config = require('../../config'),
|
|
logging = require('../../lib/common/logging'),
|
|
errors = require('../../lib/common/errors'),
|
|
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) {
|
|
var client = dbConfig.client;
|
|
|
|
if (client === 'sqlite3') {
|
|
dbConfig.useNullAsDefault = dbConfig.useNullAsDefault || false;
|
|
}
|
|
|
|
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;
|