NAME

Mojolicious::Plugin::QuickMy - Mojolicious Plugin that provided quick access methods for Mojo::mysql

SYNOPSIS

  # Mojolicious::Lite
  
  plugin 'QuickMy' => {dsn => 'mysql://username@/test'};
  
  # Mojolicious (not Lite)
  # in startup
  
  $self->plugin('Mojolicious::Plugin::QuickMy' =>
                { dsn => 'mysql://username@/test',
                  debug => 1 } );
                                                   
  # in controller
  # quick select
  # returns array of hashes [{},{}]
  
  my ($all_table) = $c->qselect('table_name');
  
  # returns hash {}
  
  my $one_row = $c->qselect('table_name');
  
  # quick count
  $c->qcount('table_name', {name => {like => 'Mos%'} } );
  
  # quick insert
  # returns last_insert_id
  
  my $id = $c->qinsert('models', { name => 'Moscow',
                                   foto => 'https://www.flickr.com/search/?text=Moscow' } );
  
  # quick update
  # returns numbers of updated rows
  
  $c->qupdate('models', {id => $id}, { name => 'New York',
                                       foto => 'https://www.flickr.com/search/?text=New%20York'
                                      } );
  
  # quick delete
  # returns numbers of deleted rows
  
  $c->qdelete('models', { id => $id });
  
  # catch the errors on insert/delete methods
  
  $c->qerror; # returns $@ value
  
  # custom requests - returns Mojo::mysql::Results object
  
  my $result = $s->qcustom('SELECT a.id, b.name
                            FROM table1 a, table2 b
                            WHERE a.id = b.id AND b.name = ?', $name);
  my $arrays = $result->hashes->to_array;                              

DESCRIPTION

Mojolicous::Plugin::QuickMy is a plugin for Mojolicious apps thas provide simple access to Mojo::mysql. The most part of the code for plugin is taken from Dancer::Plugin::Database::Core::Handle (under Artistic License)

HELPERS

Mojolicious::Plugin::QuickMy contains next helpers: qselect, qinsert, qupdate, qdelete, qcustom, qerror, qcount.

qselect

    my $one_row = $c->qselect('table_name', {id => 1},
    { order_by => {desc => 'id'}, limit => 10, offset => 5, columns => qw[id name]});

For more examples see /examples/*

qinsert

For examples see /examples/*

qupdate

For examples see /examples/*

qdelete

For examples see /examples/*

qcustom

For examples see /examples/*

qcount

For examples see /examples/*

qerror

For more examples see /examples/*

CONFIG

Mojolicious::Plugin::QuickMy configuration support two keys.

  • dsn

        $self->plugin('Mojolicious::Plugin::QuickMy' =>
                                {dsn => 'mysql://username@/test'} );

    Set connection string

  • debug

        # Lite
      
        plugin 'QuickMy' => {dsn => 'mysql://username@/test', debug => 1};
      
        # Adults App :)
      
        $self->plugin('Mojolicious::Plugin::QuickMy' =>
                                        { dsn   => 'mysql://username@/test',
                                          debug => 1 } );
                                                       

    This key switches on|off printing on console SQL requests.

SEE ALSO

Mojo::mysql Mojolicious Mojolicious::Guides http://mojolicious.org.

AUTHOR

Pavel Kuptsov <pkuptsov@gmail.com>

THANKS

Alberto Simões <ambs@perl-hackers.net> Sebastian Riedel <sri@cpan.org> Jan Henning Thorse <jhthorsen@cpan.org>

BUGS

Please report any bugs or feature requests to bug-mojolicious-plugin-quickmy at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mojolicious-Plugin-QuickMy. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.

COPYRIGHT & LICENSE

Copyright (C) 2016 by Pavel Kuptsov.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.