是的,您可以定义多个连接并将每个模型设置为使用不同的连接.请参阅
documentation on connections以获取完整的评论.
您可以在config / connections.js文件中根据需要设置任意数量的连接.您甚至可以使用同一个适配器设置多个连接:
module.exports.connections = {
// A MySQL connection
mysql1: {
adapter: 'sails-mysql',
user: 'root',
host: 'localhost',
database: 'database1'
},
// Another MySQL connection, same server, different database
mysql2: {
adapter: 'sails-mysql',
user: 'root',
host: 'localhost',
database: 'database2'
},
// A Postgresql connection
postgres: {
adapter: 'sails-postgresql',
user: 'postgres',
host: 'localhost',
database: 'mypsqldb'
}
};
然后在模型类文件中,指定用于该模型的连接:
module.exports = {
connection: 'mysql1',
attributes: {...}
}
要指定模型的默认连接,请在config / models.js中进行设置:
module.export.models = {
connection: 'mysql2'
};