Mojolicious::Plugin::QuickPg - Mojolicious Plugin that provided quick access methods for Mojo::Pg
# Mojolicious::Lite plugin 'QuickPg' => {dsn => 'postgresql://sri:123456@localhost/testdb'}; # Mojolicious (not Lite) # in startup $self->plugin('Mojolicious::Plugin::QuickPg' => { dsn => 'postgresql://sri:123456@localhost/testdb', 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'); # example with offset and limits my ($array_ref) = $c->qselect('models', {},{ limit => 10, offset => 0 } ); # quick count $c->qcount('table_name', {name => {like => 'Mos%'} } ); # quick insert # returns value of primary key (like as last_insert_id on MySQL) my $id = $c->qinsert('models', { name => 'Moscow', foto => 'https://www.flickr.com/search/?text=Moscow' } ); # or you can do like this my $params = $c->req->json; # Do not forget to validate $params before it: my $id = $c->insert('models', $params); # 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::Pg::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;
Mojolicous::Plugin::QuickPg is a plugin for Mojolicious apps thas provide simple access to Mojo::Pg. The most part of the code for plugin is taken from Dancer::Plugin::Database::Core::Handle (under Artistic License)
Mojolicious::Plugin::QuickPg 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
qdelete
qcustom
qcount
qerror
Mojolicious::Plugin::QuickPg configuration support two keys.
dsn
$self->plugin('Mojolicious::Plugin::QuickPg' => {dsn => 'postgresql://sri:123456@localhost/testdb'} );
Set connection string
debug
# Lite plugin 'QuickPg' => {dsn => 'postgresql://sri:123456@localhost/testdb', debug => 1}; # Adults App :) $self->plugin('Mojolicious::Plugin::QuickPg' => { dsn => 'postgresql://sri:123456@localhost/testdb', debug => 1 } );
This key switches on|off printing on console SQL requests.
Mojo::Pg Mojolicious Mojolicious::Guides http://mojolicious.org.
Pavel Kuptsov <pkuptsov@gmail.com>
Alberto Simões <ambs@perl-hackers.net> Sebastian Riedel <sri@cpan.org>
Please report any bugs or feature requests to bug-mojolicious-plugin-quickpg at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mojolicious-Plugin-QuickPg. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.
bug-mojolicious-plugin-quickpg at rt.cpan.org
Bitbucket
https://bitbucket.org/pkuptsov/mojolicious-plugin-quickpg
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mojolicious-Plugin-QuickPg
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Mojolicious-Plugin-QuickPg
CPANTS: CPAN Testing Service
http://cpants.perl.org/dist/overview/Mojolicious-Plugin-QuickPg
CPAN Ratings
http://cpanratings.perl.org/d/Mojolicious-Plugin-QuickPg
Search CPAN
http://search.cpan.org/dist/Mojolicious-Plugin-QuickPg
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.
To install Mojolicious::Plugin::QuickPg, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::QuickPg
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::QuickPg
For more information on module installation, please visit the detailed CPAN module installation guide.