NAME

Prancer::Plugin::Database

SYNOPSIS

This plugin enables connections to a database and exports a keyword to access those configured connections.

It's important to remember that when running your application in a single- threaded, single-process application server like, say, Twiggy, all users of your application will use the same database connection. If you are using callbacks then this becomes very important and you will want to take care to avoid crossing transactions or expecting a database connection or transaction to be in the same state it was before a callback.

To use a database connector, add something like this to your configuration file:

database:
    connection-name:
        driver: Prancer::Plugin::Database::Driver::DriverName
        options:
            username: test
            password: test
            database: test
            hostname: localhost
            port: 5432
            autocommit: true
            charset: utf8
            connection_check_threshold: 10
            dsn_extra:
                RaiseError: 0
                PrintError: 1
            on_connect:
                - SET search_path=public

The "connection-name" can be anything you want it to be. This will be used when requesting a connection from the plugin to determine which connection to return. If only one connection is configured it may be prudent to call it "default" as that is the name that Prancer will look for if no connection name is given. For example:

use Prancer::Plugin::Database qw(database);

Prancer::Plugin::Database->load();

my $dbh = database;  # returns whatever connection is called "default"
my $dbh = database("foo");  # returns the connection called "foo"

OPTIONS

CREDIT

This module is derived from Dancer::Plugin::Database. Thank you to David Precious.

COPYRIGHT

Copyright 2014 Paul Lockaby. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO