This worked for me:
module Monkey1
DB = Sequel.connect('mysql://root:@localhost/monkey1')
class Monkey < Sequel::Model(DB[:monkeys]); end
end
module Monkey2
DB = Sequel.connect('mysql://root:@localhost/monkey2')
class Monkey < Sequel::Model(DB[:monkeys]); end
end
Monkey1::DB.create_table! :monkeys do
primary_key :id
varchar :name
end
Monkey2::DB.create_table! :monkeys do
primary_key :id
varchar :name
end
__END__
ruby-1.9.1-p378 > Monkey1::Monkey.create(:name => 'monkey1')
=> #<Monkey1::Monkey @values={:id=>1, :name=>"monkey1"}>
ruby-1.9.1-p378 > Monkey2::Monkey.create(:name => 'monkey2')
=> #<Monkey2::Monkey @values={:id=>1, :name=>"monkey2"}>
ruby-1.9.1-p378 >
ruby-1.9.1-p378 > Monkey1::Monkey.count
=> 1
ruby-1.9.1-p378 > Monkey1::Monkey.first.name
=> "monkey1"
ruby-1.9.1-p378 >
ruby-1.9.1-p378 > Monkey2::Monkey.count
=> 1
ruby-1.9.1-p378 > Monkey2::Monkey.first.name
=> "monkey2"
I did have to add the DB and table when I inherited from Sequel::Model
(eg: < Sequel::Model(DB[:table_name])) or it didn't work. But, that
shouldn't be too much extra work. Perhaps someone else has another
way that would work.
On Mar 5, 8:28 pm, jv27243 <[email protected]> wrote:
> I have models defined like so:
>
> module X
> class A < Sequel::Model(:table_a)
> set_primary_key :id
> end
> class B < Sequel::Model(:table_b)
> set_primary_key :id
> end
> end
>
> module Y
> class A < Sequel::Model(:table_a)
> set_primary_key :id
> end
> class C < Sequel::Model(:table_c)
> set_primary_key :id
> end
> end
>
> Is there an easy way to create a DB connection mysql1 and assign it to
> all models in module X and a second connection mysql2 to all models in
> module Y? mysql1 and mysql2 are two separate mysql instances with
> unlike DB schemas.
--
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.