NAME

Slovo::Plugin::MojoDBx - load and use Mojo::Pg|mysql|SQLite

SYNOPSIS

  # in slovo.conf
  plugins => [
   # Should be one of the firstly loaded plugins because lately loaded plugins
   # may want to use $app->dbx.
   {
    MojoDBx => {
      adaptor   => 'SQLite',
      new       => $db_file,
      sql_debug => 0,          #4,
      on_connection => [
        'PRAGMA synchronous = OFF', 'PRAGMA foreign_keys = ON',
        'PRAGMA cache_size = 80000',    #80M cache size

    #   sub($dbh) {
    #      $app->log->debug('SQLite version: '
    #                 . $dbh->selectrow_arrayref('select sqlite_version()')->[0]);
    #      # $dbh->{TraceLevel} = "3|SQL";
    #     }
                       ],
      max_connections => 3,
      auto_migrate    => 1,
      migration_file  => $rsc->child("data/migrations.sql")->to_string,

      # Which helpers for Models to load:
      # Slovo::Model::Users,Slovo::Model::Groups... etc.
      tables => ['users', 'groups', 'domove', 'stranici', 'celini'],
    }
   },
  #... Other plugins
  ],

DESCRIPTION

Slovo::Plugin::MojoDBx 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. For now some of our SQL queries are still SQLite specific, but there is a plan to generalise them or add the corresponding queries for Pg and mysql so they will be used transparantly depending on the loaded "adaptor". 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.

CONFIGURATION

The folowing options are currently supported. They basically get the data needed for the most common steps of setting up database adaptors in Mojolicious. All options have default values as if Mojo::SQLite is used.

adaptor

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 Slovo.

migration_file

Full path to file which will be used for migrations. Default value: SQLite.

new

Anything that the adaptor constructor would accept. Default value:

    # Prefer data/slovo.$mode.sqlite over
    # lib/Slovo/resourcesdata/slovo.$mode.sqlite
    (-d $home->child('data')
    ? $home->child("data/$moniker.$mode.sqlite")->to_string
    : $resources->child("data/$moniker.$mode.sqlite")->to_string);

See also "new" in Mojo::SQLite or "new" in Mojo::Pg, or "new" in Mojo::mysql.

on_connection

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".

sql_debug

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 or 5 is useful. Allowed values are /^[0-5]$/ The value represents the number of callframes to skip when reporting the calling subroutine. Default value: 0

max_connections

Integer. Default value: 3

auto_migrate

Boolean. Default value: 1

migration_file

Path to migration file. Default value:

$resources->child("data/migrations.sql")->to_string

tables

Tables for which to be generated helpers. Each table name becomes a helper. (e.g. users becomes $c->users ot $app->users). Note that it is expected that the respective model class to be instantiated already exists f.e. Slovo::Model::Users for the table users. These classes can be initially generated using Mojolicious::Command::Author::generate::resources. Default value: ['users', 'groups', 'domove', 'stranici', 'celini']

AUTHOR

    Красимир Беров
    CPAN ID: BEROV
    berov ат cpan точка org
    http://i-can.eu

COPYRIGHT

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.

SEE ALSO

Mojo::Pg, Mojo::mysql, Mojo::SQLite, Mojolicious::Command::Author::generate::resources.