It's possible (and probably likely) that there is a better way. I
suggest posting on the Sinatra list for more advice. Except in some
rare cases, I think it's generally a bad idea to create database
objects in a route/action. For instance, you might be able to create
your DB objects at startup (e.g. in the configure block) and then use
the incoming parameters to figure out which one to use. Then again,
you may have a valid reason for creating the DB object in the route/
action. If so, I'd be interested in hearing it so I can add the use-
case to my short list of use-cases. ;)

On Oct 9, 9:41 pm, coolesting <[email protected]> wrote:
> That is right, we don't know what is the database will be operated
> (import DB,  export DB,  etc)at what is the time.
> So, we need to controll how to use and create the database connect in action.
> I really don't think a good way to do that.
>
> 2011/10/9 Jeremy Evans <[email protected]>:
>
>
>
>
>
>
>
> > On Oct 9, 5:16 am, Jason Rogers <[email protected]> wrote:
> >> There's still do not need to create the database objects in your
> >> routes. Use a configure block like the following, then reference the
> >> database constants in your routes:
>
> >> configure do
> >>   BLOG_DB     = Sequel.connect("sqlite://db/blog/data.db")
> >>   PICTURES_DB = Sequel.connect("sqlite://db/pictures/data.db")
> >>   RECORDS_DB  = Sequel.connect("sqlite://db/records/data.db")
> >> end
>
> >> get '/' do
> >>      #do something with BLOG_DB
> >>      #do something with PICTURES_DB
> >>      #do something RECORDS_DB
> >> end
>
> > This is the recommended way if you want to use multiple databases.
> > The only reason you would need to create Database objects inside an
> > action is if the database connection parameters are derived from the
> > action's parameters.
>
> > 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 
> > athttp://groups.google.com/group/sequel-talk?hl=en.

-- 
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.

Reply via email to