1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Railsで生SQLをリードレプリカに投げる

Posted at

switch_pointというgemを使用するのだが、
readmeにちらっとだけ書いてあって、例が示されてないのでわかりにくいがswitch_point_proxy.model_for_connectionってのを使えばいいみたい

https://github.com/eagletmt/switch_point

例えばUserモデルだったら、

use_switch_point :slave

みたいに追加して、

rows = []

User.with_readonly do
  con = User.switch_point_proxy.model_for_connection.connection
  sql = "select * from users limit 1"
  rows = con.select_all(sql)
end

みたいな感じで行けるみたい

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?