Thanks, Paul for posting this. I lost couple of hours trying to figure
out how this worked until I found your post.

tom

On Jun 29, 8:01 pm, Paul Barry <[email protected]> wrote:
> Michael,
>
> Here's an example that shows how you can use repositories to do what you
> want.  I think in your case, you are looking at having a bunch of different
> databases that will have the same schema?  If that's the case, you should be
> able to create a new repository for each database, and then just wrap your
> code in the repository block to switch to which repository it should use.
>
> #http://gist.github.com/458158
> require 'rubygems'
> require 'dm-core'
> require 'dm-migrations'
>
> DataMapper::Logger.new($stdout, :debug)
> DataMapper.setup(:default, 'sqlite::memory:')
>
> class Thing
>   include DataMapper::Resource
>   property :id, Serial
>
>   property :name, String
> end
>
> DataMapper.setup(:foo, 'sqlite3:///tmp/foo.db')
> DataMapper.auto_migrate! :foo
> repository(:foo) do
>   Thing.create :name => "I'm in foo!"
> end
>
> DataMapper.setup(:bar, 'sqlite3:///tmp/bar.db')
> DataMapper.auto_migrate! :bar
> repository(:bar) do
>   Thing.create :name => "I'm in bar!"
> end
>
> # Trying to re-create an already existing repo doesn't cause a problem
> DataMapper.setup(:foo, 'sqlite3:///tmp/foo.db')
> repository(:foo) do
>   Thing.create :name => "I'm in foo again!"
> end
>
> repository(:foo) do
>   puts "Things in foo: #{Thing.all.map{|t| t.name}.inspect}"
> end
>
> repository(:bar) do
>   puts "Things in bar: #{Thing.all.map{|t| t.name}.inspect}"
> end
>
> On Tue, Jun 29, 2010 at 8:23 PM, Michael Xavier 
> <[email protected]>wrote:
>
> > Was hoping someone could save me from having to futz around with
> > ActiveRecord for a legacy data store. Here's the deal: My application
> > uses MongoDB/MongoMapper as the primary data store. I need to access a
> > legacy data store (AR/MySQL database from another rails application).
> > I got everything mapped up but the problem is, I need to be able to
> > dynamically change the connection settinngs of a repository to point
> > at a different db. It's the same host, server, etc, but a different
> > db.
>
> > For example, I have a repository called :legacy, and by default it
> > points at the db 'legacy_production', but I need to be able to modify
> > that connection at will to instead point at 'legacy_whatever' and have
> > all queries against models using that repository get redirected to
> > that database.
>
> > Defining all the repositories at start up is out of the question
> > because new databases might come online in the mean time. Could anyone
> > offer any hints on how I would accomplish this or *if* I even can
> > accomplish this with DataMapper?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "DataMapper" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<datamapper%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/datamapper?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to