# SQLRelay adapter for Rails?

**URL:** <https://www.ruby-forum.com/t/sqlrelay-adapter-for-rails/93179>\
**Category:** Rails\
**Created:** [April 28, 2007, 7:31pm UTC](https://www.ruby-forum.com/t/sqlrelay-adapter-for-rails/93179 "2007-04-28T19:31:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacqui](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/edb3f5/32.png) [@jacqui](https://www.ruby-forum.com/u/jacqui)\
**Post date:** [April 28, 2007, 7:31pm UTC](https://www.ruby-forum.com/t/sqlrelay-adapter-for-rails/93179/1 "2007-04-28T19:31:38Z")

</div>

I would like to use SQLRelay for database connection pooling and query-  
based routing with a Rails application that I am just about done with.  
It is my first Rails project, and I thought it might be wise to get  
some feedback on this before I get too far in coding it.

> From what I can tell, I am going to have to write a connection adapter  
> for ActiveRecord if I want to use SQLRelay (http://  
> [sqlrelay.sourceforge.net/](http://sqlrelay.sourceforge.net/)) with Rails. While I think this could be a  
> cool, fun and rewarding project, one that I will certainly be into  
> doing, time is of essence here (when isn’t it?).

I was hoping someone on this list could add their two cents. I need  
something like SQLRelay because the ops department, used to supporting  
weighty, slow PHP apps, is refusing to put this Rails website out on  
the Internet without support for DB pooling or at least read + write  
databases. I’d like the application to respond quickly too, as that  
will certainly play a large factor in whether or not the company  
continues with Rails development. I’ve implemented caching as best as  
I could, but I do still need to point at different databases, with  
masters and slaves.

I am currently using acts\_as\_readonlyable, with some modifications, to  
support a read-only database for my main database server.  
Unfortunately, I had to use multiple database servers with this Rails  
application (a member of my team wrote a plugin to support this along  
the way), so the implementation of acts\_as\_readonlyable is less than  
straight-forward.

Advice is greatly appreciated. Have you written a connection adapter  
for ActiveRecord? Or, better yet, have you implemented SQLRelay with  
ActiveRecord/Rails?

Thanks!!  
Jacqui

---

<div class="post-metadata">

**Author:** ![jacqui](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/edb3f5/32.png) [@jacqui](https://www.ruby-forum.com/u/jacqui)\
**Post date:** [April 28, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/sqlrelay-adapter-for-rails/93179/2 "2007-04-28T22:04:48Z")

</div>

Jacqui,

I hope somebody would answer your question about SQLRelay. Meanwhile,  
I am not sure whether it helps in your situation, but as of 0.0.5,  
ActsAsReadonlyable supports multiple slaves (picked at random for  
every find). Just download the latest version from rubyforge and you  
can use it as:

class Fruit \< ActiveRecord::Base  
acts\_as\_readonlyable [:first\_read\_only, :second\_read\_only]  
end

Regards,  
Val

---

<div class="post-metadata">

**Author:** ![jacqui](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/edb3f5/32.png) [@jacqui](https://www.ruby-forum.com/u/jacqui)\
**Post date:** [April 29, 2007, 9:11pm UTC](https://www.ruby-forum.com/t/sqlrelay-adapter-for-rails/93179/3 "2007-04-29T21:11:29Z")

</div>

Thanks! That actually might help me. The problem I ran into with  
acts\_as\_readonlyable was telling it to use different read\_only  
databases for different write databases. Like so:

development:  
adapter: mysql  
database: my\_development  
username: root  
password:  
host:  
encoding: utf8

read\_only:  
adapter: mysql  
database: my\_development\_slave  
username: root  
password:  
host:  
encoding: utf8

cms\_development:  
adapter: mysql  
database: my\_cms\_development  
username: root  
password:  
host:  
encoding: utf8

cms\_read\_only:  
adapter: mysql  
database: my\_cms\_development\_slave  
username: root  
password:  
host:  
encoding: utf8

acts\_as\_readonlyable didn’t seem to work when some models had:

acts\_as\_readonlyable :read\_only

and others had

acts\_as\_readonlyable :cms\_read\_only

The erroneous behavior I saw when I had two different read-only db  
servers defined with different names was that the read only db servers  
never got hit; all requests went to the write/master.

I’ll try adding multiple read-only databases for the same master,  
though, in an array. That is useful and will make things better on my  
project - thanks!

- jacqui
