1 Star 0 Fork 0

毛毛虫吃肉肉/xny_egg_amis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
agent.js 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
毛毛虫吃肉肉 提交于 2024-04-18 14:21 . first
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;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mmc7rr/xny_egg_amis.git
[email protected]:mmc7rr/xny_egg_amis.git
mmc7rr
xny_egg_amis
xny_egg_amis
master

搜索帮助