代码拉取完成,页面将自动刷新
const {Sequelize} = require('sequelize');
const _ = require("lodash");
const fse = require("fs-extra")
const path = require("path")
const sequelizeConfig = require('./config/config.sequelize');
class AgentBootHook {
constructor(agent) {
this.agent = agent;
}
configWillLoad() {
const {database, port} = fse.readJsonSync(path.join(process.cwd(), "database.json")) ;
this.agent.config.sequelize.database = database;
this.agent.config.cluster.listen.port = port ;
}
async didLoad() {
try {
const {database} = await fse.readJson(path.join(process.cwd(), "database.json")) ;
const sequelize = new Sequelize("mysql", sequelizeConfig.username, sequelizeConfig.password, {
dialect: sequelizeConfig.dialect,
host: sequelizeConfig.host,
port: sequelizeConfig.port,
});
await sequelize.query(`CREATE DATABASE \`${database}\` /*!40100 DEFAULT CHARACTER SET ${sequelizeConfig.define.charset} */`);
console.log("创建数据库成功")
} catch (e) {}
}
async willReady() {
// 所有的插件都已启动完毕,但是应用整体还未 ready
// 可以做一些数据初始化等操作,这些操作成功才会启动应用
// 例如:从数据库加载数据到内存缓存
// this.app.cacheData = await this.app.model.query(QUERY_CACHE_SQL);
}
async didReady() {
}
async serverDidReady() {
}
}
module.exports = AgentBootHook;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。