My requirement is to connect to dynamic databases of postgresql after the sails is lifted in sails api v 0.12. From angular ui, i have a drop down of different DB values i am sending one param (dbhostname)to dummycontroller.js and want to connect to that particular db whenever the db string name matches in connections.js
1) how to pass the api dummycontroller.js param ((dbhostname)) to connections.js 2) how to dynamically access the db hosts in connections.js or models.js. where to put them with if conditions ?
dummycontroller.js
from ui select drop down, the db value is passed to dummycontroller.js with api trigger
http://localhost:1337/api/dummy/dynamicDb?db=db
module.exports = {
dynamicDb: function (req, res, next) {
const db= req.query.db;
console.log(db);
const qry = "select * from person where city= "newyork";
console.log(qry);
dummy.query(qry,function (err, resp) {
//user = JSON.parse(user);
if (err) {
return res.json({
error: err
});
}
if (resp === undefined) {
return res.notFound();
} else
console.log(resp);
return res.json({
userData: resp.rows
});
}
);
}}
I want to capture db value and send to connections or models.js and select different db host based on db value and then trigger the db query in dummycontroller.js.