@diyaner/egg-typeorm 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/README.zh_CN.md +76 -0
- package/agent.js +21 -0
- package/app.js +19 -0
- package/config/config.default.js +10 -0
- package/index.d.ts +36 -0
- package/package.json +60 -0
- package/tshelper.js +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-present Alibaba Group Holding Limited and other contributors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# egg-ts-template
|
|
2
|
+
|
|
3
|
+
[![NPM version][npm-image]][npm-url]
|
|
4
|
+
[![build status][travis-image]][travis-url]
|
|
5
|
+
[![Test coverage][codecov-image]][codecov-url]
|
|
6
|
+
[![David deps][david-image]][david-url]
|
|
7
|
+
[![Known Vulnerabilities][snyk-image]][snyk-url]
|
|
8
|
+
[![npm download][download-image]][download-url]
|
|
9
|
+
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/egg-ts-template.svg?style=flat-square
|
|
11
|
+
[npm-url]: https://npmjs.org/package/egg-ts-template
|
|
12
|
+
[travis-image]: https://img.shields.io/travis/eggjs/egg-ts-template.svg?style=flat-square
|
|
13
|
+
[travis-url]: https://travis-ci.org/eggjs/egg-ts-template
|
|
14
|
+
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-ts-template.svg?style=flat-square
|
|
15
|
+
[codecov-url]: https://codecov.io/github/eggjs/egg-ts-template?branch=master
|
|
16
|
+
[david-image]: https://img.shields.io/david/eggjs/egg-ts-template.svg?style=flat-square
|
|
17
|
+
[david-url]: https://david-dm.org/eggjs/egg-ts-template
|
|
18
|
+
[snyk-image]: https://snyk.io/test/npm/egg-ts-template/badge.svg?style=flat-square
|
|
19
|
+
[snyk-url]: https://snyk.io/test/npm/egg-ts-template
|
|
20
|
+
[download-image]: https://img.shields.io/npm/dm/egg-ts-template.svg?style=flat-square
|
|
21
|
+
[download-url]: https://npmjs.org/package/egg-ts-template
|
|
22
|
+
|
|
23
|
+
<!--
|
|
24
|
+
Description here.
|
|
25
|
+
-->
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$ npm i egg-ts-template --save
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
// {app_root}/config/plugin.js
|
|
37
|
+
exports.typeorm = {
|
|
38
|
+
enable: true,
|
|
39
|
+
package: 'egg-typeorm',
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Configuration
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
// {app_root}/config/config.default.js
|
|
47
|
+
exports.typeorm = {
|
|
48
|
+
agent:true,
|
|
49
|
+
datasources:[
|
|
50
|
+
{...}
|
|
51
|
+
]
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
see [config/config.default.js](config/config.default.js) for more detail.
|
|
56
|
+
|
|
57
|
+
## Example
|
|
58
|
+
|
|
59
|
+
<!-- example here -->
|
|
60
|
+
- 实体entity放在app/entity目录下
|
|
61
|
+
- 实体必须使用默认default导出,这样才能正确使用ets自动类型声明并绑定给app.entity
|
|
62
|
+
- 实体default导出,同时还是必须要设置class的类名,否则typeorm无法正确解析设置数据库表名
|
|
63
|
+
- 如果有多个连接,则每个连接必须提供name属性,且唯一。name也是entity下的子目录区分。这是entity目录下直接实体将挂在第一个数据库配置连接上。比如连接2使用db2,则entity目录下db2目录下的entity才会绑定给这个连接。
|
|
64
|
+
- 如果单个连接,则所有实体entity都会挂在这个连接上,不会按二级目录区分。
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Questions & Suggestions
|
|
70
|
+
|
|
71
|
+
Please open an issue [here](https://github.com/eggjs/egg/issues).
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
[MIT](LICENSE)
|
package/README.zh_CN.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# egg-ts-template
|
|
2
|
+
|
|
3
|
+
[![NPM version][npm-image]][npm-url]
|
|
4
|
+
[![build status][travis-image]][travis-url]
|
|
5
|
+
[![Test coverage][codecov-image]][codecov-url]
|
|
6
|
+
[![David deps][david-image]][david-url]
|
|
7
|
+
[![Known Vulnerabilities][snyk-image]][snyk-url]
|
|
8
|
+
[![npm download][download-image]][download-url]
|
|
9
|
+
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/egg-ts-template.svg?style=flat-square
|
|
11
|
+
[npm-url]: https://npmjs.org/package/egg-ts-template
|
|
12
|
+
[travis-image]: https://img.shields.io/travis/eggjs/egg-ts-template.svg?style=flat-square
|
|
13
|
+
[travis-url]: https://travis-ci.org/eggjs/egg-ts-template
|
|
14
|
+
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-ts-template.svg?style=flat-square
|
|
15
|
+
[codecov-url]: https://codecov.io/github/eggjs/egg-ts-template?branch=master
|
|
16
|
+
[david-image]: https://img.shields.io/david/eggjs/egg-ts-template.svg?style=flat-square
|
|
17
|
+
[david-url]: https://david-dm.org/eggjs/egg-ts-template
|
|
18
|
+
[snyk-image]: https://snyk.io/test/npm/egg-ts-template/badge.svg?style=flat-square
|
|
19
|
+
[snyk-url]: https://snyk.io/test/npm/egg-ts-template
|
|
20
|
+
[download-image]: https://img.shields.io/npm/dm/egg-ts-template.svg?style=flat-square
|
|
21
|
+
[download-url]: https://npmjs.org/package/egg-ts-template
|
|
22
|
+
|
|
23
|
+
<!--
|
|
24
|
+
Description here.
|
|
25
|
+
-->
|
|
26
|
+
|
|
27
|
+
## 依赖说明
|
|
28
|
+
|
|
29
|
+
### 依赖的 egg 版本
|
|
30
|
+
|
|
31
|
+
egg-ts-template 版本 | egg 1.x
|
|
32
|
+
--- | ---
|
|
33
|
+
1.x | 😁
|
|
34
|
+
0.x | ❌
|
|
35
|
+
|
|
36
|
+
### 依赖的插件
|
|
37
|
+
<!--
|
|
38
|
+
|
|
39
|
+
如果有依赖其它插件,请在这里特别说明。如
|
|
40
|
+
|
|
41
|
+
- security
|
|
42
|
+
- multipart
|
|
43
|
+
|
|
44
|
+
-->
|
|
45
|
+
|
|
46
|
+
## 开启插件
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// config/plugin.js
|
|
50
|
+
exports.tsTemplate = {
|
|
51
|
+
enable: true,
|
|
52
|
+
package: 'egg-ts-template',
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 使用场景
|
|
57
|
+
|
|
58
|
+
- Why and What: 描述为什么会有这个插件,它主要在完成一件什么事情。
|
|
59
|
+
尽可能描述详细。
|
|
60
|
+
- How: 描述这个插件是怎样使用的,具体的示例代码,甚至提供一个完整的示例,并给出链接。
|
|
61
|
+
|
|
62
|
+
## 详细配置
|
|
63
|
+
|
|
64
|
+
请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。
|
|
65
|
+
|
|
66
|
+
## 单元测试
|
|
67
|
+
|
|
68
|
+
<!-- 描述如何在单元测试中使用此插件,例如 schedule 如何触发。无则省略。-->
|
|
69
|
+
|
|
70
|
+
## 提问交流
|
|
71
|
+
|
|
72
|
+
请到 [egg issues](https://github.com/eggjs/egg/issues) 异步交流。
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
[MIT](LICENSE)
|
package/agent.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const loader_1 = require("./lib/loader");
|
|
5
|
+
const connection_1 = require("./lib/connection");
|
|
6
|
+
class EggTypeOrmAppBoot {
|
|
7
|
+
constructor(app) {
|
|
8
|
+
this.app = app;
|
|
9
|
+
}
|
|
10
|
+
configDidLoad() {
|
|
11
|
+
if (this.app.config.typeorm.agent) {
|
|
12
|
+
this.app.typeorm = this.app.typeorm || {
|
|
13
|
+
dataSource: {},
|
|
14
|
+
};
|
|
15
|
+
loader_1.default(this.app);
|
|
16
|
+
connection_1.default(this.app);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = EggTypeOrmAppBoot;
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJhZ2VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLDRCQUEwQjtBQUUxQix5Q0FBc0M7QUFDdEMsaURBQTJDO0FBRTNDLE1BQXFCLGlCQUFpQjtJQUVyQyxZQUFZLEdBQWdCO1FBQzNCLElBQUksQ0FBQyxHQUFHLEdBQUcsR0FBRyxDQUFDO0lBQ2hCLENBQUM7SUFDRCxhQUFhO1FBQ1osSUFBSSxJQUFJLENBQUMsR0FBRyxDQUFDLE1BQU0sQ0FBQyxPQUFPLENBQUMsS0FBSyxFQUFFO1lBQ2xDLElBQUksQ0FBQyxHQUFHLENBQUMsT0FBTyxHQUFHLElBQUksQ0FBQyxHQUFHLENBQUMsT0FBTyxJQUFJO2dCQUN0QyxVQUFVLEVBQUUsRUFBRTthQUNkLENBQUM7WUFDRixnQkFBVSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztZQUNyQixvQkFBVyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztTQUl0QjtJQUNGLENBQUM7Q0FDRDtBQWpCRCxvQ0FpQkMifQ==
|
package/app.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const loader_1 = require("./lib/loader");
|
|
5
|
+
const connection_1 = require("./lib/connection");
|
|
6
|
+
class EggTypeOrmAppBoot {
|
|
7
|
+
constructor(app) {
|
|
8
|
+
this.app = app;
|
|
9
|
+
}
|
|
10
|
+
configDidLoad() {
|
|
11
|
+
this.app.typeorm = this.app.typeorm || {
|
|
12
|
+
dataSource: {}
|
|
13
|
+
};
|
|
14
|
+
loader_1.default(this.app);
|
|
15
|
+
connection_1.default(this.app);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = EggTypeOrmAppBoot;
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiYXBwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQ0EsNEJBQTBCO0FBRTFCLHlDQUFzQztBQUN0QyxpREFBMEM7QUFFMUMsTUFBcUIsaUJBQWlCO0lBRXJDLFlBQVksR0FBZ0I7UUFDM0IsSUFBSSxDQUFDLEdBQUcsR0FBRyxHQUFHLENBQUM7SUFDaEIsQ0FBQztJQUNELGFBQWE7UUFDWixJQUFJLENBQUMsR0FBRyxDQUFDLE9BQU8sR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLE9BQU8sSUFBSTtZQUN0QyxVQUFVLEVBQUMsRUFBRTtTQUNiLENBQUM7UUFDRixnQkFBVSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztRQUNyQixvQkFBVyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztJQUd2QixDQUFDO0NBR0Q7QUFoQkQsb0NBZ0JDIn0=
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = () => {
|
|
4
|
+
const config = {};
|
|
5
|
+
config.typeorm = {
|
|
6
|
+
agent: false
|
|
7
|
+
};
|
|
8
|
+
return config;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmRlZmF1bHQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjb25maWcuZGVmYXVsdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFRQSxZQUFZLENBQUM7O0FBVWIsa0JBQWUsR0FBRyxFQUFFO0lBQ25CLE1BQU0sTUFBTSxHQUFHLEVBQWdDLENBQUM7SUFDaEQsTUFBTSxDQUFDLE9BQU8sR0FBRztRQUNoQixLQUFLLEVBQUMsS0FBSztLQUNYLENBQUM7SUFDRixPQUFPLE1BQU0sQ0FBQztBQUNmLENBQUMsQ0FBQyJ9
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @copyright: Huang Ding
|
|
3
|
+
* @Author: ding-cx
|
|
4
|
+
* @Date: 2021-02-21 17:47:08
|
|
5
|
+
* @LastEditors: ding-cx
|
|
6
|
+
* @LastEditTime: 2021-02-21 17:47:51
|
|
7
|
+
* @Description: file content
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Egg from "egg";
|
|
11
|
+
import * as typeorm from "typeorm";
|
|
12
|
+
|
|
13
|
+
declare module "egg" {
|
|
14
|
+
/** egg插件的typeorm的连接选项 */
|
|
15
|
+
|
|
16
|
+
/** typeorm 已弃用name属性,但egg-typeorm需要使用 */
|
|
17
|
+
type EggConfigTypeormDataSourceOptions = { name?: string } & typeorm.DataSourceOptions;
|
|
18
|
+
interface EggAppConfig {
|
|
19
|
+
/** typeorm 数据库连接配置 */
|
|
20
|
+
typeorm: {
|
|
21
|
+
agent: boolean;
|
|
22
|
+
datasources: EggConfigTypeormDataSourceOptions[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Application {
|
|
27
|
+
typeorm: {
|
|
28
|
+
/** 数据库连接实例 其key为配置时的name属性 */
|
|
29
|
+
dataSource: {
|
|
30
|
+
[key: string]: typeorm.DataSource;
|
|
31
|
+
};
|
|
32
|
+
// entity: any;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export = Egg;
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diyaner/egg-typeorm",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "egg plugin for nodejs orm freamwork typeorm.",
|
|
5
|
+
"eggPlugin": {
|
|
6
|
+
"name": "typeorm"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"egg",
|
|
10
|
+
"eggPlugin",
|
|
11
|
+
"egg-plugin",
|
|
12
|
+
"egg-typeorm",
|
|
13
|
+
"typeorm"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"reflect-metadata": "^0.1.13",
|
|
17
|
+
"typeorm": "^0.3.13"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/mocha": "^8.2.1",
|
|
21
|
+
"autod": "^3.0.1",
|
|
22
|
+
"autod-egg": "^1.1.0",
|
|
23
|
+
"egg": "^2.16.0",
|
|
24
|
+
"egg-bin": "^4.11.0",
|
|
25
|
+
"egg-ci": "^1.11.0",
|
|
26
|
+
"egg-mock": "^3.21.0",
|
|
27
|
+
"eslint": "^5.13.0",
|
|
28
|
+
"eslint-config-egg": "^7.1.0",
|
|
29
|
+
"mysql2": "^3.2.0",
|
|
30
|
+
"typescript": "^4.1.5"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=12.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "npm run lint -- --fix && egg-bin pkgfiles && npm run test-local",
|
|
37
|
+
"test-local": "tsc && egg-bin test && npm run clean:js",
|
|
38
|
+
"tsc": "tsc",
|
|
39
|
+
"clean:js": "ets clean",
|
|
40
|
+
"release": "tsc && npm publish --access public && npm run clean:js",
|
|
41
|
+
"cov": "egg-bin cov",
|
|
42
|
+
"lint": "eslint .",
|
|
43
|
+
"ci": "egg-bin pkgfiles --check && npm run lint && npm run cov",
|
|
44
|
+
"pkgfiles": "egg-bin pkgfiles",
|
|
45
|
+
"autod": "autod"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"app.js",
|
|
49
|
+
"agent.js",
|
|
50
|
+
"tshelper.js",
|
|
51
|
+
"config/**/*.js",
|
|
52
|
+
"app/**/*.js",
|
|
53
|
+
"index.d.ts"
|
|
54
|
+
],
|
|
55
|
+
"ci": {
|
|
56
|
+
"version": "8, 10"
|
|
57
|
+
},
|
|
58
|
+
"author": "ding",
|
|
59
|
+
"license": "MIT"
|
|
60
|
+
}
|
package/tshelper.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
watchDirs: {
|
|
3
|
+
entity: {
|
|
4
|
+
directory: "app/entity",
|
|
5
|
+
generator: "object",
|
|
6
|
+
interface: "IEntity",
|
|
7
|
+
declareTo: "Application.entity",
|
|
8
|
+
// caseStyle: "upper",
|
|
9
|
+
watch: true,
|
|
10
|
+
distName: "entity.d.ts",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
generatorConfig: {
|
|
14
|
+
entity: {
|
|
15
|
+
directory: "app/entity",
|
|
16
|
+
generator: "object",
|
|
17
|
+
interface: "IEntity",
|
|
18
|
+
declareTo: "Application.entity",
|
|
19
|
+
// caseStyle: "upper",
|
|
20
|
+
watch: true,
|
|
21
|
+
distName: "entity.d.ts",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|