mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
db53ac0721
no issue - Updated Test & linting packages - Updated use of hasOwnProperty - Using Object.prototype.hasOwnProperty instead (ref. eslint.org/docs/rules/no-prototype-builtins) - Removed already defined built-in global variable Intl - Applied `--fix` with lint command on `core/test` folder - The rules were broken because some of them were made stricter for `eslint: recommended` ruleset (ref. https://eslint.org/docs/user-guide/migrating-to-6.0.0#eslint-recommended-changes) - Removed redundant global variable declarations to pass linting
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
var knex = require('knex'),
|
|
config = require('../../config'),
|
|
common = require('../../lib/common'),
|
|
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 = 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) {
|
|
common.logging.error(new common.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;
|