<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">=pod

=encoding utf-8

笘��笘� ﾐ頒ｾﾐｱﾑﾐｾﾐｳﾐｾ ﾐｲﾑ�ｵﾐｼ 笘��笘�

=head1 Mojo::Pg::Che

ﾂ｡ ﾂ｡ ﾂ｡ ALL GLORY TO GLORIA ! ! !

=head1 NAME

Mojo::Pg::Che - mix of great Mojo::Pg and DBI

=head1 DESCRIPTION

See L&lt;Mojo::Pg&gt;

=head1 VERSION

Version 0.8552


=head1 SYNOPSIS

    use Mojo::Pg::Che;

    my $pg = Mojo::Pg::Che-&gt;connect("dbname=test;", "postgres", 'pg-pwd', \%attrs, max_connections=&gt;10);
    # or
    my $pg = Mojo::Pg::Che-&gt;new
      -&gt;dsn("DBI:Pg:dbname=test;")
      -&gt;username("postgres")
      -&gt;password('pg--pw')
      -&gt;options(\%attrs)
      -&gt;connect();
    
    # or
    my $pg = Mojo::Pg::Che-&gt;new('pg://postgres@/test');
    # or
    my $pg = Mojo::Pg::Che-&gt;new(dsn=&gt;"dbname=test;", username=&gt;"postgres", password=&gt;'pg-pwd', options=&gt;\%attrs, max_connections=&gt;10);
    
    #Parent
    my $pg2 = Mojo::Pg::Che-&gt;new($pg);

    # Bloking query
    my $result = $pg-&gt;query('select ...', undef, @bind);
    
    # Non-blocking query
    my $result = $pg-&gt;query('select ...', {Async =&gt; 1, ...}, @bind);
    
    # Cached query
    my $result = $pg-&gt;query('select ...', {Cached =&gt; 1, ...}, @bind);
    
    # prepare sth
    my $sth = $pg-&gt;prepare('select ...');
    
    # cached async sth
    my $sth = $pg-&gt;prepare_cached('select ...', {Async =&gt; 1,},);
    
    # Non-blocking query for async sth
    $pg-&gt;query($sth, undef, @bind, sub {my ($db, $err, $result) = @_; ...});
    Mojo::IOLoop-&gt;start unless Mojo::IOLoop-&gt;is_running;
    
    
    # Result non-blocking query for async sth
    my $ref_cb = $pg-&gt;query($sth, {Async =&gt; 1,}, @bind,);
    Mojo::IOLoop-&gt;start unless Mojo::IOLoop-&gt;is_running;
    # Mojo::Pg::Results style
    my res = $$ref_cb-&gt;()-&gt;hash;
    # same DBI style
    my $res  = $$ref_cb-&gt;()-&gt;fetchrow_hashref;
    
    # Mojo::Pg style
    my $now = $pg-&gt;db-&gt;query('select now() as now')-&gt;hash-&gt;{now};
    $pg-&gt;db-&gt;query('select pg_sleep(?::int), now() as now', undef, 2, $cb);
    
    # DBI style
    my $now = $pg-&gt;selectrow_hashref('select now() as now')-&gt;{now};
    my $now = $pg-&gt;db-&gt;selectrow_hashref('select now() as now')-&gt;{now};
    
    my $now = $pg-&gt;selectrow_array('select now() as now');

=head2 Transaction syntax

  eval {
    my $tx = $pg-&gt;begin;
    $tx-&gt;query('insert into foo (name) values (?)', 'bar');
    $tx-&gt;do('insert into foo (name) values (?)', 'baz');
    $tx-&gt;commit;
  };
  die $@ if $@;
  
  my $db = $pg-&gt;db;
  $db-&gt;begin;
  $db-&gt;do('insert into foo (name) values (?)', 'bazzzz');
  $db-&gt;rollback;
  $db-&gt;begin;
  $db-&gt;query('insert into foo (name) values (?)', 'barrr');
  $db-&gt;commit;

=head1 Non-blocking query

  my @results;
  my $cb = sub {
    my ($db, $err, $results) = @_;
    die $err if $err;
    push @results, $results;
  };
  $pg-&gt;query('select ?::date as d, pg_sleep(?::int)', undef, ("2016-06-$_", 1), $cb)
    for 17..23;
  Mojo::IOLoop-&gt;start unless Mojo::IOLoop-&gt;is_running;
  like($_-&gt;hash-&gt;{d}, qr/2016-06-\d+/, 'correct async query')
    for @results;



=head1 METHODS

All methods from parent module L&lt;Mojo::Pg&gt; are inherits and implements the following new ones.

=head2 connect

DBI-style of new object instance. See L&lt;DBI#connect&gt;

=head2 db

Overriden method of L&lt;Mojo::Pg#db&gt;. Because can first input param - DBI database handler (when prepared statement used).

=head2 prepare

Prepare and return DBI statement handler for query string.

=head2 prepare_cached

Prepare and return DBI cached statement handler for query string.

=head2 query

Like L&lt;Mojo::Pg::Database#query&gt; but input params - L&lt;Mojo::Pg::Che#Params-for-quering-methods&gt;

Blocking query without attr B&lt;Async&gt; or callback.

Non-blocking query with attr B&lt;Async&gt; or callback.

=head2 select

Same method C&lt;query&gt;.

=head2 selectrow_array

DBI style quering. See L&lt;DBI#selectrow_array&gt;. Blocking | non-blocking. Input params - L&lt;Mojo::Pg::Che#Params-for-quering-methods&gt;.

=head2 selectrow_arrayref

DBI style quering. See L&lt;DBI#selectrow_arrayref&gt;. Blocking | non-blocking. Input params - L&lt;Mojo::Pg::Che#Params-for-quering-methods&gt;.

=head2 selectrow_hashref

DBI style quering. See L&lt;DBI#selectrow_hashref&gt;. Blocking | non-blocking. Input params - L&lt;Mojo::Pg::Che#Params-for-quering-methods&gt;.

=head2 selectall_arrayref

DBI style quering. See L&lt;DBI#selectall_arrayref&gt;. Blocking | non-blocking. Input params - L&lt;Mojo::Pg::Che#Params-for-quering-methods&gt;.

=head2 selectall_hashref

DBI style quering. See L&lt;DBI#selectall_hashref&gt;. Blocking | non-blocking. Input params - L&lt;Mojo::Pg::Che#Params-for-quering-methods&gt;.

=head2 selectcol_arrayref

DBI style quering. See L&lt;DBI#selectcol_arrayref&gt;. Blocking | non-blocking. Input params - L&lt;Mojo::Pg::Che#Params-for-quering-methods&gt;.

=head2 do

DBI style quering. See L&lt;DBI#do&gt;. Blocking | non-blocking. Input params - L&lt;Mojo::Pg::Che#Params-for-quering-methods&gt;.

=head2 begin

Start transaction and return new L&lt;Mojo::Pg::Che::Database&gt; object which attr C&lt; {tx} &gt; is a L&lt;Mojo::Pg::Transaction&gt; object. Sinonyms are: C&lt;&lt; -&gt;tx &gt;&gt; and C&lt;&lt; -&gt;begin_work &gt;&gt;.

=head1 Params for quering methods

The methods C&lt;query&gt;, C&lt;select...&gt;, C&lt;do&gt; has next ordered input params:

=over 4

=item * String query | statement handler object

=item * Hashref attrs (optional)

=item * Array of bind values (optional)

=item * Last param - callback/coderef for non-blocking (optional)

=back

=head1 SEE ALSO

L&lt;Mojo::Pg&gt;

L&lt;DBI&gt;

=head1 AUTHOR

ﾐ慴ｸﾑ�ｰﾐｸﾐｻ ﾐｧﾐｵ (Mikhail Che), C&lt;&lt; &lt;mche[-at-]cpan.org&gt; &gt;&gt;

=head1 BUGS / CONTRIBUTING

Please report any bugs or feature requests at L&lt;https://github.com/mche/Mojo-Pg-Che/issues&gt;. Pull requests also welcome.

=head1 COPYRIGHT

Copyright 2016+ Mikhail Che.

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

=cut</pre></body></html>