[RUBY] Throw raw SQL to a read replica in Rails

I use a gem called switch_point, It's written only briefly in the readme, and it's difficult to understand because no example is shown, but it seems that you can use switch_point_proxy.model_for_connection.


For example, in the User model

use_switch_point :slave

Add like

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)

It seems that you can go like

Recommended Posts

Throw raw SQL to a read replica in Rails
How to insert a video in Rails
Steps to set a favicon in Rails
Convert to a tag to URL string in Rails
How to implement a like feature in Rails
How to easily create a pull-down in Rails
How to make a follow function in Rails
How to implement a like feature in Ajax in Rails
I want to use a little icon in Rails
[How to insert a video in haml with Rails]
How to write a date comparison search in Rails
I want to define a function in Rails Console
[Rails 6] How to set a background image in Rails [CSS]
[Rails] How to load JavaScript in a specific view
How to read rails routes
A story I was addicted to in Rails validation settings
Run raw sql in Hanami to get results not in columns
How to display a graph in Ruby on Rails (LazyHighChart)
Establish a search bar in Rails ~ Join multiple tables to search
Apply CSS to a specific View in Ruby on Rails
[Rails] A simple way to implement a self-introduction function in your profile
Add a search function in Rails.
Preparing to create a Rails application
[Rails] How to write in Japanese
Create a new app in Rails
Implement a contact form in Rails
How to introduce jQuery in Rails 6
I read "7 Design Patterns to Refactor MVC Components in Rails" (writing)
How to rename a model with foreign key constraints in Rails
How to install Swiper in Rails
Change from SQLite3 to PostgreSQL in a new Ruby on Rails project
[Rails] I want to send data of different models in a form
How to implement a slideshow using slick in Rails (one by one & multiple by one)
How to create a query using variables in GraphQL [Using Ruby on Rails]
[Rails] How to log in with a name by adding a devise name column
How to update user edits in Rails Devise without entering a password
How to implement search functionality in Rails
How to use custom helpers in rails
How to use MySQL in Rails tutorial
[rails] How to configure routing in resources
Notation to put a variable in a string
[rails] How to create a partial template
How to implement ranking functionality in Rails
How to publish a library in jCenter
How to use credentials.yml.enc introduced in Rails 5.2
Introduced # 10 devise_token_auth to build a bulletin board API with authentication authorization in Rails 6
[Rails / JavaScript / Ajax] I tried to create a like function in two ways.
I want to be able to read a file using refile with administrate [rails6]
Introducing # 15 pundit to build a bulletin board API with authentication authorization in Rails 6
A memo to simply create a form using only HTML and CSS in Rails 6
[Rails] How to get rid of flash messages in a certain amount of time
How to store data simultaneously in a model associated with a nested form (Rails 6.0.0)
How to make a unique combination of data in the rails intermediate table
Rails: How to write a rake task nicely
Two ways to start a thread in Java + @
Read a string in a PDF file with Java
[Rails] How to write when making a subquery
[Rails] Various ways to write in seed files
[Rails] How to create a graph using lazy_high_charts
How to display a web page in Java
[Rails] How to use select boxes in Ransack