Skip to content
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

refactor: do not subclass by default #120

Merged
merged 1 commit into from
Jun 25, 2021
Merged

refactor: do not subclass by default #120

merged 1 commit into from
Jun 25, 2021

Conversation

cyjake
Copy link
Owner

@cyjake cyjake commented Jun 24, 2021

  • gather around glue code for legacy timestamp

- gather around glue code for legacy timestamp
assert.equal(arda.Bone, Bone);

const realm = new Realm({ subclass: true });
assert.ok(realm.Bone.prototype instanceof Bone);
Copy link
Owner Author

Choose a reason for hiding this comment

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

egg-orm will turn opts.subclass on by default, which (theoretically) makes connecting to multiple databases simultaneously possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

subclass is not easy to understand, how about change another name, for example: singleConnection?

Copy link
Owner Author

Choose a reason for hiding this comment

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

There always is only one connection pool for realm instance. When multiple datasources is specified in egg-orm, egg-orm tries to instantiate multiple realms to retain multiple connection pools with the config specified in datasources array.

We made this possible by subclassing Bone. But this feature is seldom used (at least for now) hence I intend to not make this the default behavior.

if (opts.sequelize) return sequelize(Bone);
if (opts.subclass !== true) return Bone;
Copy link
Owner Author

Choose a reason for hiding this comment

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

For simple cases, Bone is not required to be subclassed to possess connection to database. Most of the time, the connection pool is shared at process level. By shortening prototype lookup chain, we can make function calls on Bone.prototype faster a bit.

@JimmyDaddy JimmyDaddy merged commit 1eff174 into master Jun 25, 2021
@cyjake cyjake deleted the refactor-connect branch July 5, 2021 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants