$ npm i @diyaner/egg-typeorm --save
// {app_root}/config/plugin.js
exports.typeorm = {
enable: true,
package: '@diyaner/egg-typeorm',
};
// {app_root}/config/config.default.js
exports.typeorm = {
agent:true,
datasources:[
{...}
]
};
see config/config.default.js for more detail.
- 实体entity放在app/entity目录下
- 实体必须使用默认default导出,这样才能正确使用ets自动类型声明并绑定给app.entity
- 实体default导出,同时还是必须要设置class的类名,否则typeorm无法正确解析设置数据库表名
- 如果有多个连接,则每个连接必须提供name属性,且唯一。name也是entity下的子目录区分。这是entity目录下直接实体将挂在第一个数据库配置连接上。比如连接2使用db2,则entity目录下db2目录下的entity才会绑定给这个连接。
- 如果单个连接,则所有实体entity都会挂在这个连接上,不会按二级目录区分。
Please open an issue here.