Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:58:51+00:00 2026-06-12T14:58:51+00:00

I am using sinatra with datamapper and have more than one database, that I

  • 0

I am using sinatra with datamapper and have more than one database, that I want to connect to and use them per my logic in the same app.

I have my datamapper settings defined in a file, say app.rb

#Default database
dm = DataMapper.setup :default, {
:adapter => 'mysql',
:path => 'dsfsdf',
:username => 'sdf2r',
:password => '234wer',
:host => 'f3rwefwe'
}

#Logrecord database
lrdm = DataMapper.setup :logrecdm, {
:adapter => 'mysql',
:path => 'dsf34',
:username => 't4h6',
:password => '56erg',
:host => 'g45gfg'
}

#my database
mdb = DataMapper.setup :mydb, {
:adapter => 'mysql',
:path => 'dsf34',
:username => 't4h6',
:password => '56erg',
:host => 'g45gfg'
}

# Here I include all my model files.

DataMapper.finalize

My first model file (xyz_db.rb), that is corresponding to xyz table and this table is located in default data-store :default

    class xyz  
      include DataMapper::Resource  
      property :id, Serial
      property :created_at, DateTime  
    end

My second model file (userlogrecord_db.rb), that is corresponding to userlogrecords table and that table is located in other data-store :logrecdm

class userlogrecord  
  include DataMapper::Resource  
  property :id, Serial  
  property :content, Text, :required => true
  property :created_at, DateTime  
  property :updated_at, DateTime  
end  

My third model file (abc_db.rb), that is corresponding to abc and that table is located in other data-store :mydb

class abc
  include DataMapper::Resource
  is :reflective
  reflect 
end

When I run my app.rb , first model (xyz_db.rb) by default uses default data-store. But for second and third models, I want they should be generated in :logrecdm and :mydb data store respectively. What changes I should make in my second and third model to achieve that? In third data-store (:mydb) I am using dm-reflective. I have looked at http://datamapper.org/docs/misc.html but that does not really help. Any help will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:58:52+00:00Added an answer on June 12, 2026 at 2:58 pm

    I found the solution

    class abc
      include DataMapper::Resource
      def self.default_repository_name
        :mydb
      end
    
      is :reflective
      reflect 
    end
    

    I took the idea from http://workswithruby.com/2008/12/using-datamapper-on-legacy-databases
    I wish datamapper documentation would have mentioned about it somewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Sinatra for my webapp. I have some cleanup code that I
I have a problem with DataMapper (I'm using it with Sinatra) I have a
I am using datamapper in a Sinatra application. I currently use the command DataMapper.finalize.auto_upgrade!
We are using Datamapper in a Sinatra application and would like to use case
I have a basic Ruby app that I am building with Sinatra, Datamapper and
I'm using Datamapper 1.0 with sinatra and sqlite3 as backend. I have some devices,
I am working on a simple budget app using Sinatra and DataMapper in Ruby.
I am using ruby 1.9.2 and sinatra 1.3.2, Datamapper I get error: can't convert
I'm very new to Ruby and using Sinatra, mainly so that I can do
I've just started writing a reasonably straightforward site using sinatra. My problem is that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.