On Monday, July 18, 2016 at 6:49:59 AM UTC-7, [email protected] wrote:
>
> Hi:
>
> I would like to know if it possible to connect dynamically a database and 
> then inside a block execute operations againt that database. One database 
> could be a mysql, another a posgresql... 
> I mean, using sequel model, I see if you connect several databases you can 
> access them with Sequel::DATABASES and if you select a database you can 
> make 
> queries against it but Sequel::Model is different, takes the first one 
> and makes queries against that database. 
>
> For Example if I have my sequel model but I have two databases (same 
> schema) and I want to insert the title in a specific database:
>
> ```
> class Title < Sequel::Model
> end
>
> ::Sequel::DATABASES.count #=> 2
>
> MyDatabase do 
> Title.create(name: "test")
> end
> ```
>
> MyDatabse can be selected from ::Sequel::DATABASES or other CONSTANT 
> depend on a param.
>

No, this isn't possible, models are tied to the database that created them. 
 To get similar behavior, you can use separate model classes per database, 
by having a method that accepts the Database object as an argument, and 
returns the appropriate model classes.

It's possible to use Model.db= to change the model's database dynamically, 
but I'm not sure how well that would work for what you want.

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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to