<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME

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

VERSION

    version 0.0010

SYNOPSIS

        use Dancer2;
        use Dancer2::Plugin::DBIC qw(schema resultset rset);
    
        get '/users/:user_id' =&gt; sub {
            my $user = schema('default')-&gt;resultset('User')-&gt;find(param 'user_id');
    
            # If you are accessing the 'default' schema, then all the following
            # are equivalent to the above:
            $user = schema-&gt;resultset('User')-&gt;find(param 'user_id');
            $user = resultset('User')-&gt;find(param 'user_id');
            $user = rset('User')-&gt;find(param 'user_id');
    
            template user_profile =&gt; {
                user =&gt; $user
            };
        };
    
        dance;

DESCRIPTION

    This plugin makes it very easy to create Dancer2 applications that
    interface with databases. It automatically exports the keyword schema
    which returns a DBIx::Class::Schema object. You just need to configure
    your database connection information. For performance, schema objects
    are cached in memory and are lazy loaded the first time they are
    accessed.

    This plugin is a thin wrapper around DBICx::Sugar.

CONFIGURATION

    Configuration can be done in your Dancer2 config file. This is a
    minimal example. It defines one database named default:

        plugins:
          DBIC:
            default:
              dsn: dbi:SQLite:dbname=some.db

    In this example, there are 2 databases configured named default and
    foo:

        plugins:
          DBIC:
            default:
              dsn: dbi:SQLite:dbname=some.db
              schema_class: MyApp::Schema
            foo:
              dsn: dbi:mysql:foo
              schema_class: Foo::Schema
              user: bob
              password: secret
              options:
                RaiseError: 1
                PrintError: 1

    Each database configured must at least have a dsn option. The dsn
    option should be the DBI driver connection string. All other options
    are optional.

    If you only have one schema configured, or one of them is named
    default, you can call schema without an argument to get the only or
    default schema, respectively.

    If a schema_class option is not provided, then
    DBIx::Class::Schema::Loader will be used to dynamically load the schema
    by introspecting the database corresponding to the dsn value. Remember
    that you need DBIx::Class::Schema::Loader installed to take advantage
    of that.

    The schema_class option, should be a proper Perl package name that
    Dancer2::Plugin::DBIC will use as a DBIx::Class::Schema class.
    Optionally, a database configuration may have user, password, and
    options parameters as described in the documentation for connect() in
    DBI.

    You may also declare your connection information in the following
    format (which may look more familiar to DBIC users):

        plugins:
          DBIC:
            default:
              connect_info:
                - dbi:mysql:foo
                - bob
                - secret
                -
                  RaiseError: 1
                  PrintError: 1

FUNCTIONS

 schema

        my $user = schema-&gt;resultset('User')-&gt;find('bob');

    The schema keyword returns a DBIx::Class::Schema object ready for you
    to use. If you have configured only one database, then you can simply
    call schema with no arguments. If you have configured multiple
    databases, you can still call schema with no arguments if there is a
    database named default in the configuration. With no argument, the
    default schema is returned. Otherwise, you must provide schema() with
    the name of the database:

        my $user = schema('foo')-&gt;resultset('User')-&gt;find('bob');

 resultset

    This is a convenience method that will save you some typing. Use this
    only when accessing the default schema.

        my $user = resultset('User')-&gt;find('bob');

    is equivalent to:

        my $user = schema-&gt;resultset('User')-&gt;find('bob');

 rset

        my $user = rset('User')-&gt;find('bob');

    This is simply an alias for resultset.

SCHEMA GENERATION

    There are two approaches for generating schema classes. You may
    generate your own DBIx::Class classes and set the corresponding
    schema_class setting in your configuration as shown above. This is the
    recommended approach for performance and stability.

    It is also possible to have schema classes dynamically generated if you
    omit the schema_class configuration setting. This requires you to have
    DBIx::Class::Schema::Loader installed. The v7 naming scheme will be
    used for naming the auto generated classes. See "naming" in
    DBIx::Class::Schema::Loader::Base for more information about naming.

    For generating your own schema classes, you can use the dbicdump
    command line tool provided by DBIx::Class::Schema::Loader to help you.
    For example, if your app were named Foo, then you could run the
    following from the root of your project directory:

        dbicdump -o dump_directory=./lib Foo::Schema dbi:SQLite:/path/to/foo.db

    For that example, your schema_class setting would be Foo::Schema.

SEE ALSO

      * DBICx::Sugar

CONTRIBUTORS

      * Alexis Sukrieh &lt;sukria@sukria.net&gt;

      * Dagfinn Ilmari Mannsﾃ･ker &lt;https://github.com/ilmari&gt;

      * David Precious &lt;davidp@preshweb.co.uk&gt;

      * ennio &lt;https://github.com/scriplit&gt;

      * Fabrice Gabolde &lt;https://github.com/fgabolde&gt;

      * Franck Cuny &lt;franck@lumberjaph.net&gt;

      * Steven Humphrey &lt;https://github.com/shumphrey&gt;

      * Yanick Champoux &lt;https://github.com/yanick&gt;

AUTHOR

    Naveed Massjouni &lt;naveedm9@gmail.com&gt;

COPYRIGHT AND LICENSE

    This software is copyright (c) 2013 by Naveed Massjouni.

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

</pre></body></html>