NAME

Dancer::Plugin::DBIC - DBIx::Class interface for Dancer applications

VERSION

version 0.1501

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

AUTHORS

Al Newkirk <awncorp@cpan.org>
Naveed Massjouni <ironcamel@cpan.org>

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.