Do I need to create multiple instances of Sequelize if I want to use two databases? That is, two databases on the same machine.
If not, what's the proper way to do this? It seems like overkill to have to connect twice to use two databases, to me.
So for example, I have different databases for different functions, for example, let's say I have customer data in one database, and statistical data in another.
So in MySQL:
MySQL [customers]> show databases;
+--------------------+
| Database |
+--------------------+
| customers |
| stats |
+--------------------+
And I have this to connect with sequelize
// Create a connection....
var Sequelize = require('sequelize');
var sequelize = new Sequelize('customers', 'my_user', 'some_password', {
host: 'localhost',
dialect: 'mysql',
pool: {
max: 5,
min: 0,
idle: 10000
},
logging: function(output) {
if (opts.log_queries) {
log.it("sequelize_log",{log: output});
}
}
});
// Authenticate it.
sequelize.authenticate().nodeify(function(err) {
// Do stuff....
});
I tried to "trick" it by in a definition of a model using dot notation
var InterestingStatistics = sequelize.define('stats.interesting_statistics', { /* ... */ });
But that creates the table customers.stats.interesting_statistics
. I need to use an existing table in the stats database.
What's the proper way to achieve this? Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…