Datamapper with Mysql Master / Slave

I can't seem to find information on how to use the datamapper dialog to configure the master / slave mysql. I am running rails3 using dm-mysql-adapter

+4
source share
4 answers

To do this, you can use the DataMapper function Multiple data stores :

DataMapper.setup(:default, 'mysql://master-host/mydb') DataMapper.setup(:slave, 'mysql://slave-host/mydb') 

Now that you want to read from a slave, use:

 DataMapper.repository(:slave) do Person.first end 

Unfortunately, this does not look like you can do transparent write-from-slave-write-to-master:

[...] This will use your connection to: an external data store and the first person he finds. Later, when you call .save on this person, he will be saved back to: external data storage; The object is aware of the context from which it came and must be saved back.

So, if you try to save the person you removed from the slave, he will try to save him back to the slave database when changing.

+2
source

It may be what you are looking for ...

https://github.com/d11wtq/dm-master-slave-adapter

+2
source

you do not need to do this in your application, but Mysql can handle this itself. In this way, you can take full advantage of load balancing and high availability with automatic wizard failure with you. I highly recommend this setting in manual application-based load balancing, as you must leave the persistence layer out of the business logic provided by your application. This brings written benefits and makes your application more scalable and maintainable due to better separation of concerns.

Check out the Mysql NDB documentation for concepts and this tutorial for a quick start on Mysql clustering.

0
source

1) You must install the adapter.

2) Add requires require "rubigems" require 'data_mapper' 3) Configure my sql

 DataMapper.setup(:default, 'mysql://localhost/the_database_name') 

or

 DataMapper.mysql(:host xxxx, :user xxxx, :password xxxx, :database xxxx) 

4) Create model objects, for example:

 class Post include DataMapper::Resource property :id, Serial # An auto-increment integer key property :title, String # A varchar type string, for short strings property :body, Text # A text block, for longer string data. property :created_at, DateTime # A DateTime, for any date you might like. end 

If you have any doubts, you can check this link: http://datamapper.org/getting-started

-2
source

All Articles