Hi,
I am looking into Sequel integration with Rails 3 (using sequel-rails
gem).
One setup I am able to easily do in Rails is that I can define
different modules under model, each with a Base class that
establish_connection to a particular database, e.g. in app/model/db1/
base.rb
module Db1
class Base < ActiveRecord::Base
self.abstract_class = true
establish_connection "db1_#{Rails.env}"
self.primary_key_prefix_type = :table_name
end
end
Then all classes in that app/model/db1 can subclass from Base and
perform the regular AR methods on this db1.
I am trying to figure out an equivalent, easy way in Sequel.
I have found this thread:
http://groups.google.com/group/sequel-talk/msg/98bd65de93895fab
and tried looking into the Sequel documentation:
But neither:
module Db1
DB1 =
Sequel.connect(Rails::Sequel.configuration.environment_for("db1_#{Rails.env}"))
class Base < Sequel::Model(DB1)
end
end
nor:
module Db1
class Base < Sequel::Model
self.db =
Sequel.connect(Rails::Sequel.configuration.environment_for("db1_#{Rails.env}"))
end
end
works. When a subclass of Base now tries to perform a query, for
example, Sequel would complain that the table bases doesn't exist in
db1. I know one can do, say,
module Db1
class A < Sequel::Model(DB1[:a])
...
end
end
OR
module Db1
class A < Base
self.dataset =
Sequel.connect(Rails::Sequel.configuration.environment_for("db1_#{Rails.env}"))
[:a]
...
end
end
But you can see the inelegance (non-DRY-ness) of this, particularly if
we are dealing with many tables from an existing database (legacy or
not). Is there a good, easy way in Sequel currently?
Thanks!
Philip
--
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.