From 30932fc5d39565fdfbc47883ee38d2d6e85b6487 Mon Sep 17 00:00:00 2001 From: chenzheqi Date: Wed, 9 Sep 2020 20:29:06 +0800 Subject: [PATCH 1/7] feat: customize load in agent or in app --- agent.js | 4 +++- app.js | 5 +++-- config/config.default.js | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/agent.js b/agent.js index 92b0d38..81c3948 100644 --- a/agent.js +++ b/agent.js @@ -1,5 +1,7 @@ 'use strict'; module.exports = agent => { - require('./lib/loader')(agent); + if (agent.config.sequelize.agent) { + require('./lib/loader')(agent); + } }; diff --git a/app.js b/app.js index 1d56502..fba03d8 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ 'use strict'; module.exports = app => { - require('./lib/loader')(app); + if (app.config.sequelize.app) { + require('./lib/loader')(app); + } }; - diff --git a/config/config.default.js b/config/config.default.js index 8fadc8a..9201407 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -1,6 +1,8 @@ 'use strict'; exports.sequelize = { + agent: false, + app: true, dialect: 'mysql', database: '', host: 'localhost', From 8bd089e1dd0a63d35e7005ee992dfabe610a1976 Mon Sep 17 00:00:00 2001 From: chenzheqi Date: Wed, 9 Sep 2020 20:36:15 +0800 Subject: [PATCH 2/7] fix: modify default config --- config/config.default.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.default.js b/config/config.default.js index 9201407..14d4616 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -1,7 +1,7 @@ 'use strict'; exports.sequelize = { - agent: false, + agent: true, app: true, dialect: 'mysql', database: '', From 6b420d7f47c9367780abede32e966843fc99a5a2 Mon Sep 17 00:00:00 2001 From: chenzheqi Date: Wed, 9 Sep 2020 20:43:42 +0800 Subject: [PATCH 3/7] test: modify test app config --- test/fixtures/apps/connection-uri/config/config.default.ts | 2 ++ test/fixtures/apps/datasources-same-dir/config/config.js | 2 ++ test/fixtures/apps/datasources/config/config.js | 2 ++ test/fixtures/apps/model-app/config/config.js | 2 ++ test/fixtures/apps/sub-model/config/config.js | 2 ++ test/fixtures/apps/ts/config/config.default.ts | 2 ++ 6 files changed, 12 insertions(+) diff --git a/test/fixtures/apps/connection-uri/config/config.default.ts b/test/fixtures/apps/connection-uri/config/config.default.ts index f407e1f..b892428 100644 --- a/test/fixtures/apps/connection-uri/config/config.default.ts +++ b/test/fixtures/apps/connection-uri/config/config.default.ts @@ -7,6 +7,8 @@ export default (appInfo: EggAppInfo) => { config.keys = '123123'; config.sequelize = { + app: true, + agent: true, } return config; diff --git a/test/fixtures/apps/datasources-same-dir/config/config.js b/test/fixtures/apps/datasources-same-dir/config/config.js index ff49b15..55d81c9 100644 --- a/test/fixtures/apps/datasources-same-dir/config/config.js +++ b/test/fixtures/apps/datasources-same-dir/config/config.js @@ -1,6 +1,8 @@ 'use strict'; exports.sequelize = { + app: true, + agent: true, datasources: [ { delegate: 'model', diff --git a/test/fixtures/apps/datasources/config/config.js b/test/fixtures/apps/datasources/config/config.js index ed81e06..a26e492 100644 --- a/test/fixtures/apps/datasources/config/config.js +++ b/test/fixtures/apps/datasources/config/config.js @@ -1,6 +1,8 @@ 'use strict'; exports.sequelize = { + app: true, + agent: true, datasources: [ { delegate: 'model', diff --git a/test/fixtures/apps/model-app/config/config.js b/test/fixtures/apps/model-app/config/config.js index 7ddbbf9..e56e2b1 100644 --- a/test/fixtures/apps/model-app/config/config.js +++ b/test/fixtures/apps/model-app/config/config.js @@ -1,6 +1,8 @@ 'use strict'; exports.sequelize = { + app: true, + agent: true, port: '3306', host: '127.0.0.1', username: 'root', diff --git a/test/fixtures/apps/sub-model/config/config.js b/test/fixtures/apps/sub-model/config/config.js index 7ddbbf9..e56e2b1 100644 --- a/test/fixtures/apps/sub-model/config/config.js +++ b/test/fixtures/apps/sub-model/config/config.js @@ -1,6 +1,8 @@ 'use strict'; exports.sequelize = { + app: true, + agent: true, port: '3306', host: '127.0.0.1', username: 'root', diff --git a/test/fixtures/apps/ts/config/config.default.ts b/test/fixtures/apps/ts/config/config.default.ts index 48b0364..c6e4912 100644 --- a/test/fixtures/apps/ts/config/config.default.ts +++ b/test/fixtures/apps/ts/config/config.default.ts @@ -7,6 +7,8 @@ export default (appInfo: EggAppInfo) => { config.keys = '123123'; config.sequelize = { + app: true, + agent: true, datasources: [ { delegate: 'model', From 2040b093c39c32766a024d6a04aa89e089ed06e4 Mon Sep 17 00:00:00 2001 From: chenzheqi Date: Wed, 9 Sep 2020 20:48:03 +0800 Subject: [PATCH 4/7] docs: update index.d.ts --- index.d.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.d.ts b/index.d.ts index b1c57b3..a81d1a0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -22,6 +22,18 @@ interface EggSequelizeOptions extends sequelize.Options { * `connectionUri:"mysql://localhost:3306/database"` */ connectionUri?: string; + + /** + * Load sequelize in worker + * @default true + */ + app?: boolean; + + /** + * Load sequelize in agent + * @default true + */ + agent?: boolean; } interface DataSources { From c7de444ac2b395f91ffed749390bc45f07429d25 Mon Sep 17 00:00:00 2001 From: chenzheqi Date: Thu, 10 Sep 2020 09:24:44 +0800 Subject: [PATCH 5/7] docs: update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec27699..9984f87 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ egg-sequelize has a default sequelize options below ```js { + app: true, + agent: true, delegate: 'model', baseDir: 'model', logging(...args) { @@ -363,4 +365,3 @@ Please open an issue [here](https://github.com/eggjs/egg/issues). ## License [MIT](LICENSE) - From c0d8a73faed52431f9fc1dcd378811e6b6a5aa56 Mon Sep 17 00:00:00 2001 From: chenzheqi Date: Thu, 10 Sep 2020 11:38:40 +0800 Subject: [PATCH 6/7] docs: update comment --- README.md | 2 ++ index.d.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9984f87..674cc9d 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,9 @@ egg-sequelize has a default sequelize options below ```js { + // load sequelize in app(worker) app: true, + // load sequelize in agent agent: true, delegate: 'model', baseDir: 'model', diff --git a/index.d.ts b/index.d.ts index a81d1a0..e18ee09 100644 --- a/index.d.ts +++ b/index.d.ts @@ -24,7 +24,7 @@ interface EggSequelizeOptions extends sequelize.Options { connectionUri?: string; /** - * Load sequelize in worker + * Load sequelize in app(worker) * @default true */ app?: boolean; From 33b819b287993b0d74de2386c0497f6adfc549f8 Mon Sep 17 00:00:00 2001 From: chenzheqi Date: Thu, 10 Sep 2020 15:03:25 +0800 Subject: [PATCH 7/7] docs: update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 674cc9d..f72f328 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ exports.sequelize = { ```js exports.sequelize = { + app: true, // load sequelize in app(worker) + agent: true, // load sequelize in agent dialect: 'mysql', // support: mysql, mariadb, postgres, mssql database: 'test', host: 'localhost', @@ -82,9 +84,7 @@ egg-sequelize has a default sequelize options below ```js { - // load sequelize in app(worker) app: true, - // load sequelize in agent agent: true, delegate: 'model', baseDir: 'model',