NAME

Yancy::Backend::Dbic - A backend for DBIx::Class schemas

VERSION

version 0.006

SYNOPSIS

# yancy.conf
{
    backend => 'dbic://My::Schema/dbi:Pg:localhost',
    collections => {
        ResultSet => { ... },
    },
}

# Plugin
use Mojolicious::Lite;
plugin Yancy => {
    backend => 'dbic://My::Schema/dbi:Pg:localhost',
    collections => {
        ResultSet => { ... },
    },
};

DESCRIPTION

This Yancy backend allows you to connect to a DBIx::Class schema to manage the data inside.

See Yancy::Backend for the methods this backend has and their return values.

Backend URL

The URL for this backend takes the form dbic://<schema_class>/<dbi_dsn> where schema_class is the DBIx::Class schema module name and dbi_dsn is the full DBI data source name (DSN) used to connect to the database.

Collections

The collections for this backend are the names of the DBIx::Class::Row classes in your schema, just as DBIx::Class allows in the $schema->resultset method.

So, if you have the following schema:

package My::Schema;
use base 'DBIx::Class::Schema';
__PACKAGE__->load_namespaces;

package My::Schema::Result::People;
__PACKAGE__->table( 'people' );
__PACKAGE__->add_columns( qw/ id name email / );

package My::Schema::Result::Business
__PACKAGE__->table( 'business' );
__PACKAGE__->add_columns( qw/ id name email / );

You could map that schema to the following collections:

{
    backend => 'dbic://My::Schema/dbi:SQLite:test.db',
    collections => {
        People => {
            properties => {
                id => {
                    type => 'integer',
                    readOnly => 1,
                },
                name => { type => 'string' },
                email => { type => 'string' },
            },
        },
        Business => {
            properties => {
                id => {
                    type => 'integer',
                    readOnly => 1,
                },
                name => { type => 'string' },
                email => { type => 'string' },
            },
        },
    },
}

SEE ALSO

Yancy::Backend, DBIx::Class, Yancy

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Doug Bell.

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