mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
const Knex = require('knex');
|
|
const { knexSnakeCaseMappers } = require('objection');
|
|
const color = require('colorette');
|
|
const config = require('./config');
|
|
|
|
function initSystemKnex() {
|
|
return Knex({
|
|
client: config.system.db_client,
|
|
connection: {
|
|
host: config.system.db_host,
|
|
user: config.system.db_user,
|
|
password: config.system.db_password,
|
|
database: config.system.db_name,
|
|
charset: 'utf8',
|
|
},
|
|
migrations: {
|
|
directory: config.system.migrations_dir,
|
|
},
|
|
seeds: {
|
|
directory: config.system.seeds_dir,
|
|
},
|
|
pool: { min: 0, max: 7 },
|
|
...knexSnakeCaseMappers({ upperCase: true }),
|
|
});
|
|
}
|
|
|
|
function exit(text) {
|
|
if (text instanceof Error) {
|
|
console.error(
|
|
color.red(`${text.detail ? `${text.detail}\n` : ''}${text.stack}`)
|
|
);
|
|
} else {
|
|
console.error(color.red(text));
|
|
}
|
|
process.exit(1);
|
|
}
|
|
|
|
function success(text) {
|
|
console.log(text);
|
|
process.exit(0);
|
|
}
|
|
function log(text) {
|
|
console.log(text);
|
|
}
|
|
|
|
module.exports = {
|
|
log,
|
|
success,
|
|
exit,
|
|
initSystemKnex,
|
|
};
|