带有Mysql Master / Slave的Datamapper
作者:互联网
我似乎无法找到有关如何使用datamapper与mysql主/从设置进行通信的任何信息.我正在使用dm-mysql-adapter运行rails3
解决方法:
您可以使用DataMapper的Multiple Data Store功能:
DataMapper.setup(:default, 'mysql://master-host/mydb')
DataMapper.setup(:slave, 'mysql://slave-host/mydb')
现在,无论何时您想从奴隶中读取,请使用:
DataMapper.repository(:slave) do
Person.first
end
不幸的是,它看起来不像你可以做透明的read-from-slave写入到master:
[…] This will use your connection to the :external data-store and the
first Person it finds. Later, when you call .save on that person,
it’ll get saved back to the :external data-store; An object is aware
of what context it came from and should be saved back to.
因此,如果您尝试保存从从站检索到的人员,则会在修改后尝试将其存储回从属数据库.
标签:mysql,ruby-on-rails-3,ruby,datamapper 来源: https://codeday.me/bug/20190704/1381448.html