@diyaner/egg-typeorm
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

egg-ts-template

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i @diyaner/egg-typeorm --save

Usage

// {app_root}/config/plugin.js
exports.typeorm = {
  enable: true,
  package: '@diyaner/egg-typeorm',
};

Configuration

// {app_root}/config/config.default.js
exports.typeorm = {
  agent:true,
  datasources:[
    {...}
  ]
};

see config/config.default.js for more detail.

Example

  • 实体entity放在app/entity目录下
  • 实体必须使用默认default导出,这样才能正确使用ets自动类型声明并绑定给app.entity
  • 实体default导出,同时还是必须要设置class的类名,否则typeorm无法正确解析设置数据库表名
  • 如果有多个连接,则每个连接必须提供name属性,且唯一。name也是entity下的子目录区分。这是entity目录下直接实体将挂在第一个数据库配置连接上。比如连接2使用db2,则entity目录下db2目录下的entity才会绑定给这个连接。
  • 如果单个连接,则所有实体entity都会挂在这个连接上,不会按二级目录区分。

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i @diyaner/egg-typeorm

Weekly Downloads

6

Version

2.2.0

License

MIT

Unpacked Size

41.7 kB

Total Files

19

Last publish

Collaborators

  • dingiyan