Yancy::Backend::Dbic - A backend for DBIx::Class schemas
version 1.045
### 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, };
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.
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.
result_class
yancy
A very useful possibility is for that JSON schema to just contain <{ 'x-ignore' = 1 }>>.
<{ 'x-ignore' =
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.
dbic://<schema_class>/<dbi_dsn>
schema_class
dbi_dsn
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.
$schema->resultset
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' }, }, }, }, }
Yancy::Backend, DBIx::Class, Yancy
Doug Bell <preaction@cpan.org>
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.
To install Yancy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yancy
CPAN shell
perl -MCPAN -e shell install Yancy
For more information on module installation, please visit the detailed CPAN module installation guide.