Transfer data from one database to another with Datamapper

67 Views Asked by At

I have two repositories set up within data mapper as follows:

DataMapper.setup(:default, "sqlite://path/to/db1")
DataMapper.setup(:another, "sqlite://path/to/otherdb")

Lets say I have a model Foo that they both share a schema for. This is the pseudocode that I want to accomplish:

DataMapper.repository(:default){
    Foo.each do |f|
        # do some transformations
        # write to Foo table in DataMapper.repository(:another)
    end
}

How would I go about this?

1

There are 1 best solutions below

0
Omar Darwish On BEST ANSWER

The way I ended up doing it:

DataMapper.repository(:default){
    Foo.each do |foo|
        DataMapper.repository(:another){
            newFoo = Foo.new
            newFoo.attributes = foo.attributes
            newFoo.save
        }
    end
}