Using node.js, how can I write to one MySQL DB and read from another? -


specifically, i'm talking mysql master-slave(s) replication. understand it, of reads should happen slave (or multiple slaves hid behind load balancer) , of writes directly master.

how can node.js? i'm using mysql active record package database queries , don't think supports natively. supposed can hack away @ package , have if write-query, use db1 type of situation, wonder if there's easier way.

you can create 2 adapters this:

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 go update or other writing query, use writedb; when go select use readdb.

another option switch orm supports out of box. know isn't nice of solution though. sequelize example used , supports out of box.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -