Skip to content

feat: customize load in agent or in app #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -82,6 +84,8 @@ egg-sequelize has a default sequelize options below

```js
{
app: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解释一下这两个参数的含义

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方是告诉用户默认配置是什么,参数具体的解释放在这里吧:

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好,是我看错了

agent: true,
delegate: 'model',
baseDir: 'model',
logging(...args) {
Expand Down Expand Up @@ -363,4 +367,3 @@ Please open an issue [here](https://github.com/eggjs/egg/issues).
## License

[MIT](LICENSE)

4 changes: 3 additions & 1 deletion agent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

module.exports = agent => {
require('./lib/loader')(agent);
if (agent.config.sequelize.agent) {
require('./lib/loader')(agent);
}
};
5 changes: 3 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

module.exports = app => {
require('./lib/loader')(app);
if (app.config.sequelize.app) {
require('./lib/loader')(app);
}
};

2 changes: 2 additions & 0 deletions config/config.default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

exports.sequelize = {
agent: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文档里面加一下这两个参数

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

app: true,
dialect: 'mysql',
database: '',
host: 'localhost',
Expand Down
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/apps/connection-uri/config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default (appInfo: EggAppInfo) => {
config.keys = '123123';

config.sequelize = {
app: true,
agent: true,
}

return config;
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/apps/datasources-same-dir/config/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

exports.sequelize = {
app: true,
agent: true,
datasources: [
{
delegate: 'model',
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/apps/datasources/config/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

exports.sequelize = {
app: true,
agent: true,
datasources: [
{
delegate: 'model',
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/apps/model-app/config/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

exports.sequelize = {
app: true,
agent: true,
port: '3306',
host: '127.0.0.1',
username: 'root',
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/apps/sub-model/config/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

exports.sequelize = {
app: true,
agent: true,
port: '3306',
host: '127.0.0.1',
username: 'root',
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/apps/ts/config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default (appInfo: EggAppInfo) => {
config.keys = '123123';

config.sequelize = {
app: true,
agent: true,
datasources: [
{
delegate: 'model',
Expand Down