[Dancer-users] D::P::Database: Changing Databases dynamically between routes

Gurunandan Bhat gbhat at pobox.com
Fri Jan 27 10:10:46 CET 2012


Hi,

I am trying to use Dance::Plugin::Database with SQLite in a situation where
different databases must be connected to in different routes. For example:

get route_1 => sub {

    my $dbfile_1 = "...";
    my $dbh = database({
        driver: 'SQLite',
        database => $dbfile_1,
        .... Other Options
    });

    ... Work with $dbh

}

get route_2 => sub {

    my $dbfile_2 = "...";
    my $dbh = database({
        driver: 'SQLite',
        database => $dbfile_2,
        .... Other Options
    });

    ... Work with $dbh

}

My Config file contains:

plugins:
  Database:
    driver: 'SQLite'

Since I dont know what the database is going to be I dont have the database
setting here (probably incorrect, but I dont know any better)
After a few routes I begin to get this error:

Can't connect to data source 'dbi:SQLite' because I can't work out what
driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the
DBI_DRIVER env var is not set) at
/home/nandan/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/Dancer/Plugin/Database.pm
line 163

Could you suggest the correct way to set the database dynamically in each
route?

Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20120127/c7f664b8/attachment.htm>


More information about the Dancer-users mailing list