Yancy::Backend::Mysql - A backend for MySQL using Mojo::mysql
version 1.015
### URL string use Mojolicious::Lite; plugin Yancy => { backend => 'mysql:///mydb', read_schema => 1, }; ### Mojo::mysql object use Mojolicious::Lite; use Mojo::mysql; plugin Yancy => { backend => { Mysql => Mojo::mysql->new( 'mysql:///mydb' ) }, read_schema => 1, }; ### Hash reference use Mojolicious::Lite; plugin Yancy => { backend => { Mysql => { dsn => 'dbi:mysql:dbname', username => 'fry', password => 'b3nd3r1sgr34t', }, }, read_schema => 1, };
This Yancy backend allows you to connect to a MySQL database to manage the data inside. This backend uses Mojo::mysql to connect to MySQL.
See Yancy::Backend for the methods this backend has and their return values.
The URL for this backend takes the form mysql://<user>:<pass>@<host>:<port>/<db>.
mysql://<user>:<pass>@<host>:<port>/<db>
Some examples:
# Just a DB mysql:///mydb # User+DB (server on localhost:3306) mysql://user@/mydb # User+Pass Host and DB mysql://user:pass@example.com/mydb
The collections for this backend are the names of the tables in the database.
So, if you have the following schema:
CREATE TABLE people ( id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL ); CREATE TABLE business ( id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) NULL );
You could map that schema to the following collections:
{ backend => 'mysql://user@/mydb', collections => { People => { required => [ 'name', 'email' ], properties => { id => { type => 'integer', readOnly => 1, }, name => { type => 'string' }, email => { type => 'string' }, }, }, Business => { required => [ 'name' ], properties => { id => { type => 'integer', readOnly => 1, }, name => { type => 'string' }, email => { type => 'string' }, }, }, }, }
By default, this backend will ignore some tables when using read_schema: Tables used by Mojo::mysql::Migrations, Mojo::mysql::PubSub, DBIx::Class::Schema::Versioned (in case we're co-habitating with a DBIx::Class schema), and the Minion::Backend::mysql Minion backend.
read_schema
Mojo::mysql, Yancy
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2018 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.