Hi guys. I have a postgresql database with multiple schemas (namespaces). Is there a way to use namespaces with ORM models? I did not find an easy way to tell all my models what namespace they should switch to.
```ruby namespaces = [:customer1, :customer2, ...] namespaces.each do |ns| # Change datasets on all my models Product.set_dataset(Sequel[ns][Product.table_name]) User.set_dataset(Sequel[ns][User.table_name]) # etc... # do more things here end ``` The example above seems to work, but I don't like it. It is not thread safe, it changes the namespaces globally. I can make it safer by creating an ephemeral namespaced model: ```ruby def with_namespace(model, namespace, &block) model_with_namespace = Class.new(model) model_with_namespace.set_dataset(Sequel[namespace.to_sym][model.table_name] block.call(model_with_namespace) end with_namespace(Product, :customer1) do |product| data = product.all # do more things here end ``` but it is still per model, and it pollutes memory. Having something like an example below would really help: ```ruby DB.with_namespace(:customer1) do # all models are automatically namespaced inside the block data = Product.all # do more things here end ``` Is there anything like this already, or am I not using the namespaces properly? Thank you! -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/65a8b049-a45b-4eb4-8f0f-03ab7f1fe927n%40googlegroups.com.
