views:

17

answers:

2

I am implementing a Rails application that needs to aggregate search results from N independent heterogeneous databases. An example use case would be:

  • User queries "xpto"
  • The query is submitted to all the databases registered on the system
  • The results are transformed and combined in a predefined format
  • User gets the results

The application needs to provide an extensibility point for the introduction of new databases in the system. A database here can be of different kinds - a flat file, SQL database, REST interface to an SQL database, etc.

If I was working in C#/Java, ignoring speed issues, I would define a plug-in management system where each host would have a plug-in that would know how to query and transform the results of the host. New hosts would be easily introduced by defining a new plug-in and configuring the host in the system.

I am new comer to rails and I am looking for either ideas, tools or design patterns that can help me to solve this problem.

A: 

My best guess wolud be to write a custom ActiveRecord Adapter that would query all your databases and combine the results.

clyfe
That's a possibility, but I would prefer to have a different modules for different databases.
luis
Have your MultiSourceAdapter rely on several MultiSourceAdapterAdapter.s and in database.yml specify adapter and adapteradapter for each source.
clyfe
A: 

From the API reference:

Connections are usually created through ActiveRecord::Base.establish_connection and retrieved by ActiveRecord::Base.connection. All classes inheriting from ActiveRecord::Base will use this connection. But you can also set a class-specific connection. For example, if Course is an ActiveRecord::Base, but resides in a different database, you can just say Course.establish_connection and Course and all of its subclasses will use this connection instead.

Shyam