I'm trying to understand how to architect an app that needs to have
two separate database connections, both managed by Sequel.  Some model
classes will go into one database while others go into the other
database.

I've got a couple of global variables that I'm using to store the two
connections, although I'm not really sure where they should live.  I'm
using the optional argument to Sequel::Model, hoping to specify which
database that model belongs in.  I believe that I have no choice but
to explicitly include the table name, as well.

So, one of my classes looks like this:

require 'rubygems'
require 'sequel'

$transientdb = Sequel.connect('jdbc:hsqldb:mem:testmem') if
$transientdb == nil
$permanentdb = Sequel.connect('jdbc:hsqldb:file:testfile') if
$permanentdb == nil

class Call < Sequel::Model($transientdb[:calls])
  set_schema do
    primary_key   :id
    ...
  end

  def initialize
    $transientdb.transaction do
      puts "Creating table 'calls'\n"
      Call.create_table
    end unless Call.table_exists?
  end
end

A table that is intended to live in the permanent database might be
declared

class Message < Sequel::Model($permanentdb[:messages])
...

Am I going about this the right way?  I'm open to suggestions for a
better approach, as I'm learning as I go.

Thanks!

--Lee
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to