Add support for multiple database connection simultaneously #22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement support for multiple data store connections, if defined.
If there are different connections defined in the models (eg.
User.options.connection = 'myMySqlConn'
andStore.options.connection = 'myPostgresConn'
), then it will search for these connections in thesails.config.connections
file and initialize a sequelize connection instance for each data store. And it will add each connection instance to theglobal['sequelize']
pool asglobal['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).