Skip to content

Using multiple databases

leucos edited this page Oct 14, 2012 · 2 revisions

This is well explained in this list post.

Just define constants containing your database connections :

BLOG_DB = Sequel.sqlite('data/blog/blog.db') 
COMMENTS_DB = Sequel.sqlite('data/blog/comments.db') 

Then, use self.db to set the database connection to use in your model :

class Blog < Sequel::Model 
  self.db = BLOG_DB 
  ... 
end 

class BlogComment < Sequel::Model 
  self.db = COMMENTS_DB 
  ... 
end 

Alternatively, you can set the database connection like this :

class Blog < Sequel::Model(BLOG_DB) 
  ...
end

class BlogComment < Sequel::Model(COMMENTS_DB) 
  ...
end
Clone this wiki locally