NAME
Dancer::Plugin::DBIC - DBIx::Class interface for Dancer applications
VERSION
version 0.1504
SYNOPSIS
# Dancer Code File
use Dancer;
use Dancer::Plugin::DBIC;
#use Dancer::Plugin::DBIC qw(schema); # explicit import if you like
get '/profile/:id' => sub {
my $user = schema->resultset('Users')->find(params->{id});
# or explicitly ask for a schema by name:
$user = schema('foo')->resultset('Users')->find(params->{id});
template user_profile => { user => $user };
};
dance;
# Dancer Configuration File
plugins:
DBIC:
foo:
dsn: "dbi:SQLite:dbname=./foo.db"
Database connection details are read from your Dancer application config - see below.
DESCRIPTION
This plugin provides an easy way to obtain DBIx::Class::ResultSet instances via the the function schema(), which it automatically imports. You just need to point to a dsn in your Dancer configuration file. So you no longer have to write boilerplate DBIC setup code.
CONFIGURATION
Connection details will be grabbed from your Dancer config file. For example:
plugins:
DBIC:
foo:
dsn: dbi:SQLite:dbname=./foo.db
bar:
schema_class: Foo::Bar
dsn: dbi:mysql:db_foo
user: root
pass: secret
options:
RaiseError: 1
PrintError: 1
Each schema configuration *must* have a dsn option. The dsn option should be the DBI driver connection string. All other options are optional.
If a schema_class option is not provided, then DBIx::Class::Schema::Loader will be used to auto load the schema based on the dsn value.
The schema_class option, if provided, should be a proper Perl package name that Dancer::Plugin::DBIC will use as a DBIx::Class::Schema class. Optionally, a database configuation may have user, pass and options paramters as described in the documentation for connect() in DBI.
# Note! You can also declare your connection information with the
# following syntax:
plugings:
DBIC:
foo:
connect_info:
- dbi:mysql:db_foo
- root
- secret
-
RaiseError: 1
PrintError: 1
SCHEMA GENERATION
This plugin provides flexibility in defining schemas for use in your Dancer applications. Schemas can be generated manually by you and defined in your configuration file, or, they can be automatically and programmatically generated by this plugin whenever you call the `schema` keyword, or, because this plugin uses DBIx::Class::Schema::Loader to do most of the heavy lifting, you can use the command-line utility dbicdump to generate physical DBIC schema class files in the current working directory. Note! The command-line utility is useful when loading schemas large enough to discourage auto-generation and manual creation.
AUTHORS
Al Newkirk <awncorp@cpan.org>
Naveed Massjouni <naveed.massjouni@rackspace.com>
Alexis Sukrieh <sukria@sukria.net>
Franck Cuny <franck@lumberjaph.net>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by awncorp.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.