On Jun 8, 6:55 am, Evgeni Dzhelyov <[email protected]> wrote:
> Hi,
>
> I have the following case, I have different products all of which have
> one main table and N-corresponding tables
> I decided that I want to namespace each product's tables in separate
> schema using Postgres.
>
> Now the problem I'm facing is how to organize the Sequel connection.
> I want to provide web interface that manipulate these products
> and based on the path prefix in the url to decide which one should be
> loaded.
>
> Playing in Sinatra this scenario I'm faced with some problems:
> * If I initialize the DB connection outside of the request then
> multiple request fail because they all shared one connection with one
> "search_path" set to postgres
> * If I want to initialize the DB connection I have to require the
> model files after that in each request
>
> I think the cleaner way to go with this is that I have separate
> connection for each request, but how could I accomplish that, maybe
> using some middleware like
> ActiveRecord::ConnectionAdapters::ConnectionManagement
>
> I would appreciate any help how to setup this or if you think that
> using schema in this scenario becomes too complicated.
I would certainly recommend against this approach. If you do it
anyway, you'll have to use a Rack middleware that does something like:
def call(env)
DB.synchronize do |conn|
conn.execute('SQL to set schema search path')
@app.call(env)
end
end
This will limit the number of simultaneous connections your Sinatra
instance handle to the size of your connection pool.
If you have a empty copy of the models tables in the default search
path, with matching columns, you should be able to load the models
when the app loads and not inside every request.
Jeremy
--
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.