Hello community, here is the log from the commit of package perl-Mojo-Pg for openSUSE:Factory checked in at 2017-12-20 10:40:27 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-Mojo-Pg (Old) and /work/SRC/openSUSE:Factory/.perl-Mojo-Pg.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Mojo-Pg" Wed Dec 20 10:40:27 2017 rev:9 rq:558583 version:4.04 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-Mojo-Pg/perl-Mojo-Pg.changes 2017-11-11 14:19:40.523047597 +0100 +++ /work/SRC/openSUSE:Factory/.perl-Mojo-Pg.new/perl-Mojo-Pg.changes 2017-12-20 10:40:31.836092811 +0100 @@ -1,0 +2,11 @@ +Mon Dec 18 06:36:50 UTC 2017 - [email protected] + +- updated to 4.04 + see /usr/share/doc/packages/perl-Mojo-Pg/Changes + + 4.04 2017-12-16 + - Added db attribute to Mojo::Pg::Results. + - Added sql_for method to Mojo::Pg::Migrations. + - Fixed a bug that could cause connections to be cached for reuse too early. + +------------------------------------------------------------------- Old: ---- Mojo-Pg-4.03.tar.gz New: ---- Mojo-Pg-4.04.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Mojo-Pg.spec ++++++ --- /var/tmp/diff_new_pack.kIxgj7/_old 2017-12-20 10:40:32.556040684 +0100 +++ /var/tmp/diff_new_pack.kIxgj7/_new 2017-12-20 10:40:32.560040394 +0100 @@ -17,7 +17,7 @@ Name: perl-Mojo-Pg -Version: 4.03 +Version: 4.04 Release: 0 %define cpan_name Mojo-Pg Summary: Mojolicious ♥ PostgreSQL @@ -48,48 +48,6 @@ schema with migrations and build scalable real-time web applications with the publish/subscribe pattern. -Database and statement handles are cached automatically, and will be reused -transparently to increase performance. You can handle connection timeouts -gracefully by holding on to them only for short amounts of time. - - use Mojolicious::Lite; - use Mojo::Pg; - - helper pg => sub { state $pg = Mojo::Pg->new('postgresql://postgres@/test') }; - - get '/' => sub { - my $c = shift; - my $db = $c->pg->db; - $c->render(json => $db->query('select now() as now')->hash); - }; - - app->start; - -In this example application, we create a 'pg' helper to store a Mojo::Pg -object. Our action calls that helper and uses the method Mojo::Pg/"db" to -dequeue a Mojo::Pg::Database object from the connection pool. Then we use -the method Mojo::Pg::Database/"query" to execute an at -http://www.postgresql.org/docs/current/static/sql.html statement, which -returns a Mojo::Pg::Results object. And finally we call the method -Mojo::Pg::Results/"hash" to retrieve the first row as a hash reference. - -While all I/O operations are performed blocking, you can wait for long -running queries asynchronously, allowing the Mojo::IOLoop event loop to -perform other tasks in the meantime. Since database connections usually -have a very low latency, this often results in very good performance. - -Every database connection can only handle one active query at a time, this -includes asynchronous ones. To perform multiple queries concurrently, you -have to use multiple connections. - - # Performed concurrently (5 seconds) - $pg->db->query('select pg_sleep(5)' => sub {...}); - $pg->db->query('select pg_sleep(5)' => sub {...}); - -All cached database handles will be reset automatically if a new process -has been forked, this allows multiple processes to share the same Mojo::Pg -object safely. - %prep %setup -q -n %{cpan_name}-%{version} find . -type f ! -name \*.pl -print0 | xargs -0 chmod 644 ++++++ Mojo-Pg-4.03.tar.gz -> Mojo-Pg-4.04.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/Changes new/Mojo-Pg-4.04/Changes --- old/Mojo-Pg-4.03/Changes 2017-11-04 18:01:39.000000000 +0100 +++ new/Mojo-Pg-4.04/Changes 2017-12-16 16:24:58.000000000 +0100 @@ -1,4 +1,9 @@ +4.04 2017-12-16 + - Added db attribute to Mojo::Pg::Results. + - Added sql_for method to Mojo::Pg::Migrations. + - Fixed a bug that could cause connections to be cached for reuse too early. + 4.03 2017-11-04 - Improved Mojo::Pg::Database to use Mojo::Promise. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/META.json new/Mojo-Pg-4.04/META.json --- old/Mojo-Pg-4.03/META.json 2017-11-04 18:04:41.000000000 +0100 +++ new/Mojo-Pg-4.04/META.json 2017-12-17 19:00:55.000000000 +0100 @@ -57,6 +57,6 @@ }, "x_IRC" : "irc://irc.perl.org/#mojo" }, - "version" : "4.03", - "x_serialization_backend" : "JSON::PP version 2.94" + "version" : "4.04", + "x_serialization_backend" : "JSON::PP version 2.97000" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/META.yml new/Mojo-Pg-4.04/META.yml --- old/Mojo-Pg-4.03/META.yml 2017-11-04 18:04:41.000000000 +0100 +++ new/Mojo-Pg-4.04/META.yml 2017-12-17 19:00:55.000000000 +0100 @@ -30,5 +30,5 @@ homepage: http://mojolicious.org license: http://www.opensource.org/licenses/artistic-license-2.0 repository: https://github.com/kraih/mojo-pg.git -version: '4.03' +version: '4.04' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/lib/Mojo/Pg/Database.pm new/Mojo-Pg-4.04/lib/Mojo/Pg/Database.pm --- old/Mojo-Pg-4.03/lib/Mojo/Pg/Database.pm 2017-11-04 16:21:36.000000000 +0100 +++ new/Mojo-Pg-4.04/lib/Mojo/Pg/Database.pm 2017-12-16 16:23:31.000000000 +0100 @@ -106,7 +106,7 @@ # Blocking unless ($cb) { $self->_notifications; - return $self->results_class->new(sth => $sth); + return $self->results_class->new(db => $self, sth => $sth); } # Non-blocking @@ -172,7 +172,7 @@ my $result = do { local $dbh->{RaiseError} = 0; $dbh->pg_result }; my $err = defined $result ? undef : $dbh->errstr; - $self->$cb($err, $self->results_class->new(sth => $sth)); + $self->$cb($err, $self->results_class->new(db => $self, sth => $sth)); $self->_unwatch unless $self->{waiting} || $self->is_listening; } )->watch($self->{handle}, 1, 0); @@ -308,7 +308,7 @@ my $promise = $db->delete_p($table, \%where, \%options); Same as L</"delete">, but performs all operations non-blocking and returns a -L<Mojo::Promise> object to be used as a promise instead of accepting a callback. +L<Mojo::Promise> object instead of accepting a callback. $db->delete_p('some_table')->then(sub { my $results = shift; @@ -369,7 +369,7 @@ my $promise = $db->insert_p($table, \@values || \%fieldvals, \%options); Same as L</"insert">, but performs all operations non-blocking and returns a -L<Mojo::Promise> object to be used as a promise instead of accepting a callback. +L<Mojo::Promise> object instead of accepting a callback. $db->insert_p(some_table => {foo => 'bar'})->then(sub { my $results = shift; @@ -451,7 +451,7 @@ my $promise = $db->query_p('select * from foo'); Same as L</"query">, but performs all operations non-blocking and returns a -L<Mojo::Promise> object to be used as a promise instead of accepting a callback. +L<Mojo::Promise> object instead of accepting a callback. $db->query_p('insert into foo values (?, ?, ?)' => @values)->then(sub { my $results = shift; @@ -498,7 +498,7 @@ my $promise = $db->select_p($source, $fields, $where, $order); Same as L</"select">, but performs all operations non-blocking and returns a -L<Mojo::Promise> object to be used as a promise instead of accepting a callback. +L<Mojo::Promise> object instead of accepting a callback. $db->select_p(some_table => ['foo'] => {bar => 'yada'})->then(sub { my $results = shift; @@ -559,7 +559,7 @@ my $promise = $db->update_p($table, \%fieldvals, \%where, \%options); Same as L</"update">, but performs all operations non-blocking and returns a -L<Mojo::Promise> object to be used as a promise instead of accepting a +L<Mojo::Promise> object instead of accepting a callback. $db->update_p(some_table => {foo => 'baz'} => {foo => 'bar'})->then(sub { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/lib/Mojo/Pg/Migrations.pm new/Mojo-Pg-4.04/lib/Mojo/Pg/Migrations.pm --- old/Mojo-Pg-4.03/lib/Mojo/Pg/Migrations.pm 2017-06-24 15:01:30.000000000 +0200 +++ new/Mojo-Pg-4.04/lib/Mojo/Pg/Migrations.pm 2017-12-14 19:43:41.000000000 +0100 @@ -60,19 +60,7 @@ croak "Active version $active is greater than the latest version $latest" if $active > $latest; - # Up - my $sql; - if ($active < $target) { - my @up = grep { $_ <= $target && $_ > $active } keys %$up; - $sql = join '', @$up{sort { $a <=> $b } @up}; - } - - # Down - else { - my @down = grep { $_ > $target && $_ <= $active } keys %$down; - $sql = join '', @$down{reverse sort { $a <=> $b } @down}; - } - + my $sql = $self->sql_for($active, $target); warn "-- Migrate ($active -> $target)\n$sql\n" if DEBUG; $sql .= ';update mojo_migrations set version = $1 where name = $2;'; $db->query($sql, $target, $self->name) and $tx->commit; @@ -80,6 +68,21 @@ return $self; } +sub sql_for { + my ($self, $from, $to) = @_; + + # Up + my ($up, $down) = @{$self->{migrations}}{qw(up down)}; + if ($from < $to) { + my @up = grep { $_ <= $to && $_ > $from } keys %$up; + return join '', @$up{sort { $a <=> $b } @up}; + } + + # Down + my @down = grep { $_ > $to && $_ <= $from } keys %$down; + return join '', @$down{reverse sort { $a <=> $b } @down}; +} + sub _active { my ($self, $db, $create) = @_; @@ -225,6 +228,12 @@ # Reset database $migrations->migrate(0)->migrate; +=head2 sql_for + + my $sql = $migrations->sql_for(5, 10); + +Get SQL to migrate from one version to another, up or down. + =head1 DEBUGGING You can set the C<MOJO_MIGRATIONS_DEBUG> environment variable to get some diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/lib/Mojo/Pg/Results.pm new/Mojo-Pg-4.04/lib/Mojo/Pg/Results.pm --- old/Mojo-Pg-4.03/lib/Mojo/Pg/Results.pm 2017-07-23 15:57:01.000000000 +0200 +++ new/Mojo-Pg-4.04/lib/Mojo/Pg/Results.pm 2017-12-17 19:00:44.000000000 +0100 @@ -5,7 +5,7 @@ use Mojo::JSON 'from_json'; use Mojo::Util 'tablify'; -has 'sth'; +has [qw(db sth)]; sub DESTROY { my $self = shift; @@ -86,6 +86,13 @@ L<Mojo::Pg::Results> implements the following attributes. +=head2 db + + my $db = $results->db; + $results = $results->db(Mojo::Pg::Database->new); + +L<Mojo::Pg::Database> object these results belong to. + =head2 sth my $sth = $results->sth; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/lib/Mojo/Pg.pm new/Mojo-Pg-4.04/lib/Mojo/Pg.pm --- old/Mojo-Pg-4.03/lib/Mojo/Pg.pm 2017-11-04 18:03:27.000000000 +0100 +++ new/Mojo-Pg-4.04/lib/Mojo/Pg.pm 2017-12-14 19:43:41.000000000 +0100 @@ -38,7 +38,7 @@ return $pubsub; }; -our $VERSION = '4.03'; +our $VERSION = '4.04'; sub db { $_[0]->database_class->new(dbh => $_[0]->_prepare, pg => $_[0]) } @@ -219,6 +219,8 @@ database schema with migrations and build scalable real-time web applications with the publish/subscribe pattern. +=head1 BASICS + Database and statement handles are cached automatically, and will be reused transparently to increase performance. You can handle connection timeouts gracefully by holding on to them only for short amounts of time. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/t/database.t new/Mojo-Pg-4.04/t/database.t --- old/Mojo-Pg-4.03/t/database.t 2017-11-02 19:31:37.000000000 +0100 +++ new/Mojo-Pg-4.04/t/database.t 2017-12-16 16:37:38.000000000 +0100 @@ -27,16 +27,19 @@ # Non-blocking select my ($fail, $result); +my $same; my $db = $pg->db; $db->query( 'select 1 as one, 2 as two, 3 as three' => sub { my ($db, $err, $results) = @_; $fail = $err; $result = $results->hash; + $same = $db->dbh eq $results->db->dbh; Mojo::IOLoop->stop; } ); Mojo::IOLoop->start; +ok $same, 'same database handles'; ok !$fail, 'no error'; is_deeply $result, {one => 1, two => 2, three => 3}, 'right structure'; @@ -121,6 +124,20 @@ isnt $db->query('select 6 as six')->sth, $sth, 'different statement handles'; is $db->query('select 3 as three')->sth, $sth, 'same statement handle'; +# Connection reuse +$db = $pg->db; +$dbh = $db->dbh; +$results = $db->query('select 1'); +undef $db; +my $db2 = $pg->db; +isnt $db2->dbh, $dbh, 'new database handle'; +undef $results; +my $db3 = $pg->db; +is $db3->dbh, $dbh, 'same database handle'; +$results = $db3->query('select 2'); +is $results->db->dbh, $dbh, 'same database handle'; +is $results->array->[0], 2, 'right result'; + # Dollar only $db = $pg->db; is $db->dollar_only->query('select $1::int as test', 23)->hash->{test}, 23, @@ -199,7 +216,7 @@ $db = $pg->db; ok !$db->is_listening, 'not listening'; ok $db->listen('dbtest')->is_listening, 'listening'; -my $db2 = $pg->db->listen('dbtest'); +$db2 = $pg->db->listen('dbtest'); my @notifications; Mojo::IOLoop->delay( sub { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-Pg-4.03/t/migrations.t new/Mojo-Pg-4.04/t/migrations.t --- old/Mojo-Pg-4.03/t/migrations.t 2017-07-06 23:36:56.000000000 +0200 +++ new/Mojo-Pg-4.04/t/migrations.t 2017-12-06 22:47:28.000000000 +0100 @@ -125,6 +125,22 @@ is_deeply $pg3->db->query('select * from migration_test_six')->hashes, [], 'right structure'; is $pg3->migrations->migrate(0)->active, 0, 'active version is 0'; +is $pg3->migrations->sql_for(0, 5), <<EOF, 'right SQL'; +-- 5 up +create table if not exists migration_test_six (foo varchar(255)); +EOF +is $pg3->migrations->sql_for(6, 0), <<EOF, 'right SQL'; +-- 6 down +delete from migration_test_six; +-- 5 down +drop table if exists migration_test_six; +EOF +is $pg3->migrations->sql_for(6, 5), <<EOF, 'right SQL'; +-- 6 down +delete from migration_test_six; +EOF +is $pg3->migrations->sql_for(6, 6), '', 'right SQL'; +is $pg3->migrations->sql_for(2, 3), '', 'right SQL'; # Migrate automatically with shared connection cache my $pg4
