On Dec 30 2008, 4:10 am, greymatter <[email protected]> wrote: > 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.
That is the correct way to instantiate the classes. You are most likely getting an error because Sequel doesn't support HSQLDB specifically, and HSQLDB must not like the generic SQL support. From the error message, it looks transaction related. Looking at the HSQLDB documentation, the way they want you to do transactions is: 1) Turn autocommit off 2) COMMIT or ROLLBACK if you want. Sequel uses BEGIN by default to signal the start of the transaction, and that is probably what HSQLDB is complaining about. You can either use a different database (H2 is now supported), or write an HSQLDB JDBC subadapter for Sequel (which isn't as hard as it sounds). See the existing JDBC subadapters for an example: http://github.com/jeremyevans/sequel/tree/8ea918c35bc691e2cd07818f0170d7f733108400/lib/sequel_core/adapters/jdbc. If you run into any problems creating an HSQLDB subadapter, please let me know and I'll try to help. Jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
