You can create multiple data sources inside datasources.json or dynamically create data sources. For your specific case, you need to install loopback-connector-mysql and loopback-connector -PosgreSQL
datasourcses.json
{ "mysql": { "name": "mysql", "connector": "mysql" }, "postgresql": { "name": "postgresql", "connector": "postgresql" } }
Remember to add the host, port, username, password, and other properties to establish the connection correctly.
The next thing to do is use the attachTo () method to change the model data source when you want to switch the database.
app.models.YourModel.attachTo(app.dataSources.mysql); ... or ... app.models.YourModel.attachTo(app.dataSources.postgresql);
Also check this answer
AZ
source share