Slovo::Plugin::MojoDBx - switch between Mojo::Pg/mysql/SQLite
$app->plugin( MojoDBI => { adaptor => 'SQLite', # Load Mojo::SQLite or 'mysql', or 'Pg' new => $app->resources->child("data/$moniker.$mode.sqlite"), helper => 'dbx', # instead of 'pg', 'mysql' or 'sqlite' on_connection => [ 'PRAGMA synchronous = OFF', 'PRAGMA journal_mode=WAL', 'PRAGMA foreign_keys = ON', sub($dbh) { # do something after DBI connects } ], sql_debug => 4, # how many callframes to skip..(0 means 'no debug') max_connections => 3, migration_files => [$app->home->child('sql/one.sql'), $app->home->child('sql/two.sql')] tables => [qw(users groups pages content)] , # Tables to load models and generate helpers for } );
Slovo::Plugin::MojoDBI allows you to switch from using one Mojo database adaptor to another without having to change your database helper name or just about any code in your application as long as Mojo::Pg, Mojo::mysql, Mojo::SQLite or Mojo::WhateverDB have compatible APIs. Currently this plugin is part of Slovo, but it can be easily moved to the Mojo::Plugin namespace if there is positive feedback about that.
The folowing options are currently supported. They basically get the data needed for the most common steps of setting up database adaptors in Mojolicious.
The specific part of the name of a known database adaptor - SQLite for Mojo::SQLite, Pg for Mojo::Pg, etc. This adaptor will be loaded via "load_class" in Mojo::Loader.
Array reference of hash referenses. See "ATTRIBUTES" in Mojo::Pg. Keys will be called as setters and the values will be passed as arguments. =head2 dsn
Another way to specify database connection. See the corresponding documentation.
The helper name which you will use everywhere in your controllers to invoke database functionality. Common names are sqlite, pg, mysql. Having a common name will allow you to easily switch from SQLite to mysql for example as your user-base grows. Defaults to dbx.
sqlite
pg
mysql
dbx
Array reference of full paths to files which will be used for migrations.
Mandatory. Anything that the constructor would accept.
Array of SQL statements or code referneces. Some Perl or SQL code which you want to execute every time the application conects to the database. See "SYNOPSIS".
This plugin uses "Callbacks" in DBI to log the produced SQL for debugging purposes. A positive integer is used for "caller" in perlfunc to report which method produced this SQL. A value of 0 disables SQL debugging and usually 4 and above is useful. The value is the number of callframes to skip when reporting the calling subroutine.
0
4
Tables for which to be generated helpers. Each table name is camelized and this is the name of the new helper for that table (e.g. users becomes Users).
users
Users
Красимир Беров CPAN ID: BEROV berov ат cpan точка org http://i-can.eu
This program is free software licensed under the Artistic License 2.0.
The full text of the license can be found in the LICENSE file included with this module.
Mojo::Pg, Mojo::mysql, Mojo::SQLite
To install Slovo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Slovo
CPAN shell
perl -MCPAN -e shell install Slovo
For more information on module installation, please visit the detailed CPAN module installation guide.