[Dancer-users] Using persistent DB connections in Dancer::Tutorial

David Precious davidp at preshweb.co.uk
Mon Jan 10 13:53:19 CET 2011

On Sat, 2011-01-08 at 14:48 +0530, Gurunandan Bhat wrote:
> If I rewrite connect_db as:
> my $dbh;
> sub connect_db {
>     if (! defined $dbh) {
>         $dbh = DBI->connect("dbi:SQLite:dbname=".setting('database'))
> or
>             die $DBI::errstr;
>     }
>     return $dbh;
> }
> will the application use a single connection for all connections under
> all
> perl webservers (in-built, mod_perl, Starman, Twiggy etc.).
> If that is true, a line to that effect in an appropriate place in the
> tutorial would emphasize the persistent features of the solution.

A single connection per process, I believe.  For instance, if you run it
under Starman, which will start a certain number of spare processes (5,
by default) I'd expect each of those processes to have their own
database connection.

Incidentally, Dancer::Plugin::Database makes this kind of thing very
easy indeed :)


Dave P

David Precious <davidp at preshweb.co.uk> ("bigpresh")

More information about the Dancer-users mailing list