You can simply create two adapters, for example:
var activeRecord = require('mysql-activerecord'); var readDB = new activeRecord.Adapter({ server: 'slave.db.com', username: 'user', password: 'pass', database: 'db' }); var writeDB = new activeRecord.Adapter({ server: 'master.db.com', username: 'user', password: 'pass', database: 'db' });
When you go to update or another write request, use writeDB ; when you go to use select , use readDB .
Another option would be to switch to another ORM that supports this out of the box. I know this is not so good for a solution. Sequelize , for example, is widely used and supports this out of the box.
source share