init
This commit is contained in:
24
middleware/db_proxy.js
Normal file
24
middleware/db_proxy.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 数据库连接代理
|
||||
* 从 Framework 获取 Sequelize 实例
|
||||
*/
|
||||
|
||||
const Framework = require("../framework/node-core-framework.js");
|
||||
|
||||
module.exports = new Proxy({}, {
|
||||
get(_, prop) {
|
||||
const models = Framework.getModels();
|
||||
|
||||
if (!models) {
|
||||
throw new Error('Framework not initialized. Please call Framework.init() first.');
|
||||
}
|
||||
|
||||
const db = {
|
||||
sequelize: models.sequelize || global.sequelize,
|
||||
Sequelize: models.Sequelize
|
||||
};
|
||||
|
||||
return db[prop];
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user