Dancer2-Plugin-Database

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    Returns a Dancer::Plugin::Database::Core::Handle object, which is a subclass
    of DBI's `DBI::db' connection handle object, so it does everything you'd
    expect to do with DBI, but also adds a few convenience methods. See the
    documentation for Dancer::Plugin::Database::Core::Handle for full details of
    those.

    Takes care of ensuring that the database handle is still connected and
    valid. If the handle was last asked for more than
    `connection_check_threshold' seconds ago, it will check that the
    connection is still alive, using either the `$dbh->ping' method if the
    DBD driver supports it, or performing a simple no-op query against the
    database if not. If the connection has gone away, a new connection will
    be obtained and returned. This avoids any problems for a long-running
    script where the connection to the database might go away.

    Care is taken that handles are not shared across processes/threads, so
    this should be thread-safe with no issues with transactions etc. (Thanks
    to Matt S Trout for pointing out the previous lack of thread safety.
    Inspiration was drawn from DBIx::Connector.)

lib/Dancer2/Plugin/Database.pm  view on Meta::CPAN

Provides an easy way to obtain a connected DBI database handle by simply calling
the database keyword within your L<Dancer2> application

Returns a L<Dancer::Plugin::Database::Core::Handle> object, which is a subclass of
L<DBI>'s C<DBI::db> connection handle object, so it does everything you'd expect
to do with DBI, but also adds a few convenience methods.  See the documentation
for L<Dancer::Plugin::Database::Core::Handle> for full details of those.

Takes care of ensuring that the database handle is still connected and valid.
If the handle was last asked for more than C<connection_check_threshold> seconds
ago, it will check that the connection is still alive, using either the 
C<< $dbh->ping >> method if the DBD driver supports it, or performing a simple
no-op query against the database if not.  If the connection has gone away, a new
connection will be obtained and returned.  This avoids any problems for
a long-running script where the connection to the database might go away.

Care is taken that handles are not shared across processes/threads, so this
should be thread-safe with no issues with transactions etc.  (Thanks to Matt S
Trout for pointing out the previous lack of thread safety.  Inspiration was
drawn from DBIx::Connector.)



( run in 2.479 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )