On Thursday, February 6, 2014 12:49:41 PM UTC-8, Martinos wrote:
>
> I have a table that is distributed across multiple (0..n) databases. I
> would like to create one model to be used for all these databases.
>
> I order to do that I have created the model with a connection to the first
> database. After that, I have duplicated the model class and then changed
> it's connection:
>
> db1 = Sequel.connect(%{postgres://server1.example.com/db})
> class Message < Sequel::Model(db[:messages])
> def my_method
> end
> end
>
> db2 = Sequel.connect(%{postgres://server2.example.com/db})
>
> Message2 = Message.dup
> Message2.db = db2
>
> But this approach does not work since I need at least one connection to
> create the first model.
>
> Is it possible to create a model without a db connection? If not, does
> someone have a solution for my problem ?
>
You can create a model without a database connection using an anonymous
subclass (Message = Class.new(Sequel::Model)), but you won't get very far.
You can use Sequel's sharding support to handle the situation where the
same schema exists on multiple databases, allowing you to switch which
database is used on a per-call basis.
See http://sequel.jeremyevans.net/rdoc/files/doc/sharding_rdoc.html, and
also look into the sharding plugin and server_block and arbitrary_servers
extensions.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.