I'm building a rest api using sails js v 1.x I need to connect two mysql database so I have defined them in config/datastores.js file life this:
module.exports.datastores = {
default: {
adapter: require('sails-mysql'),
url: 'mysql://root:12345@192.168.0.5:3306/test',
},
mysqldb: {
adapter: require('sails-mysql'),
url: 'mysql://root:12345@192.168.0.5:3306/test2',
},
};
In my controller, I have this function which needs to get data by joining the database test as well as test2
module.exports = {
index: function (req, res) {
User.getDatastore().sendNativeQuery("SELECT * from test.users u INNER JOIN test2.users t ON u.id=t.id limit 10",function(err, rawResult) {
res.send(rawResult);
})
},
};
But this gives me an error :
{
"code": "ER_NO_SUCH_TABLE",
"errno": 1146,
"sqlMessage": "Table 'test.users' doesn't exist",
}
Also I have a blank User model and execution of raw sql queries work perfecty when the query is like select * from users
(it uses the default database i.e test)
How do I achieve this kind of query by connecting more than one MySQL database in sails js?