loopbackjs - How to configure two different datasource for a model in Strongloop Loopback framework? -
our mysql database set write clusters , read clusters, there way set strongloop loopback model (e.g. user) write mysql host , read mysql host b?
try use attachto() if want change datasource single model. example
app.models.yourmodel.attachto(app.datasources.readds); readdata(); ... app.models.yourmodel.attachto(app.datasources.writeds); writedata();
you have define readds , writeds datasources in datasources.json file:
{ "readds": { "host": "hosta", "database": "dbonhosta", "username": "user", "password": "password", "name": "readds", "connector": "mysql" }, "writeds": { "host": "hostb", "database": "dbonhostb", "username": "user", "password": "password", "name": "writeds", "connector": "mysql" } }
or can create datasources dynamically.
Comments
Post a Comment