File tree Expand file tree Collapse file tree 3 files changed +24
-67
lines changed Expand file tree Collapse file tree 3 files changed +24
-67
lines changed Original file line number Diff line number Diff line change 1
- const { registerPlugin } = require ( '@142vip/egg' )
2
- const { RegisterEggPluginName } = require ( '@142vip/egg' )
3
- const { createMysqlInstance } = require ( './core/mysql' )
1
+ const { RegisterEggPluginName, EggPluginBoot } = require ( '@142vip/egg' )
2
+ const { createEggMysqlInstance } = require ( './core/mysql' )
4
3
5
4
/**
6
5
* agent启动器
7
6
*/
8
- class EggMysqlAgentBoot {
7
+ class EggMysqlAgentBoot extends EggPluginBoot {
9
8
constructor ( agent ) {
10
- this . agent = agent
11
- }
12
-
13
- configWillLoad ( ) {
14
- console . log ( this . agent )
15
- }
16
-
17
- configDidLoad ( ) {
18
- }
19
-
20
- async didLoad ( ) {
21
- // 所有文件已加载,此时可以启动插件。
22
- if ( this . agent . config [ RegisterEggPluginName . EGG_MYSQL ] ) {
23
- registerPlugin ( RegisterEggPluginName . EGG_MYSQL , this . agent , createMysqlInstance )
24
- }
9
+ super ( {
10
+ pluginName : RegisterEggPluginName . EGG_MYSQL ,
11
+ appOrAgent : agent ,
12
+ createEggPluginInstance : createEggMysqlInstance ,
13
+ } )
25
14
}
26
15
}
27
16
Original file line number Diff line number Diff line change 1
- const { registerPlugin } = require ( '@142vip/egg' )
2
- const { RegisterEggPluginName } = require ( '@142vip/egg' )
3
- const { createMysqlInstance } = require ( './core/mysql' )
1
+ const { RegisterEggPluginName, EggPluginBoot } = require ( '@142vip/egg' )
2
+ const { createEggMysqlInstance } = require ( './core/mysql' )
4
3
5
- class EggMysqlAppBoot {
4
+ class EggMysqlAppBoot extends EggPluginBoot {
6
5
constructor ( app ) {
7
- this . app = app
8
- }
9
-
10
- configWillLoad ( ) {
11
- // 预备调用 configDidLoad,
12
- // Config 和 plugin 文件已被引用,
13
- // 这是修改配置的最后机会。
14
- console . log ( this . app )
15
- }
16
-
17
- configDidLoad ( ) {
18
- // Config 和 plugin 文件已加载。
19
- }
20
-
21
- async didLoad ( ) {
22
- // 所有文件已加载,此时可以启动插件。
23
- if ( this . app . config [ RegisterEggPluginName . EGG_MYSQL ] ) {
24
- console . log ( 111 , this . app . config . mysql )
25
- registerPlugin ( RegisterEggPluginName . EGG_MYSQL , this . app , createMysqlInstance )
26
- }
27
- }
28
-
29
- async willReady ( ) {
30
- // 所有插件已启动,这里可以执行一些在应用准备好之前的操作。
31
- }
32
-
33
- async didReady ( ) {
34
- // Worker 已准备好,可以执行一些不会阻塞应用启动的操作。
35
- }
36
-
37
- async serverDidReady ( ) {
38
- // 服务器已监听。
39
- }
40
-
41
- async beforeClose ( ) {
42
- // 应用关闭前执行的操作。
6
+ super ( {
7
+ pluginName : RegisterEggPluginName . EGG_MYSQL ,
8
+ appOrAgent : app ,
9
+ createEggPluginInstance : createEggMysqlInstance ,
10
+ } )
43
11
}
44
12
}
45
13
Original file line number Diff line number Diff line change 1
1
const { VipEggPluginLogger } = require ( '@142vip/egg' )
2
2
const mysql = require ( 'mysql2/promise' )
3
- const { name : pkgName } = require ( '../package.json' )
4
3
const { createDataBase } = require ( './database' )
5
4
6
5
async function creatPool ( config ) {
@@ -27,19 +26,20 @@ async function creatPool(config) {
27
26
/**
28
27
* 创建MySQL实例
29
28
*/
30
- function createMysqlInstance ( config , app ) {
31
- const pluginLogger = VipEggPluginLogger . getInstance ( pkgName , app )
32
-
29
+ async function createEggMysqlInstance ( pluginConfig , app ) {
30
+ const pluginLogger = VipEggPluginLogger . getInstance ( pluginConfig , app )
33
31
try {
34
- const client = creatPool ( config )
35
- pluginLogger . info ( `DataBase create success , the name is ${ config . database } ` )
32
+ const client = await creatPool ( pluginConfig )
33
+ pluginLogger . info ( `dataBase create success , the name is ${ pluginConfig . database } ` )
36
34
return client
37
35
}
36
+
38
37
catch ( e ) {
39
- pluginLogger . error ( `DataBase create failed ,check egg-sequelize-plus config carefully ${ e . message } ` )
38
+ pluginLogger . error ( `dataBase create failed,check config carefully!!!!` )
39
+ pluginLogger . error ( e . message )
40
40
}
41
41
}
42
42
43
43
module . exports = {
44
- createMysqlInstance ,
44
+ createEggMysqlInstance ,
45
45
}
You can’t perform that action at this time.
0 commit comments