NAME
Yancy::Backend::Dbic - A backend for DBIx::Class schemas
VERSION
version 1.049
SYNOPSIS
### URL string
use Mojolicious::Lite;
plugin Yancy => {
backend => 'dbic://My::Schema/dbi:Pg:localhost',
read_schema => 1,
};
### DBIx::Class::Schema object
use Mojolicious::Lite;
use My::Schema;
plugin Yancy => {
backend => { Dbic => My::Schema->connect( 'dbi:SQLite:myapp.db' ) },
read_schema => 1,
};
### Arrayref
use Mojolicious::Lite;
use My::Schema;
plugin Yancy => {
backend => {
Dbic => [
'My::Schema',
'dbi:SQLite:mysql.db',
undef, undef,
{ PrintError => 1 },
],
},
read_schema => 1,
};
DESCRIPTION
This Yancy backend allows you to connect to a DBIx::Class schema to manage the data inside.
METHODS
See Yancy::Backend for the methods this backend has and their return values.
read_schema
While reading the various sources, this method will check each source's result_class
for the existence of a yancy
method. If it exists, that will be called, and must return the initial JSON schema for Yancy.
A very useful possibility is for that JSON schema to just contain <{ 'x-ignore' =
1 }>>.
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.
Schema Names
The schema names 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 to the following schema names:
{
backend => 'dbic://My::Schema/dbi:SQLite:test.db',
schema => {
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) 2019 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.