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

Add support for multiple database connection simultaneously #22

Conversation

gvko
Copy link

@gvko gvko commented Apr 12, 2016

Implement support for multiple data store connections, if defined.
If there are different connections defined in the models (eg. User.options.connection = 'myMySqlConn' and Store.options.connection = 'myPostgresConn'), then it will search for these connections in the sails.config.connections file and initialize a sequelize connection instance for each data store. And it will add each connection instance to the global['sequelize'] pool as global['sequelize'].myMySqlConn, etc.

If there's no connection property defined in a model - it will use the default connection defined in sails.config.models.

If there's only one connection defined at all, it will have this connection instance as it was before - simply as global['sequelize']. I made it this way so that current projects of people don't break after update (unless they decide to use multiple data store connections. Then they'll have to do some changes in their code).

I bumped up the version with a major update because if someone decides to use multiple connections, then it's not completely backwards-compatile (because of the global['sequelize'] pool of sequelize connection instances). If people remain with single data store connections, then everything works backwards-compatible and noone needs to make any changes. :)

P.S. Please tag the merge commit when/if you decide to merge (for easier reference in package lists).

Galin Kostov added 4 commits April 12, 2016 19:05
Refactor to loop through the models and initialize a Sequelize instance for each new connection that is defined in SomeModel.options.connection. If not defined - just use the default connection. If there is only one connection ever used - then it works as before.
@gvko gvko changed the title Feature/add connection to multiple databases simultaneously Feature - implement support for multiple database connection instances simultaneously Apr 13, 2016
@gvko gvko changed the title Feature - implement support for multiple database connection instances simultaneously Add support for multiple database connection simultaneously Apr 13, 2016
@KSDaemon KSDaemon mentioned this pull request Aug 11, 2017
@KSDaemon
Copy link
Owner

Hi! I've implemented this a little bit differently.
You can check and test it. Feel free to extend, test, and/or provide any other feedback!

@KSDaemon KSDaemon closed this Aug 15, 2017
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.

None yet

2 participants