diff --git a/README.md b/README.md index ec27699..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,6 +84,8 @@ egg-sequelize has a default sequelize options below ```js { + app: true, + agent: true, delegate: 'model', baseDir: 'model', logging(...args) { @@ -363,4 +367,3 @@ Please open an issue [here](https://github.com/eggjs/egg/issues). ## License [MIT](LICENSE) - 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..14d4616 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -1,6 +1,8 @@ 'use strict'; exports.sequelize = { + agent: true, + app: true, dialect: 'mysql', database: '', host: 'localhost', diff --git a/index.d.ts b/index.d.ts index b1c57b3..e18ee09 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 app(worker) + * @default true + */ + app?: boolean; + + /** + * Load sequelize in agent + * @default true + */ + agent?: boolean; } interface DataSources { 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',