SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Manually connecting to a database?

    Say you are running a SaaS and each user has their own database, is it possible to manually connect to each database?
    Have a good day.

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. You can connect to multiple networks. You just need to set up each connection in database.yml. There are plenty of references:

    http://www.google.com/search?q=rails+multiple+database

    It is usual to use one connection per model, but you can force a different connection at the method level. it shouldn't take too much work to pass a user to a method and define the connection based on the user.

    So possible.

    However, not something that's going to work without you putting in the effort to work out the way to handle the each connection. As this goes against the usual Rails conventions it will require you to work out a lot of it yourself.

  3. #3
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean without specifying it in database.yml...
    Have a good day.

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes again, but you'll have to manually create the code to do it.

    The key thing is that anything that is available to Ruby is available to you in Rails. Therefore, if you want to set up customised connections its available but you'll need to write the Ruby classes to handle it - either directly or to proxy the connections via ActiveRecord or another Ruby database utility. If you use JRuby, you may even be able to use JDBC.

    With Rails, doing things the "Rails way" is the easiest path, but not the only path.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems to me that a seperate database per user would be an administrative nightmare, not to mention resource intensive.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depends how many users. Less than five : not a problem. Fifty, and as you say "an administrative nightmare".

    The key point is that you can do it using the tools Rails provides. As with any coding language, the tools are there for you to build heaven or hell. The skill of the developer is in not building one when they meant to build the other.

  7. #7
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am talking about an app with thousands of SQLite databases and then a main MySQL database for master data.
    Have a good day.

  8. #8
    SitePoint Zealot
    Join Date
    Feb 2003
    Location
    Akron, OH, USA
    Posts
    106
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You may want to take a look at http://www.railskits.com

    They have a ready-made SaaS that you can purchase...I have used some of their kits and they are pretty well worth it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •